Skip to content

Commit

Permalink
Fb/service keys prep (#52)
Browse files Browse the repository at this point in the history
* prep for service-key changes

* prep for service-key changes 2

* fix linter problems
  • Loading branch information
rlindner81 authored Dec 22, 2023
1 parent 3313fc7 commit 6327401
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
30 changes: 15 additions & 15 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ const _readRuntimeConfig = (filepath, { logged = false, checkConfig = true } = {
}

return rawRuntimeConfig
? Object.keys(SETTING).reduce((result, key) => {
result[key] = rawRuntimeConfig[key];
? Object.values(SETTING).reduce((result, value) => {
result[value.config] = rawRuntimeConfig[value.config];
return result;
}, Object.create(null))
: {};
Expand Down Expand Up @@ -209,13 +209,13 @@ const _setup = async (location) => {
const newRuntimeConfig = {};
console.log("hit enter to skip a question. re-using the same app for multiple questions is possible.");
try {
const settings = Object.entries(SETTING);
const settings = Object.values(SETTING);
for (let i = 0; i < settings.length; i++) {
const [key, value] = settings[i];
const value = settings[i];
const ask = `${i + 1}/${settings.length} | ${value.question}`;
const answer = (await question(ask, runtimeConfig[key])).trim();
const answer = (await question(ask, runtimeConfig[value.config])).trim();
if (answer) {
newRuntimeConfig[key] = answer;
newRuntimeConfig[value.config] = answer;
}
}
} catch (err) {
Expand All @@ -235,10 +235,10 @@ const setupLocal = async () => {
const setupList = () => {
const { filepath } = _resolveDir(FILENAME.CONFIG) || {};
const runtimeConfig = _readRuntimeConfig(filepath, { logged: true });
return Object.entries(SETTING)
return Object.values(SETTING)
.map(
([key, value], i, settings) =>
`${i + 1}/${settings.length} | ${value.question} ${runtimeConfig[key] || "<empty>"}`
(value, i, settings) =>
`${i + 1}/${settings.length} | ${value.question} ${runtimeConfig[value.config] || "<empty>"}`
)
.join("\n");
};
Expand Down Expand Up @@ -410,7 +410,7 @@ const newContext = async ({ usePersistedCache = true, isReadonlyCommand = false
const setting = SETTING[type];

// determine configured appName
const configAppName = runtimeConfig[type];
const configAppName = runtimeConfig[setting.config];
const envAppName = (setting.envVariable && process.env[setting.envVariable]) || null;
if (envAppName && configAppName !== envAppName) {
if (configAppName) {
Expand Down Expand Up @@ -495,11 +495,11 @@ const newContext = async ({ usePersistedCache = true, isReadonlyCommand = false
return processRawAppInfo(cfApp.name, rawAppInfo, setting);
};

const getUaaInfo = getAppInfoCached(SETTING_TYPE.UAA);
const getRegInfo = getAppInfoCached(SETTING_TYPE.REG);
const getCdsInfo = getAppInfoCached(SETTING_TYPE.CDS);
const getHdiInfo = getAppInfoCached(SETTING_TYPE.HDI);
const getSrvInfo = getAppInfoCached(SETTING_TYPE.SRV);
const getUaaInfo = getAppInfoCached(SETTING_TYPE.UAA_APP);
const getRegInfo = getAppInfoCached(SETTING_TYPE.REGISTRY_APP);
const getCdsInfo = getAppInfoCached(SETTING_TYPE.CDS_APP);
const getHdiInfo = getAppInfoCached(SETTING_TYPE.HDI_APP);
const getSrvInfo = getAppInfoCached(SETTING_TYPE.SERVER_APP);

const getCachedUaaTokenFromCredentials = async (credentials, options) =>
await cfUaaTokenCache.getSetCb(
Expand Down
32 changes: 20 additions & 12 deletions src/setting.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@
const { ENV } = require("./shared/static");

const SETTING_TYPE = {
UAA: "uaaAppName",
REG: "regAppName",
CDS: "cdsAppName",
HDI: "hdiAppName",
SRV: "srvAppName",
UAA_APP: "UAA_APP",
UAA_KEY: "UAA_KEY",
REGISTRY_APP: "REGISTRY_APP",
REGISTRY_KEY: "REGISTRY_KEY",
CDS_APP: "CDS_APP",
HDI_APP: "HDI_APP",
HDI_KEY: "HDI_KEY",
SERVER_APP: "SERVER_APP",
};

const SETTING = {
[SETTING_TYPE.UAA]: {
[SETTING_TYPE.UAA_APP]: {
config: "uaaAppName",
name: "uaa app",
envVariable: ENV.UAA_APP,
question: "cf app bound to xsuaa service (optional)?",
Expand All @@ -27,8 +31,9 @@ const SETTING = {
},
],
},
[SETTING_TYPE.REG]: {
name: "registry app",
[SETTING_TYPE.REGISTRY_APP]: {
config: "regAppName",
name: "saas-registry app",
envVariable: ENV.REGISTRY_APP,
question: "cf app bound to saas-registry service (optional)?",
failMessage: "option requires configured app bound to service label:saas-registry plan:application",
Expand All @@ -43,15 +48,17 @@ const SETTING = {
},
],
},
[SETTING_TYPE.CDS]: {
[SETTING_TYPE.CDS_APP]: {
config: "cdsAppName",
name: "cds-mtx app",
envVariable: ENV.CDS_APP,
question: "cf app running @sap/cds-mtx or @sap/cds-mtxs library (optional)?",
failMessage: "option requires configured app running @sap/cds-mtx",
requireRoute: true,
},
[SETTING_TYPE.HDI]: {
name: "hdi app",
[SETTING_TYPE.HDI_APP]: {
config: "hdiAppName",
name: "service-manager app",
envVariable: ENV.HDI_APP,
question: "cf app bound to service-manager or managed-hana service (optional)?",
failMessage:
Expand All @@ -67,7 +74,8 @@ const SETTING = {
},
],
},
[SETTING_TYPE.SRV]: {
[SETTING_TYPE.SERVER_APP]: {
config: "srvAppName",
name: "server app",
envVariable: ENV.SERVER_APP,
question: 'cf app with "/info" endpoint (optional)?',
Expand Down
3 changes: 3 additions & 0 deletions src/shared/static.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ const util = require("util");

const ENV = Object.freeze({
UAA_APP: "MTX_UAA_APP",
UAA_KEY: "MTX_UAA_KEY",
REGISTRY_APP: "MTX_REG_APP",
REGISTRY_KEY: "MTX_REG_KEY",
CDS_APP: "MTX_CDS_APP",
HDI_APP: "MTX_HDI_APP",
HDI_KEY: "MTX_HDI_KEY",
SERVER_APP: "MTX_SRV_APP",
APP_SUFFIX: "MTX_APP_SUFFIX",
CDS_CONCURRENCY: "MTX_CDS_CONCURRENCY",
Expand Down
4 changes: 2 additions & 2 deletions src/submodules/hanaManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -471,8 +471,8 @@ const hdiListServiceManager = async (context, filterTenantId, doTimestamps) => {
const [binding] = bindingsByInstance[instance.id] || [];
const row = [
instance.labels.tenant_id[0],
binding ? binding.credentials.host + ":" + binding.credentials.port : "missing binding",
binding ? binding.credentials.schema : "",
binding ? binding.credentials?.host + ":" + binding.credentials?.port : "missing binding",
binding ? binding.credentials?.schema : "",
instance.ready,
];
doTimestamps && row.push(...formatTimestampsWithRelativeDays([instance.created_at, instance.updated_at], nowDate));
Expand Down

0 comments on commit 6327401

Please sign in to comment.