From 514ff2f9a6eced191da60be94a3f786a298f3aa3 Mon Sep 17 00:00:00 2001 From: Mohammed Saud Date: Tue, 7 Nov 2023 17:39:29 +0530 Subject: [PATCH] fix(secrets): add secretFor to remotesecret labels --- .../Secrets/__tests___/secret-utils.spec.ts | 31 ++++++++++++++++++- src/components/Secrets/utils/secret-utils.ts | 7 +++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/components/Secrets/__tests___/secret-utils.spec.ts b/src/components/Secrets/__tests___/secret-utils.spec.ts index db71e9bb8..d31001c1a 100644 --- a/src/components/Secrets/__tests___/secret-utils.spec.ts +++ b/src/components/Secrets/__tests___/secret-utils.spec.ts @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); }); diff --git a/src/components/Secrets/utils/secret-utils.ts b/src/components/Secrets/utils/secret-utils.ts index ea9efb3b2..993590115 100644 --- a/src/components/Secrets/utils/secret-utils.ts +++ b/src/components/Secrets/utils/secret-utils.ts @@ -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;