Skip to content

Commit

Permalink
Merge pull request #54 from edenlabllc/bugfix/v0.45.0
Browse files Browse the repository at this point in the history
#29 - add support downloading exists SOPS Age keys.
  • Loading branch information
apanasiuk-el authored Jan 6, 2025
2 parents e9e75b9 + 133e225 commit bc300ee
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 82 deletions.
47 changes: 7 additions & 40 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"os"
"path/filepath"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -313,20 +312,8 @@ func initAWSProfile(c *cli.Context, conf *config.Config, gitSpec *git_handler.Gi
return err
}

if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in AWS Secrets Manager secrets",
conf.Tenant)
}

for key, val := range secrets {
zap.S().Infof("download AWS Secrets Manager secret %s to %s",
key, filepath.Join(conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
}

return nil
return newSecretCommands(conf, c, util.GetPwdPath("")).
WriteKeysInRootDir(secrets, "AWS Secrets Manager")
}

func initAzureProfile(c *cli.Context, conf *config.Config, gitSpec *git_handler.GitSpec) error {
Expand Down Expand Up @@ -398,17 +385,9 @@ func initAzureProfile(c *cli.Context, conf *config.Config, gitSpec *git_handler.
return err
}

if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in Azure Key Vault secrets",
conf.Tenant)
}

for key, val := range secrets {
zap.S().Infof("download Azure Key Vault secret %s to %s",
key, filepath.Join(conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
if err := newSecretCommands(conf, c, util.GetPwdPath("")).
WriteKeysInRootDir(secrets, "Azure Key Vault"); err != nil {
return err
}
}

Expand Down Expand Up @@ -446,20 +425,8 @@ func initGCPProfile(c *cli.Context, conf *config.Config, gitSpec *git_handler.Gi
return err
}

if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in GCP Secrets Manager secrets",
conf.Tenant)
}

for key, val := range secrets {
zap.S().Infof("download GCP Secrets Manager secret %s to %s",
key, filepath.Join(conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
}

return nil
return newSecretCommands(conf, c, util.GetPwdPath("")).
WriteKeysInRootDir(secrets, "GCP Secrets Manager")
}

func configDeleteAction(conf *config.Config) cli.ActionFunc {
Expand Down
66 changes: 24 additions & 42 deletions cmd/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,27 @@ func (sc *SecretCommands) CreateKeys() error {
return nil
}

func (sc *SecretCommands) WriteKeysInRootDir(secrets map[string][]byte, logOutput string) error {
if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in %s secrets",
sc.Conf.Tenant, logOutput)
} else {
if err := os.MkdirAll(sc.Conf.SopsAgeKeys, 0775); err != nil {
return err
}
}

for key, val := range secrets {
zap.S().Infof("download %s secret %s to %s",
logOutput, key, filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
}

return nil
}

func (sc *SecretCommands) DownloadKeys() error {
switch sc.Conf.ClusterProvider {
case aws_provider.AWSClusterProvider:
Expand All @@ -161,20 +182,7 @@ func (sc *SecretCommands) DownloadKeys() error {
return err
}

if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in AWS Secrets Manager secrets",
sc.Conf.Tenant)
}

for key, val := range secrets {
zap.S().Infof("download AWS Secrets Manager secret %s to %s",
key, filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
}

return nil
return sc.WriteKeysInRootDir(secrets, "AWS Secrets Manager")
case azure_provider.AzureClusterProvider:
if err := sc.Conf.NewAzureClient(sc.Ctx.Context, sc.Conf.Name); err != nil {
return err
Expand All @@ -185,20 +193,7 @@ func (sc *SecretCommands) DownloadKeys() error {
return err
}

if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in Azure Key Vault secrets",
sc.Conf.Tenant)
}

for key, val := range secrets {
zap.S().Infof("download Azure Key Vault secret %s to %s",
key, filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
}

return nil
return sc.WriteKeysInRootDir(secrets, "Azure Key Vault")
case google_provider.GoogleClusterProvider:
gcp := google_provider.NewGCPConfigure(sc.Ctx.Context, sc.Conf.GCPConfigure.AppCredentialsPath)

Expand All @@ -207,20 +202,7 @@ func (sc *SecretCommands) DownloadKeys() error {
return err
}

if len(secrets) == 0 {
zap.S().Warnf("SOPS Age keys contents for tenant %s not found in GCP Secrets Manager secrets",
sc.Conf.Tenant)
}

for key, val := range secrets {
zap.S().Infof("download GCP Secrets Manager secret %s to %s",
key, filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt))
if err := os.WriteFile(filepath.Join(sc.Conf.SopsAgeKeys, key+util.SopsAgeKeyExt), val, 0644); err != nil {
return err
}
}

return nil
return sc.WriteKeysInRootDir(secrets, "GCP Secrets Manager")
default:
return nil
}
Expand Down
1 change: 1 addition & 0 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- #29 - Added support for the AWS provider in Cluster API.
- #29 - Added support for the GCP provider in Cluster API.
- #29 - Added support for the Azure provider in Cluster API.
- #29 - Added support for downloading existing SOPS Age keys.
- #29 - Added the ability to create an SSH key pair for the AWS provider.
- #29 - Added GCP NAT router creation for the GCP provider.
- #29 - Added commands for managing Cluster API clusters to the cluster category commands.
Expand Down

0 comments on commit bc300ee

Please sign in to comment.