From acacd532baf4c80487867c93c706113900c1632d Mon Sep 17 00:00:00 2001 From: Edgar Garcia <63310723+edgarulg@users.noreply.github.com> Date: Wed, 17 Jul 2024 10:03:21 -0600 Subject: [PATCH] fix: [ASSMT-476]: include Spinnaker credentialsInfo in the payload (#126) --- pipelines.go | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pipelines.go b/pipelines.go index 7e7726e..a30c342 100644 --- a/pipelines.go +++ b/pipelines.go @@ -89,6 +89,7 @@ func migrateSpinnakerPipelines() error { } var jsonBody []byte var pipelines []map[string]interface{} + var credentials []map[string]interface{} var err error if len(migrationReq.PipelineName) > 0 { jsonBody, err = getSinglePipeline(authMethod, migrationReq.PipelineName) @@ -106,7 +107,11 @@ func migrateSpinnakerPipelines() error { if err != nil { return err } - payload := map[string][]map[string]interface{}{"pipelines": pipelines} + credentials, err = getCredentialsInfo(authMethod) + if err != nil { + return err + } + payload := map[string][]map[string]interface{}{"pipelines": pipelines, "credentials": credentials} _, err = createSpinnakerPipelines(payload) return err } @@ -334,6 +339,22 @@ func getAllPipelines(authMethod string, appName string) ([]byte, error) { return GetWithAuth(migrationReq.SpinnakerHost, "applications/"+appName+"/pipelineConfigs", authMethod, migrationReq.Auth64, migrationReq.Cert, migrationReq.Key, migrationReq.AllowInsecureReq) } +func getCredentialsInfo(authMethod string) ([]map[string]interface{}, error) { + jsonBody, err := GetWithAuth(migrationReq.SpinnakerHost, "credentials", authMethod, migrationReq.Auth64, migrationReq.Cert, migrationReq.Key, migrationReq.AllowInsecureReq) + if err != nil { + return nil, err + } + credentials, err := normalizeJsonArray(jsonBody) + if err != nil { + return nil, err + } + filtered := make([]map[string]interface{}, 0) + for _, credential := range credentials { + filtered = append(filtered, map[string]interface{}{"name": credential["name"], "type": credential["type"]}) + } + return filtered, nil +} + // this is because there's no endpoint in gate to fetch pipeline config based on a pipeline id func findPipelineById(authMethod string, appName string, pipelineId string) (map[string]interface{}, error) {