Skip to content

Commit

Permalink
handle remote param authentication (#258)
Browse files Browse the repository at this point in the history
* handle remote param authentication

* conditionally add auth to base

Co-authored-by: Katie Dai <kdai7@ibm.com>
  • Loading branch information
kdai7 and Katie Dai committed Nov 4, 2022
1 parent ee127ea commit 45bbc45
Showing 1 changed file with 45 additions and 47 deletions.
92 changes: 45 additions & 47 deletions lib/backendservice/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module.exports = class Git extends BackendService {
super(sub, razeeApi, namespace);
this._provider = sub.remote.remoteType;
this._secretNameGit = 'satellite-config-gitops';
this._auth = false;
sub.remote.parameters.forEach(param => {
if (param.key == 'repo') {
this._repo = param.value;
Expand All @@ -33,6 +34,8 @@ module.exports = class Git extends BackendService {
this._release = param.value;
} else if (param.key == 'secretName') {
this._secretNameGit = param.value;
} else if (param.key == 'authentication') {
this._auth = (param.value.toLowerCase() === 'true');
}
});

Expand Down Expand Up @@ -62,6 +65,10 @@ module.exports = class Git extends BackendService {
return this._filePath;
}

get auth() {
return this._auth;
}

render() {
let rendered;
if (this.ref) {
Expand All @@ -72,32 +79,28 @@ module.exports = class Git extends BackendService {
repo: '{{{repo}}}',
ref: '{{{ref}}}',
filePath: '{{{filePath}}}'
},
headers: {
'razee-org-key': {
valueFrom: {
secretKeyRef:{
name: '{{{secretName}}}',
namespace: '{{namespace}}',
key: 'razee-api-org-key'
}
}
},
Authorization: {
valueFrom: {
secretKeyRef:{
name: '{{{secretNameGit}}}',
namespace: '{{namespace}}',
key: 'token'
}
}
}
}

}
};
const requestsTemplate = JSON.stringify(requests);
rendered = Mustache.render(requestsTemplate, { repo: this.repo, provider: this.provider, ref: this.ref, filePath: this.filePath, secretName: this.secretName, secretNameGit: this.secretNameGit, namespace: this.namespace});
if (this.auth) {
requests.options.headers = {
Authorization: {
valueFrom: {
secretKeyRef:{
name: '{{{secretNameGit}}}',
namespace: '{{namespace}}',
key: 'token'
}
}
}
};
const requestsTemplate = JSON.stringify(requests);
rendered = Mustache.render(requestsTemplate, { repo: this.repo, provider: this.provider, ref: this.ref, filePath: this.filePath, secretNameGit: this.secretNameGit, namespace: this.namespace});
} else {
const requestsTemplate = JSON.stringify(requests);
rendered = Mustache.render(requestsTemplate, { repo: this.repo, provider: this.provider, ref: this.ref, filePath: this.filePath});
}

} else if (this.release) {
const requests = {
options: {
Expand All @@ -106,34 +109,29 @@ module.exports = class Git extends BackendService {
repo: '{{{repo}}}',
release: '{{{release}}}',
filePath: '{{{filePath}}}'
},
headers: {
'razee-org-key': {
valueFrom: {
secretKeyRef:{
name: '{{{secretName}}}',
namespace: '{{namespace}}',
key: 'razee-api-org-key'
}
}
},
Authorization: {
valueFrom: {
secretKeyRef:{
name: '{{{secretNameGit}}}',
namespace: '{{namespace}}',
key: 'token'
}
}
}
}

}
};
const requestsTemplate = JSON.stringify(requests);
rendered = Mustache.render(requestsTemplate, { repo: this.repo, provider: this.provider, release: this.release, filePath: this.filePath, secretName: this.secretName, secretNameGit: this.secretNameGit, namespace: this.namespace});
if (this.auth) {
requests.options.headers = {
Authorization: {
valueFrom: {
secretKeyRef:{
name: '{{{secretNameGit}}}',
namespace: '{{namespace}}',
key: 'token'
}
}
}
};
const requestsTemplate = JSON.stringify(requests);
rendered = Mustache.render(requestsTemplate, { repo: this.repo, provider: this.provider, release: this.release, filePath: this.filePath, secretNameGit: this.secretNameGit, namespace: this.namespace});
} else {
const requestsTemplate = JSON.stringify(requests);
rendered = Mustache.render(requestsTemplate, { repo: this.repo, provider: this.provider, release: this.release, filePath: this.filePath});
}
}

return rendered;
}

};

0 comments on commit 45bbc45

Please sign in to comment.