Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support secret manager scope #96

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading