-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add parameter store option to get env values
- Loading branch information
Leonardo Biffi
committed
Nov 24, 2023
1 parent
ca458ad
commit bb7f28b
Showing
7 changed files
with
279 additions
and
10 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
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
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
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,109 @@ | ||
package parameters | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/joho/godotenv" | ||
"github.com/leonardobiffi/envctl/config" | ||
"github.com/leonardobiffi/envctl/platform/aws" | ||
"github.com/leonardobiffi/envctl/util/system/exit" | ||
) | ||
|
||
func GetParameters(path string, env string, region string, profile string, envFile string) map[string]string { | ||
if envFile != "" { | ||
parameters, err := godotenv.Read(envFile) | ||
|
||
if err != nil { | ||
exit.Error("Could not read env file " + envFile) | ||
} | ||
|
||
return parameters | ||
} | ||
|
||
conf := config.GetConfig() | ||
|
||
if env == "" { | ||
env = os.Getenv("ENVIRONMENT") | ||
} | ||
|
||
if env == "" { | ||
env = conf.DefaultEnvironment | ||
} | ||
|
||
if path == "" { | ||
path = os.Getenv("PARAMETER_NAME") | ||
} | ||
|
||
if path == "" && env == "" { | ||
exit.Error("Parameter Name is required to list environments. Set -parameter flag.") | ||
} | ||
|
||
if path == "" && env != "" { | ||
if _, ok := conf.Environments[env]; !ok { | ||
exit.Error("Environment '" + env + "' does not exist.") | ||
} | ||
|
||
path = conf.Environments[env] | ||
} | ||
|
||
if region == "" { | ||
region = conf.Region | ||
} | ||
|
||
if profile == "" { | ||
profile = conf.Profile | ||
} | ||
|
||
return aws.GetParameters(profile, region, path) | ||
} | ||
|
||
// UpdateParameters sets appropriate config and updates parameters on aws. | ||
func UpdateParameters(parameterPath string, env string, region string, profile string, envFile string) { | ||
if envFile == "" { | ||
exit.Error("Env file is required to update parameters. Set --envfile flag.") | ||
} | ||
|
||
if envFile != "" { | ||
parameters, err := godotenv.Read(envFile) | ||
|
||
if err != nil { | ||
exit.Error("Could not read env file " + envFile) | ||
} | ||
|
||
conf := config.GetConfig() | ||
|
||
if env == "" { | ||
env = os.Getenv("ENVIRONMENT") | ||
} | ||
|
||
if env == "" { | ||
env = conf.DefaultEnvironment | ||
} | ||
|
||
if parameterPath == "" { | ||
parameterPath = os.Getenv("PARAMETER_NAME") | ||
} | ||
|
||
if parameterPath == "" && env == "" { | ||
exit.Error("Parameter Path is required to list environments. Set -parameter flag.") | ||
} | ||
|
||
if parameterPath == "" && env != "" { | ||
if _, ok := conf.Environments[env]; !ok { | ||
exit.Error("Environment '" + env + "' does not exist.") | ||
} | ||
|
||
parameterPath = conf.Environments[env] | ||
} | ||
|
||
if region == "" { | ||
region = conf.Region | ||
} | ||
|
||
if profile == "" { | ||
profile = conf.Profile | ||
} | ||
|
||
aws.UpdateParameters(profile, region, parameterPath, parameters) | ||
} | ||
} |
Oops, something went wrong.