Skip to content

Commit

Permalink
change flag --stage to --env
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Nov 19, 2022
1 parent 321b040 commit b164a2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions cli/packages/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ var runCmd = &cobra.Command{
Use: "run [any infisical run command flags] -- [your application start command]",
Short: "Used to inject environments variables into your application process",
DisableFlagsInUseLine: true,
Example: "infisical run --stage=prod -- npm run dev",
Example: "infisical run --env=prod -- npm run dev",
Args: cobra.MinimumNArgs(1),
PreRun: toggleDebug,
Run: func(cmd *cobra.Command, args []string) {
stageName, err := cmd.Flags().GetString("stage")
envName, err := cmd.Flags().GetString("env")
if err != nil {
log.Errorln("Unable to parse the stage flag")
log.Errorln("Unable to parse the environment flag")
log.Debugln(err)
return
}
Expand Down Expand Up @@ -67,14 +67,14 @@ var runCmd = &cobra.Command{
return
}

envsFromApi, err = util.GetSecretsFromAPIUsingCurrentLoggedInUser(stageName, userCreds)
envsFromApi, err = util.GetSecretsFromAPIUsingCurrentLoggedInUser(envName, userCreds)
if err != nil {
log.Errorln("Something went wrong when pulling secrets using your logged in credentials. If the issue persists, double check your project id/try logging in again.")
log.Debugln(err)
return
}
} else {
envsFromApi, err = util.GetSecretsFromAPIUsingInfisicalToken(infisicalToken, stageName, projectId)
envsFromApi, err = util.GetSecretsFromAPIUsingInfisicalToken(infisicalToken, envName, projectId)
if err != nil {
log.Errorln("Something went wrong when pulling secrets using your Infisical token. Double check the token, project id or environment name (dev, prod, ect.)")
log.Debugln(err)
Expand All @@ -88,7 +88,7 @@ var runCmd = &cobra.Command{

func init() {
rootCmd.AddCommand(runCmd)
runCmd.Flags().StringP("stage", "s", "dev", "Set the stage (dev, prod, etc.) from which your secrets should be pulled from")
runCmd.Flags().StringP("env", "e", "dev", "Set the environment (dev, prod, etc.) from which your secrets should be pulled from")
runCmd.Flags().String("projectId", "", "The project ID from which your secrets should be pulled from")
}

Expand Down
14 changes: 7 additions & 7 deletions cli/packages/util/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"golang.org/x/crypto/nacl/box"
)

func GetSecretsFromAPIUsingCurrentLoggedInUser(stageName string, userCreds models.UserCredentials) ([]models.SingleEnvironmentVariable, error) {
log.Debugln("stageName", stageName, "userCreds", userCreds)
func GetSecretsFromAPIUsingCurrentLoggedInUser(envName string, userCreds models.UserCredentials) ([]models.SingleEnvironmentVariable, error) {
log.Debugln("envName", envName, "userCreds", userCreds)
// check if user has configured a workspace
workspace, err := GetWorkSpaceFromFile()
if err != nil {
Expand All @@ -28,7 +28,7 @@ func GetSecretsFromAPIUsingCurrentLoggedInUser(stageName string, userCreds model
var pullSecretsRequestResponse models.PullSecretsResponse
response, err := httpClient.
R().
SetQueryParam("environment", stageName).
SetQueryParam("environment", envName).
SetQueryParam("channel", "cli").
SetResult(&pullSecretsRequestResponse).
Get(fmt.Sprintf("%v/%v/%v", INFISICAL_URL, "secret", workspace.WorkspaceId)) // need to change workspace id
Expand Down Expand Up @@ -97,9 +97,9 @@ func GetSecretsFromAPIUsingCurrentLoggedInUser(stageName string, userCreds model
return listOfEnv, nil
}

func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, stageName string, projectId string) ([]models.SingleEnvironmentVariable, error) {
if infisicalToken == "" || projectId == "" || stageName == "" {
return nil, errors.New("infisical token, project id and or stage name cannot be empty")
func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string, projectId string) ([]models.SingleEnvironmentVariable, error) {
if infisicalToken == "" || projectId == "" || envName == "" {
return nil, errors.New("infisical token, project id and or environment name cannot be empty")
}
splitToken := strings.Split(infisicalToken, ",")
JTWToken := splitToken[0]
Expand All @@ -113,7 +113,7 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, stageName strin
var pullSecretsByInfisicalTokenResponse models.PullSecretsByInfisicalTokenResponse
response, err := httpClient.
R().
SetQueryParam("environment", stageName).
SetQueryParam("environment", envName).
SetQueryParam("channel", "cli").
SetResult(&pullSecretsByInfisicalTokenResponse).
Get(fmt.Sprintf("%v/secret/%v/service-token", INFISICAL_URL, projectId))
Expand Down

0 comments on commit b164a2f

Please sign in to comment.