Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update request options to add keys from config map data to headers #334

Merged
merged 7 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/BaseDownloadController.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const clone = require('clone');

const CompositeController = require('./CompositeController');

const FetchEnvs = require('./FetchEnvs');

module.exports = class BaseDownloadController extends CompositeController {
constructor(params) {
Expand Down Expand Up @@ -195,6 +196,19 @@ module.exports = class BaseDownloadController extends CompositeController {
}
}
}

const reqopt = new FetchEnvs(this);
const headersFrom = objectPath.get(requestOptions, 'headersFrom');
if (headersFrom) {
const headersFromTemp = await reqopt.processEnvFrom(headersFrom);
let mergedHeaders = { ...headers };
for (const header of headersFromTemp) {
const data = header?.data;
mergedHeaders = { ...mergedHeaders, ...data };
}
requestOptions = { ...requestOptions, headers: mergedHeaders };
}

return requestOptions;
}

Expand Down
4 changes: 2 additions & 2 deletions lib/FetchEnvs.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = class FetchEnvs {
}


#processEnvFrom(envFrom) {
processEnvFrom(envFrom) {
return Promise.all(envFrom.map((element) => {
const { configMapRef, secretMapRef, genericMapRef } = element;

Expand Down Expand Up @@ -218,7 +218,7 @@ module.exports = class FetchEnvs {
path = path.replace(/^\.*|\.*$|(\.envFrom\.*$)|(\.env\.*$)/g, '');

let envFrom = objectPath.get(this.data, `object.${path}.envFrom`, []);
envFrom = await this.#processEnvFrom(envFrom);
envFrom = await this.processEnvFrom(envFrom);
for (const env of envFrom) {
const data = env?.data ?? {};
result = { ...result, ...data };
Expand Down