Skip to content

Commit

Permalink
Support secret manager scope (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
puthrayaharness authored Mar 6, 2024
1 parent cb1ca48 commit 3a51e78
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 28 deletions.
28 changes: 14 additions & 14 deletions constants.go
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package main

const (
SecretManager EntityType = "SECRET_MANAGER"
Secret = "SECRET"
Service = "SERVICE"
Connector = "CONNECTOR"
Application = "APPLICATION"
Workflow = "WORKFLOW"
Trigger = "TRIGGER"
WorkflowExecution = "WORKFLOW_EXECUTION"
Pipeline = "PIPELINE"
Infrastructure = "INFRA"
Environment = "ENVIRONMENT"
ApplicationManifest = "MANIFEST"
Template = "TEMPLATE"
UserGroups = "USER_GROUP"
SecretManager = "SECRET_MANAGER"
Secret = "SECRET"
Service = "SERVICE"
Connector = "CONNECTOR"
Application = "APPLICATION"
Workflow = "WORKFLOW"
Trigger = "TRIGGER"
WorkflowExecution = "WORKFLOW_EXECUTION"
Pipeline = "PIPELINE"
Infrastructure = "INFRA"
Environment = "ENVIRONMENT"
ApplicationManifest = "MANIFEST"
Template = "TEMPLATE"
UserGroups = "USER_GROUP"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ func LoadOverridesFromFile(filePath string) map[string]EntityOverrideInput {
for i, override := range data.Overrides {
assertNotBlank(override.Type, fmt.Sprintf("Type cannot be blank in overrides for index - %d", i))
assertNotAllBlank(fmt.Sprintf("Name, Identifier & Scope are blank in overrides for index - %d", i), override.Name, override.Identifier, override.Scope)
assertAllowedValues(override.Type, []string{UserGroups, Template, Connector, Secret, Service, Environment, Workflow, Pipeline}, fmt.Sprintf("Only a few types of entities support overrides for index %d", i))
assertAllowedValues(override.Type, []string{UserGroups, Template, Connector, Secret, Service, Environment, Workflow, Pipeline, SecretManager}, fmt.Sprintf("Only a few types of entities support overrides for index %d", i))
if len(strings.TrimSpace(override.ID)) > 0 {
overrides[fmt.Sprintf("CgEntityId(id=%s, type=%s)", override.ID, override.Type)] = EntityOverrideInput{
Name: override.Name,
Expand Down
13 changes: 10 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var migrationReq = struct {
Environment string `survey:"environment"`
Account string `survey:"account"`
SecretScope string `survey:"secretScope"`
SecretManagerScope string `survey:"secretManagerScope"`
ConnectorScope string `survey:"connectorScope"`
WorkflowScope string `survey:"workflowScope"`
PipelineScope string `survey:"pipelineScope"`
Expand Down Expand Up @@ -71,15 +72,16 @@ var migrationReq = struct {
}{}

func getReqBody(entityType EntityType, filter Filter) RequestBody {
secretScope := getOrDefault(migrationReq.SecretScope, Project)
inputs := Inputs{
Overrides: LoadOverridesFromFile(migrationReq.OverrideFile),
Replace: LoadCustomeStringsFromFile(migrationReq.CustomStringsFile),
Expressions: LoadYamlFromFile(migrationReq.CustomExpressionsFile),
Settings: LoadSettingsFromFile(migrationReq.OverrideFile),
Defaults: Defaults{
Secret: EntityDefaults{Scope: getOrDefault(migrationReq.SecretScope, Project)},
SecretManager: EntityDefaults{Scope: getOrDefault(migrationReq.SecretScope, Project)},
SecretManagerTemplate: EntityDefaults{Scope: getOrDefault(migrationReq.SecretScope, Project)},
Secret: EntityDefaults{Scope: secretScope},
SecretManager: EntityDefaults{Scope: getOrDefault(migrationReq.SecretManagerScope, secretScope)},
SecretManagerTemplate: EntityDefaults{Scope: getOrDefault(migrationReq.SecretManagerScope, secretScope)},
Connector: EntityDefaults{Scope: getOrDefault(migrationReq.ConnectorScope, Project)},
Template: EntityDefaults{Scope: getOrDefault(migrationReq.TemplateScope, Project)},
Environment: EntityDefaults{Scope: getOrDefault(migrationReq.EnvironmentScope, Project)},
Expand Down Expand Up @@ -225,6 +227,11 @@ func main() {
Usage: "`SCOPE` to create secrets in. Possible values - account, org, project",
Destination: &migrationReq.SecretScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "secret-manager-scope",
Usage: "`SCOPE` to create secret managers in. Possible values - account, org, project",
Destination: &migrationReq.SecretManagerScope,
}),
altsrc.NewStringFlag(&cli.StringFlag{
Name: "connector-scope",
Usage: "`SCOPE` to create connectors in. Possible values - account, org, project",
Expand Down
21 changes: 11 additions & 10 deletions projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,17 @@ func bulkCreateProject(*cli.Context) error {

func writeYamlToFile(appId string, appName string, orgIdentifier string, projectIdentifier string) error {
yamlData := map[string]string{
"env": migrationReq.Environment,
"account": migrationReq.Account,
"api-key": migrationReq.Auth,
"app": appId,
"org": orgIdentifier,
"project": projectIdentifier,
"secret-scope": migrationReq.SecretScope,
"connector-scope": migrationReq.ConnectorScope,
"template-scope": migrationReq.TemplateScope,
"workflow-scope": Project,
"env": migrationReq.Environment,
"account": migrationReq.Account,
"api-key": migrationReq.Auth,
"app": appId,
"org": orgIdentifier,
"project": projectIdentifier,
"secret-scope": migrationReq.SecretScope,
"secret-manager-scope": migrationReq.SecretManagerScope,
"connector-scope": migrationReq.ConnectorScope,
"template-scope": migrationReq.TemplateScope,
"workflow-scope": Project,
}

yamlContent, err := yaml.Marshal(&yamlData)
Expand Down

0 comments on commit 3a51e78

Please sign in to comment.