Add addon hook to get dynamic environment variables
This commit is contained in:
+54
-15
@@ -75,13 +75,15 @@ const ADDONS = {
|
||||
teardown: teardownTurn,
|
||||
backup: NOOP,
|
||||
restore: NOOP,
|
||||
clear: NOOP
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
email: {
|
||||
setup: setupEmail,
|
||||
teardown: teardownEmail,
|
||||
backup: NOOP,
|
||||
restore: setupEmail,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
ldap: {
|
||||
@@ -89,6 +91,7 @@ const ADDONS = {
|
||||
teardown: teardownLdap,
|
||||
backup: NOOP,
|
||||
restore: setupLdap,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
localstorage: {
|
||||
@@ -96,6 +99,7 @@ const ADDONS = {
|
||||
teardown: teardownLocalStorage,
|
||||
backup: NOOP, // no backup because it's already inside app data
|
||||
restore: NOOP,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: clearLocalStorage,
|
||||
},
|
||||
mongodb: {
|
||||
@@ -103,6 +107,7 @@ const ADDONS = {
|
||||
teardown: teardownMongoDb,
|
||||
backup: backupMongoDb,
|
||||
restore: restoreMongoDb,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: clearMongodb,
|
||||
},
|
||||
mysql: {
|
||||
@@ -110,6 +115,7 @@ const ADDONS = {
|
||||
teardown: teardownMySql,
|
||||
backup: backupMySql,
|
||||
restore: restoreMySql,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: clearMySql,
|
||||
},
|
||||
postgresql: {
|
||||
@@ -117,6 +123,7 @@ const ADDONS = {
|
||||
teardown: teardownPostgreSql,
|
||||
backup: backupPostgreSql,
|
||||
restore: restorePostgreSql,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: clearPostgreSql,
|
||||
},
|
||||
proxyAuth: {
|
||||
@@ -124,6 +131,7 @@ const ADDONS = {
|
||||
teardown: teardownProxyAuth,
|
||||
backup: NOOP,
|
||||
restore: NOOP,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP
|
||||
},
|
||||
recvmail: {
|
||||
@@ -131,6 +139,7 @@ const ADDONS = {
|
||||
teardown: teardownRecvMail,
|
||||
backup: NOOP,
|
||||
restore: setupRecvMail,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
redis: {
|
||||
@@ -138,6 +147,7 @@ const ADDONS = {
|
||||
teardown: teardownRedis,
|
||||
backup: backupRedis,
|
||||
restore: restoreRedis,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: clearRedis,
|
||||
},
|
||||
sendmail: {
|
||||
@@ -145,6 +155,7 @@ const ADDONS = {
|
||||
teardown: teardownSendMail,
|
||||
backup: NOOP,
|
||||
restore: setupSendMail,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
scheduler: {
|
||||
@@ -152,6 +163,7 @@ const ADDONS = {
|
||||
teardown: NOOP,
|
||||
backup: NOOP,
|
||||
restore: NOOP,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
docker: {
|
||||
@@ -159,6 +171,7 @@ const ADDONS = {
|
||||
teardown: NOOP,
|
||||
backup: NOOP,
|
||||
restore: NOOP,
|
||||
getDynamicEnvironment: getDynamicEnvironmentDocker,
|
||||
clear: NOOP,
|
||||
},
|
||||
tls: {
|
||||
@@ -166,6 +179,7 @@ const ADDONS = {
|
||||
teardown: teardownTls,
|
||||
backup: NOOP,
|
||||
restore: NOOP,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
oauth: { // kept for backward compatibility. keep teardown for uninstall to work
|
||||
@@ -173,6 +187,7 @@ const ADDONS = {
|
||||
teardown: teardownOauth,
|
||||
backup: NOOP,
|
||||
restore: NOOP,
|
||||
getDynamicEnvironment: NOOP,
|
||||
clear: NOOP,
|
||||
},
|
||||
oidc: {
|
||||
@@ -180,6 +195,7 @@ const ADDONS = {
|
||||
teardown: teardownOidc,
|
||||
backup: NOOP,
|
||||
restore: setupOidc,
|
||||
getDynamicEnvironment: getDynamicEnvironmentOidc,
|
||||
clear: NOOP,
|
||||
},
|
||||
};
|
||||
@@ -796,26 +812,19 @@ async function startServices(existingInfra) {
|
||||
async function getEnvironment(app) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
|
||||
// contains values for environment from addonConfigs db
|
||||
const result = await addonConfigs.getByAppId(app.id);
|
||||
|
||||
// convert result to object to ensure unique env names if we overwrite static ones from the previously stored value in addonconfigs
|
||||
const env = {};
|
||||
let env = {};
|
||||
result.forEach(e => { env[e.name] = e.value; });
|
||||
|
||||
if (app.manifest.addons['docker']) env['CLOUDRON_DOCKER_HOST'] = `tcp://172.18.0.1:${constants.DOCKER_PROXY_PORT}`;
|
||||
// get dynamic environment configs overwriting static ones
|
||||
for (let addon in app.manifest.addons) {
|
||||
const configs = await ADDONS[addon].getDynamicEnvironment(app, {});
|
||||
console.log('====', addon, configs);
|
||||
|
||||
if (app.sso && app.manifest.addons['oidc']) {
|
||||
env['CLOUDRON_OIDC_DISCOVERY_URL'] = `https://${settings.dashboardFqdn()}/.well-known/openid-configuration`;
|
||||
env['CLOUDRON_OIDC_ISSUER'] = `https://${settings.dashboardFqdn()}/openid`;
|
||||
env['CLOUDRON_OIDC_AUTH_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/auth`;
|
||||
env['CLOUDRON_OIDC_TOKEN_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/token`;
|
||||
env['CLOUDRON_OIDC_KEYS_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/jwks`;
|
||||
env['CLOUDRON_OIDC_PROFILE_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/me`;
|
||||
env['CLOUDRON_OIDC_LOGOUT_URL'] = `https://${settings.dashboardFqdn()}/openid/session/env`;
|
||||
|
||||
const client = await oidc.clients.get(app.id);
|
||||
env['CLOUDRON_OIDC_CLIENT_ID'] = client.id;
|
||||
env['CLOUDRON_OIDC_CLIENT_SECRET'] = client.secret;
|
||||
if (configs) env = { ...env, ...configs };
|
||||
}
|
||||
|
||||
return Object.keys(env).map(function (e) { return e + '=' + env[e]; });
|
||||
@@ -1815,6 +1824,13 @@ async function restoreRedis(app, options) {
|
||||
await pipeFileToRequest(dumpPath('redis', app.id), `http://${result.ip}:3000/restore?access_token=${result.token}`);
|
||||
}
|
||||
|
||||
async function getDynamicEnvironmentDocker(app, options) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
|
||||
return { CLOUDRON_DOCKER_HOST: `tcp://172.18.0.1:${constants.DOCKER_PROXY_PORT}` };
|
||||
}
|
||||
|
||||
async function setupTls(app, options) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
@@ -1961,3 +1977,26 @@ async function teardownOidc(app, options) {
|
||||
const [error] = await safe(oidc.clients.del(app.id));
|
||||
if (error && error.reason !== BoxError.NOT_FOUND) throw error;
|
||||
}
|
||||
|
||||
async function getDynamicEnvironmentOidc(app, options) {
|
||||
assert.strictEqual(typeof app, 'object');
|
||||
assert.strictEqual(typeof options, 'object');
|
||||
|
||||
const tmp = {};
|
||||
|
||||
if (app.sso && app.manifest.addons['oidc']) {
|
||||
tmp['CLOUDRON_OIDC_DISCOVERY_URL'] = `https://${settings.dashboardFqdn()}/.well-known/openid-configuration`;
|
||||
tmp['CLOUDRON_OIDC_ISSUER'] = `https://${settings.dashboardFqdn()}/openid`;
|
||||
tmp['CLOUDRON_OIDC_AUTH_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/auth`;
|
||||
tmp['CLOUDRON_OIDC_TOKEN_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/token`;
|
||||
tmp['CLOUDRON_OIDC_KEYS_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/jwks`;
|
||||
tmp['CLOUDRON_OIDC_PROFILE_ENDPOINT'] = `https://${settings.dashboardFqdn()}/openid/me`;
|
||||
tmp['CLOUDRON_OIDC_LOGOUT_URL'] = `https://${settings.dashboardFqdn()}/openid/session/env`;
|
||||
|
||||
const client = await oidc.clients.get(app.id);
|
||||
tmp['CLOUDRON_OIDC_CLIENT_ID'] = client.id;
|
||||
tmp['CLOUDRON_OIDC_CLIENT_SECRET'] = client.secret;
|
||||
}
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user