Skip to content

Commit

Permalink
Hopefully fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
drogus committed Jun 27, 2024
1 parent 94b2e54 commit a51a4d6
Showing 1 changed file with 58 additions and 17 deletions.
75 changes: 58 additions & 17 deletions secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ func mapToYaml(data map[string]interface{}) (string, error) {

func resourceSecrets() *schema.Resource {
return &schema.Resource{
// Removed "directory_path" from the schema
Schema: map[string]*schema.Schema{
"secrets": {
Type: schema.TypeMap,
Expand Down Expand Up @@ -63,13 +62,25 @@ func secretPath(directoryPath string, env string, app string, secretName string,
}

func resourceSecretsCreate(d *schema.ResourceData, m interface{}) error {
config := m.(*Config) // Cast the interface{} to *Config
config, ok := m.(*Config) // Cast the interface{} to *Config
if !ok {
return fmt.Errorf("Could not fetch plugin config")
}
directoryPath := config.DirectoryPath // Use the directory path from the provider config
awsProfile := config.AwsProfile

secrets := d.Get("secrets").(map[string]interface{})
app := d.Get("app").(string)
env := d.Get("env").(string)
secrets, ok := d.Get("secrets").(map[string]interface{})
if !ok {
return fmt.Errorf("Could not fetch parameter secrets")
}
app, ok := d.Get("app").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter app")
}
env, ok := d.Get("env").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter env")
}

for secretName, val := range secrets {
err := createSecret(awsProfile, directoryPath, app, env, secretName, val)
Expand Down Expand Up @@ -165,12 +176,21 @@ func isNil(c interface{}) bool {
}

func resourceSecretsRead(d *schema.ResourceData, m interface{}) error {
config := m.(*Config) // Retrieve the provider configuration
config, ok := m.(*Config) // Retrieve the provider configuration
if !ok {
return fmt.Errorf("Could not fetch plugin config")
}
directoryPath := config.DirectoryPath
awsProfile := config.AwsProfile

app := d.Get("app").(string)
env := d.Get("env").(string)
app, ok := d.Get("app").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter app")
}
env, ok := d.Get("env").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter env")
}

decryptedSecrets, err := fetchExistingSecrets(awsProfile, directoryPath, env, app)
if err != nil {
Expand All @@ -186,13 +206,25 @@ func resourceSecretsRead(d *schema.ResourceData, m interface{}) error {
}

func resourceSecretsUpdate(d *schema.ResourceData, m interface{}) error {
config := m.(*Config)
config, ok := m.(*Config)
if !ok {
return fmt.Errorf("Could not fetch plugin config")
}
directoryPath := config.DirectoryPath
awsProfile := config.AwsProfile

definedSecrets := d.Get("secrets").(map[string]interface{})
app := d.Get("app").(string)
env := d.Get("env").(string)
definedSecrets, ok := d.Get("secrets").(map[string]interface{})
if !ok {
return fmt.Errorf("Could not fetch parameter secrets")
}
app, ok := d.Get("app").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter app")
}
env, ok := d.Get("env").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter env")
}
ageKeysPath := filepath.Join(directoryPath, "applications/clusters", env)

existingSecrets, err := fetchExistingSecrets(ageKeysPath, directoryPath, env, app)
Expand Down Expand Up @@ -257,7 +289,7 @@ func decryptSopsFile(awsProfile string, env string, filePath string) (map[string
err := cmd.Run()

if err != nil {
return nil, true, fmt.Errorf("%s", errb)
return nil, true, fmt.Errorf("%s", errb.String())
}

// Parse the output to extract the secret value
Expand All @@ -271,10 +303,19 @@ func decryptSopsFile(awsProfile string, env string, filePath string) (map[string
}

func resourceSecretsDelete(d *schema.ResourceData, m interface{}) error {
config := m.(*Config)
config, ok := m.(*Config)
if !ok {
return fmt.Errorf("Could not fetch plugin config")
}
directoryPath := config.DirectoryPath
app := d.Get("app").(string)
env := d.Get("env").(string)
app, ok := d.Get("app").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter app")
}
env, ok := d.Get("env").(string)
if !ok {
return fmt.Errorf("Could not fetch parameter env")
}
ageKeysPath := filepath.Join(directoryPath, "applications/clusters", env)

existingSecrets, err := fetchExistingSecrets(ageKeysPath, directoryPath, env, app)
Expand Down Expand Up @@ -314,7 +355,7 @@ func executeSopsEncrypt(env string, awsProfile string, sourcePath string, destPa
err := cmd.Run()

if err != nil {
return fmt.Errorf("%s", errb)
return fmt.Errorf("%s", errb.String())
}
return nil
}

0 comments on commit a51a4d6

Please sign in to comment.