-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from springload/feature/dotenv
Add dotenv command to generate .env
- Loading branch information
Showing
5 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/apex/log" | ||
"github.com/imdario/mergo" | ||
"github.com/joho/godotenv" | ||
"github.com/spf13/cobra" | ||
"github.com/springload/ssm-parent/ssm" | ||
) | ||
|
||
// dotenvCmd represents the dotenv command | ||
var dotenvCmd = &cobra.Command{ | ||
Use: "dotenv <filename>", | ||
Short: "Writes dotenv file", | ||
Long: `Gathers parameters from SSM Parameter store, writes .env file and exits`, | ||
Args: cobra.ExactArgs(1), | ||
Run: func(cmd *cobra.Command, args []string) { | ||
megamap := make(map[string]string) | ||
parameters, err := ssm.GetParameters(names, paths, expand, strict, recursive) | ||
if err != nil { | ||
log.WithError(err).Fatal("Can't get parameters") | ||
} | ||
for _, parameter := range parameters { | ||
err = mergo.Merge(&megamap, ¶meter, mergo.WithOverride) | ||
if err != nil { | ||
log.WithError(err).Fatal("Can't merge maps") | ||
} | ||
} | ||
for key, value := range megamap { | ||
if expand { | ||
megamap[key] = ssm.ExpandValue(value) | ||
} | ||
} | ||
|
||
err = godotenv.Write(megamap, args[0]) | ||
if err != nil { | ||
log.WithError(err).Fatal("Can't write the dotenv file") | ||
} else { | ||
log.WithFields(log.Fields{"filename": args[0]}).Info("Wrote the .env file") | ||
|
||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(dotenvCmd) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters