Skip to content

Commit

Permalink
Merge pull request #854 from rottencandy/fix/secret-label-916
Browse files Browse the repository at this point in the history
fix(secrets): Always add secretFor to remotesecret labels
  • Loading branch information
openshift-merge-bot[bot] authored Nov 10, 2023
2 parents 8ee1947 + 514ff2f commit 495da91
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
31 changes: 30 additions & 1 deletion src/components/Secrets/__tests___/secret-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,15 @@ describe('getTargetLabelsForRemoteSecret', () => {
...formValues,
targets: { application: null, component: null, environment: null },
}),
).toEqual({});
).toEqual({
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return application target labels for remote secret', () => {
expect(getTargetLabelsForRemoteSecret(formValues)).toEqual({
'appstudio.redhat.com/application': 'test-application',
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

Expand All @@ -407,6 +410,7 @@ describe('getTargetLabelsForRemoteSecret', () => {
expect(getTargetLabelsForRemoteSecret(fValues)).toEqual({
'appstudio.redhat.com/application': 'test-application',
'appstudio.openshift.io/component': 'test-component',
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

Expand All @@ -423,6 +427,31 @@ describe('getTargetLabelsForRemoteSecret', () => {
'appstudio.redhat.com/application': 'test-application',
'appstudio.openshift.io/component': 'test-component',
'appstudio.redhat.com/environment': 'test-environment',
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return correct label for build secret', () => {
expect(
getTargetLabelsForRemoteSecret({
...formValues,
secretFor: SecretFor.Build,
targets: { application: null, component: null, environment: null },
}),
).toEqual({
'ui.appstudio.redhat.com/secret-for': 'Build',
});
});

it('should return correct label for deployment secret', () => {
expect(
getTargetLabelsForRemoteSecret({
...formValues,
secretFor: SecretFor.Deployment,
targets: { application: null, component: null, environment: null },
}),
).toEqual({
'ui.appstudio.redhat.com/secret-for': 'Deployment',
});
});
});
Expand Down
7 changes: 5 additions & 2 deletions src/components/Secrets/utils/secret-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,11 @@ export const getSecretFormData = (values: AddSecretFormValues, namespace: string
export const getTargetLabelsForRemoteSecret = (
values: AddSecretFormValues,
): { [key: string]: string } => {
const labels = {};
const { application, component, environment } = values.targets;
const { targets, secretFor } = values;
const labels = {
[SecretByUILabel]: secretFor,
};
const { application, component, environment } = targets;

if (environment && environment !== TargetDropdownDefaults.ALL_ENVIRONMENTS)
labels[SecretSPILabel.ENVIRONMENT] = environment;
Expand Down

0 comments on commit 495da91

Please sign in to comment.