Skip to content

Commit d19eec9

Browse files
committed
fix gitiops_auth_password when using jenkins as pipeline provider
1 parent 67ef722 commit d19eec9

File tree

7 files changed

+42
-36
lines changed

7 files changed

+42
-36
lines changed

integration-tests/config/testplan.json

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,29 @@
33
{
44
"name": "backend-tests",
55
"templates": ["go"],
6-
"tssc": [{
7-
"git": "github",
8-
"ci": "tekton",
9-
"registry": "quay",
10-
"tpa": "remote",
11-
"acs": "remote"
12-
},
13-
{
14-
"git": "gitlab",
15-
"ci": "tekton",
16-
"registry": "nexus",
17-
"tpa": "remote",
18-
"acs": "remote"
19-
},
20-
{
21-
"git": "gitlab",
22-
"ci": "gitlabci",
23-
"registry": "quay",
24-
"tpa": "remote",
25-
"acs": "remote"
26-
},
27-
{
28-
"git": "github",
29-
"ci": "githubactions",
30-
"registry": "artifactory",
31-
"tpa": "remote",
32-
"acs": "remote"
33-
},
6+
"tssc": [
347
{
358
"git": "github",
36-
"ci": "azure",
9+
"ci": "jenkins",
3710
"registry": "quay",
3811
"tpa": "remote",
3912
"acs": "remote"
4013
},
4114
{
42-
"git": "github",
15+
"git": "gitlab",
4316
"ci": "jenkins",
4417
"registry": "quay",
4518
"tpa": "remote",
4619
"acs": "remote"
4720
},
4821
{
49-
"git": "gitlab",
22+
"git": "bitbucket",
5023
"ci": "jenkins",
5124
"registry": "quay",
5225
"tpa": "remote",
5326
"acs": "remote"
54-
}],
27+
}
28+
],
5529
"tests": ["full_workflow.test.ts"]
5630
}
5731
]

src/rhtap/core/integration/git/baseGitProvider.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,11 @@ export abstract class BaseGitProvider implements Git {
165165
): Promise<string>;
166166

167167
public abstract getToken(): string;
168+
169+
public getUsername(): string {
170+
if (!this.secret?.username) {
171+
throw new Error('Username not found in the secret. Please ensure the username is provided.');
172+
}
173+
return this.secret.username;
174+
}
168175
}

src/rhtap/core/integration/git/gitInterface.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,6 @@ export interface Git extends IntegrationSecret {
115115
): Promise<string>;
116116

117117
getToken(): string;
118+
119+
getUsername(): string;
118120
}

src/rhtap/modification/jenkinsfile.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,19 @@ export class EnableTPAVariablesModification implements JenkinsfileModification {
109109
};
110110
}
111111
}
112+
113+
export class EnableGitoAuthUsernameModification implements JenkinsfileModification {
114+
getModification(): ContentModifications {
115+
return {
116+
Jenkinsfile: [
117+
{
118+
oldContent: "/* GITOPS_AUTH_USERNAME = credentials('GITOPS_AUTH_USERNAME') */",
119+
newContent: "GITOPS_AUTH_USERNAME = credentials('GITOPS_AUTH_USERNAME')",
120+
},
121+
],
122+
};
123+
}
124+
}
112125
/**
113126
* Enum of available Jenkinsfile modification types
114127
*/
@@ -119,6 +132,7 @@ export enum JenkinsfileModificationType {
119132
DISABLE_QUAY_CREDENTIALS = 'DISABLE_QUAY_CREDENTIALS',
120133
ENABLE_COSIGN_PUBLIC_KEY = 'ENABLE_COSIGN_PUBLIC_KEY',
121134
ENABLE_TPA_VARIABLES = 'ENABLE_TPA_VARIABLES',
135+
GITOPS_AUTH_USERNAME = 'GITOPS_AUTH_USERNAME',
122136
}
123137

124138
/**
@@ -144,6 +158,8 @@ export class JenkinsfileModificationFactory {
144158
return new EnableCosignPublicKeyModification();
145159
case JenkinsfileModificationType.ENABLE_TPA_VARIABLES:
146160
return new EnableTPAVariablesModification();
161+
case JenkinsfileModificationType.GITOPS_AUTH_USERNAME:
162+
return new EnableGitoAuthUsernameModification();
147163
default:
148164
throw new Error(`Unknown Jenkinsfile modification type: ${type}`);
149165
}
@@ -218,6 +234,14 @@ export class JenkinsfileModifier {
218234
return this;
219235
}
220236

237+
enableGitoAuthUsername(): JenkinsfileModifier {
238+
const modification = JenkinsfileModificationFactory.create(
239+
JenkinsfileModificationType.GITOPS_AUTH_USERNAME
240+
).getModification();
241+
this.container.merge(modification);
242+
return this;
243+
}
244+
221245
getModifications(): ContentModifications {
222246
return this.container.getModifications();
223247
}

src/rhtap/postcreation/strategies/commands/addJenkinsSecretsCommand.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,12 @@ export class AddJenkinsSecretsCommand extends BaseCommand {
6363
}
6464

6565
private async addGitAuthSecrets(): Promise<void> {
66+
const username = this.git.getUsername();
6667
const password = this.getGitOpsAuthPassword();
6768
await this.jenkinsCI.addCredential(
6869
this.folderName,
6970
Credential.GITOPS_AUTH_PASSWORD,
70-
`fakeUsername:${password}`,
71+
`${username}:${password}`,
7172
CredentialType.USERNAME_PASSWORD
7273
);
7374
}
@@ -133,6 +134,7 @@ export class AddJenkinsSecretsCommand extends BaseCommand {
133134
throw new Error('Unsupported Git type');
134135
}
135136
}
137+
136138
//add ROX_CENTRAL_ENDPOINT
137139
private async addRoxCentralEndpointSecrets(): Promise<void> {
138140
await this.jenkinsCI.addCredential(

src/rhtap/postcreation/strategies/commands/jenkinsfileAndEnvModificationsOnGitopsRepoCommand.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,8 @@ export class JenkinsfileAndEnvModificationsOnGitopsRepoCommand extends BaseComma
3333

3434
modificationsContainer.merge(
3535
JenkinsfileModifier.create()
36-
.updateKubernetesAgentConfig()
3736
.enableRegistryPassword()
3837
.disableQuayCredentials()
39-
.enableTPAVariables()
4038
.getModifications()
4139
);
4240

src/rhtap/postcreation/strategies/commands/jenkinsfileAndEnvModificationsOnSourceRepoCommand.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export class JenkinsfileAndEnvModificationsOnSourceRepoCommand extends BaseComma
3939

4040
modificationsContainer.merge(
4141
JenkinsfileModifier.create()
42-
.updateKubernetesAgentConfig()
4342
.enableRegistryPassword()
4443
.disableQuayCredentials()
4544
.getModifications()

0 commit comments

Comments
 (0)