Merge pull request #13487 from tanguyantoine/feat/allow-jenkins-plugin-to-send-extra-headers
feat(jenkins-backend): extend config to allow passing extra headers
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-jenkins-backend': patch
|
||||
---
|
||||
|
||||
Extend configuration so that extra headers can be sent to jenkins instance
|
||||
@@ -89,6 +89,9 @@ jenkins:
|
||||
baseUrl: https://jenkins.example.com
|
||||
username: backstage-bot
|
||||
apiKey: 123456789abcdef0123456789abcedf012
|
||||
# optionally add extra headers
|
||||
# extraRequestHeaders:
|
||||
# extra-header: my-value
|
||||
```
|
||||
|
||||
Catalog
|
||||
|
||||
@@ -72,6 +72,7 @@ export interface JenkinsInstanceConfig {
|
||||
baseUrl: string;
|
||||
// (undocumented)
|
||||
crumbIssuer?: boolean;
|
||||
extraRequestHeaders?: Record<string, string>;
|
||||
// (undocumented)
|
||||
name: string;
|
||||
// (undocumented)
|
||||
|
||||
@@ -55,6 +55,9 @@ describe('JenkinsConfig', () => {
|
||||
baseUrl: 'https://jenkins.example.com',
|
||||
username: 'backstage - bot',
|
||||
apiKey: '123456789abcdef0123456789abcedf012',
|
||||
headers: {
|
||||
myHeader: 'my-value',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -67,6 +70,9 @@ describe('JenkinsConfig', () => {
|
||||
baseUrl: 'https://jenkins.example.com',
|
||||
username: 'backstage - bot',
|
||||
apiKey: '123456789abcdef0123456789abcedf012',
|
||||
headers: {
|
||||
myHeader: 'my-value',
|
||||
},
|
||||
},
|
||||
]);
|
||||
});
|
||||
@@ -197,6 +203,9 @@ describe('DefaultJenkinsInfoProvider', () => {
|
||||
baseUrl: 'https://jenkins.example.com',
|
||||
username: 'backstage - bot',
|
||||
apiKey: '123456789abcdef0123456789abcedf012',
|
||||
extraRequestHeaders: {
|
||||
['extra-header']: 'extra-value',
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -218,6 +227,7 @@ describe('DefaultJenkinsInfoProvider', () => {
|
||||
headers: {
|
||||
Authorization:
|
||||
'Basic YmFja3N0YWdlIC0gYm90OjEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNlZGYwMTI=',
|
||||
'extra-header': 'extra-value',
|
||||
},
|
||||
jobFullName: 'teamA/artistLookup-build',
|
||||
});
|
||||
|
||||
@@ -53,6 +53,10 @@ export interface JenkinsInstanceConfig {
|
||||
username: string;
|
||||
apiKey: string;
|
||||
crumbIssuer?: boolean;
|
||||
/**
|
||||
* Extra headers to send to Jenkins instance
|
||||
*/
|
||||
extraRequestHeaders?: Record<string, string>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -74,12 +78,13 @@ export class JenkinsConfig {
|
||||
const jenkinsConfig = config.getConfig('jenkins');
|
||||
|
||||
// load all named instance config
|
||||
const namedInstanceConfig =
|
||||
const namedInstanceConfig: JenkinsInstanceConfig[] =
|
||||
jenkinsConfig.getOptionalConfigArray('instances')?.map(c => ({
|
||||
name: c.getString('name'),
|
||||
baseUrl: c.getString('baseUrl'),
|
||||
username: c.getString('username'),
|
||||
apiKey: c.getString('apiKey'),
|
||||
headers: c.getOptional('headers'),
|
||||
crumbIssuer: c.getOptionalBoolean('crumbIssuer'),
|
||||
})) || [];
|
||||
|
||||
@@ -93,6 +98,9 @@ export class JenkinsConfig {
|
||||
const username = jenkinsConfig.getOptionalString('username');
|
||||
const apiKey = jenkinsConfig.getOptionalString('apiKey');
|
||||
const crumbIssuer = jenkinsConfig.getOptionalBoolean('crumbIssuer');
|
||||
const extraRequestHeaders = jenkinsConfig.getOptional<
|
||||
JenkinsInstanceConfig['extraRequestHeaders']
|
||||
>('extraRequestHeaders');
|
||||
|
||||
if (hasNamedDefault && (baseUrl || username || apiKey)) {
|
||||
throw new Error(
|
||||
@@ -109,19 +117,16 @@ export class JenkinsConfig {
|
||||
}
|
||||
|
||||
if (unnamedAllPresent) {
|
||||
const unnamedInstanceConfig = [
|
||||
{ name: DEFAULT_JENKINS_NAME, baseUrl, username, apiKey, crumbIssuer },
|
||||
] as {
|
||||
name: string;
|
||||
baseUrl: string;
|
||||
username: string;
|
||||
apiKey: string;
|
||||
crumbIssuer: boolean;
|
||||
}[];
|
||||
|
||||
return new JenkinsConfig([
|
||||
...namedInstanceConfig,
|
||||
...unnamedInstanceConfig,
|
||||
{
|
||||
name: DEFAULT_JENKINS_NAME,
|
||||
baseUrl,
|
||||
username,
|
||||
apiKey,
|
||||
extraRequestHeaders,
|
||||
crumbIssuer,
|
||||
},
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -243,6 +248,7 @@ export class DefaultJenkinsInfoProvider implements JenkinsInfoProvider {
|
||||
baseUrl: instanceConfig.baseUrl,
|
||||
headers: {
|
||||
Authorization: `Basic ${creds}`,
|
||||
...instanceConfig.extraRequestHeaders,
|
||||
},
|
||||
jobFullName,
|
||||
crumbIssuer: instanceConfig.crumbIssuer,
|
||||
|
||||
Reference in New Issue
Block a user