From 07584df882957b26bf62d7444d2e971c79ff2559 Mon Sep 17 00:00:00 2001 From: Etien Roznik <12816736+eroznik@users.noreply.github.com> Date: Sat, 23 Mar 2024 11:53:11 +0100 Subject: [PATCH] feat: expose secrets for notification templates (#3455) --- utils/record/record.go | 13 +++++++++++-- utils/record/record_test.go | 18 +++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/utils/record/record.go b/utils/record/record.go index 801db089b6..22424de0e3 100644 --- a/utils/record/record.go +++ b/utils/record/record.go @@ -289,7 +289,11 @@ func NewAPIFactorySettings(arInformer argoinformers.AnalysisRunInformer) api.Set InitGetVars: func(cfg *api.Config, configMap *corev1.ConfigMap, secret *corev1.Secret) (api.GetVars, error) { return func(obj map[string]any, dest services.Destination) map[string]any { - var vars = map[string]any{"rollout": obj, "time": timeExprs} + var vars = map[string]any{ + "rollout": obj, + "time": timeExprs, + "secrets": secret.Data, + } if arInformer == nil { log.Infof("Notification is not set for analysisRun Informer: %s", dest) @@ -313,7 +317,12 @@ func NewAPIFactorySettings(arInformer argoinformers.AnalysisRunInformer) api.Set } - vars = map[string]any{"rollout": obj, "analysisRuns": arsObj, "time": timeExprs} + vars = map[string]any{ + "rollout": obj, + "analysisRuns": arsObj, + "time": timeExprs, + "secrets": secret.Data, + } return vars }, nil }, diff --git a/utils/record/record_test.go b/utils/record/record_test.go index 2cc7afd12c..384dffdd2f 100644 --- a/utils/record/record_test.go +++ b/utils/record/record_test.go @@ -484,6 +484,18 @@ func TestNewAPIFactorySettings(t *testing.T) { }, } + expectedSecrets := map[string][]byte{ + "notification-secret": []byte("secret-value"), + } + + notificationsSecret := corev1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: "argocd-notifications-secret", + Namespace: "default", + }, + Data: expectedSecrets, + } + type expectedFunc func(obj map[string]interface{}, ar any) map[string]interface{} type arInformerFunc func([]*v1alpha1.AnalysisRun) argoinformers.AnalysisRunInformer @@ -506,6 +518,7 @@ func TestNewAPIFactorySettings(t *testing.T) { "rollout": obj, "analysisRuns": ar, "time": timeExprs, + "secrets": expectedSecrets, } }, }, @@ -531,6 +544,7 @@ func TestNewAPIFactorySettings(t *testing.T) { "rollout": obj, "analysisRuns": nil, "time": timeExprs, + "secrets": expectedSecrets, } }, }, @@ -545,6 +559,7 @@ func TestNewAPIFactorySettings(t *testing.T) { return map[string]interface{}{ "rollout": obj, "time": timeExprs, + "secrets": expectedSecrets, } }, }, @@ -570,6 +585,7 @@ func TestNewAPIFactorySettings(t *testing.T) { "rollout": obj, "analysisRuns": nil, "time": timeExprs, + "secrets": expectedSecrets, } }, }, @@ -579,7 +595,7 @@ func TestNewAPIFactorySettings(t *testing.T) { t.Run(test.name, func(t *testing.T) { settings := NewAPIFactorySettings(test.arInformer(test.ars)) - getVars, err := settings.InitGetVars(nil, nil, nil) + getVars, err := settings.InitGetVars(nil, nil, ¬ificationsSecret) require.NoError(t, err) if err != nil { t.Errorf("Unexpected error: %v", err)