Skip to content

Commit

Permalink
feat: expose secrets for notification templates
Browse files Browse the repository at this point in the history
Signed-off-by: Etien Roznik <[email protected]>
  • Loading branch information
eroznik committed Mar 23, 2024
1 parent 0f52c93 commit ccc9603
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
13 changes: 11 additions & 2 deletions utils/record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
},
Expand Down
18 changes: 17 additions & 1 deletion utils/record/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -506,6 +518,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
"rollout": obj,
"analysisRuns": ar,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -531,6 +544,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
"rollout": obj,
"analysisRuns": nil,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -545,6 +559,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
return map[string]interface{}{
"rollout": obj,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -570,6 +585,7 @@ func TestNewAPIFactorySettings(t *testing.T) {
"rollout": obj,
"analysisRuns": nil,
"time": timeExprs,
"secrets": expectedSecrets,
}
},
},
Expand All @@ -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, &notificationsSecret)
require.NoError(t, err)
if err != nil {
t.Errorf("Unexpected error: %v", err)
Expand Down

0 comments on commit ccc9603

Please sign in to comment.