Skip to content

Commit

Permalink
feat: ability to deploy shared secret
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Oct 3, 2022
1 parent 457014f commit 708660e
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 24 deletions.
16 changes: 13 additions & 3 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,21 @@ func deploy(cmd *cobra.Command, args []string) error {

// filter configs with changed values
for _, c := range config.Configs {
found := false
for _, a := range all {
if c.Name == *a.Name && c.Value != *a.Value {
configsToDeploy = append(configsToDeploy, c)
if c.Name == *a.Name {
found = true

if c.Value != *a.Value {
configsToDeploy = append(configsToDeploy, c)
}
break
}
}

if !found {
configsToDeploy = append(configsToDeploy, c)
}
}

err = st.PutMany(configsToDeploy)
Expand All @@ -106,7 +116,7 @@ func deploy(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "failed to write params")
}

fmt.Printf("%d new configs deployed", len(configsToDeploy))
fmt.Printf("%d new configs deployed. service = %s, stage = %s", len(configsToDeploy), config.Service, stage)

return nil
}
Expand Down
43 changes: 24 additions & 19 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type rawConfig struct {
Service string

Config map[string]map[string]string
Secret map[string]string
Secret map[string]map[string]string
}

type Config struct {
Expand Down Expand Up @@ -62,41 +62,46 @@ func Load(param LoadParam) (*Config, error) {
}

func parseConfig(rc rawConfig, c *Config, param LoadParam) {
temp := map[string]string{}
c.Configs = []store.ConfigInput{}

defaultConfig := rc.Config["defaults"]
sharedConfig := rc.Config["shared"]
envConfig := rc.Config[param.Stage]

for key, value := range defaultConfig {
temp[formatPath(param.Stage, c.Service, key)] = value
}

for key, value := range sharedConfig {
temp[formatSharedPath(param.Stage, key)] = value
for key, value := range rc.Config["defaults"] {
c.Configs = append(c.Configs, store.ConfigInput{
Name: formatPath(param.Stage, c.Service, key),
Value: value,
Secret: false,
})
}

for key, value := range envConfig {
temp[formatPath(param.Stage, c.Service, key)] = value
for key, value := range rc.Config["shared"] {
c.Configs = append(c.Configs, store.ConfigInput{
Name: formatSharedPath(param.Stage, key),
Value: value,
Secret: false,
})
}

for key, value := range temp {
for key, value := range rc.Config[param.Stage] {
c.Configs = append(c.Configs, store.ConfigInput{
Name: key,
Name: formatPath(param.Stage, c.Service, key),
Value: value,
Secret: false,
})
}

for key, value := range rc.Secret {
for key, value := range rc.Secret["defaults"] {
c.Secrets = append(c.Secrets, store.ConfigInput{
Name: formatPath(param.Stage, c.Service, key),
Description: value,
Secret: true,
})
}

for key, value := range rc.Secret["shared"] {
c.Secrets = append(c.Secrets, store.ConfigInput{
Name: formatSharedPath(param.Stage, key),
Description: value,
Secret: true,
})
}

c.All = append(c.Secrets, c.Configs...)
}

Expand Down
8 changes: 6 additions & 2 deletions example/safebox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,9 @@ config:
SHARED_KEY: "shared key"

secret:
API_KEY: "key of the api endpoint"
DB_SECRET: "database secret"
defaults:
API_KEY: "key of the api endpoint"
DB_SECRET: "database secret"

shared:
APOLLO_KEY: "apollo key"

0 comments on commit 708660e

Please sign in to comment.