Skip to content

Commit

Permalink
fix variable assignment when pulling via token
Browse files Browse the repository at this point in the history
  • Loading branch information
maidul98 committed Dec 10, 2022
1 parent f49fe39 commit aa55440
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions cli/packages/util/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,27 +196,26 @@ func GetSecretsFromAPIUsingInfisicalToken(infisicalToken string, envName string,
}

func GetAllEnvironmentVariables(projectId string, envName string) ([]models.SingleEnvironmentVariable, error) {
var envsFromApi []models.SingleEnvironmentVariable
infisicalToken := os.Getenv(INFISICAL_TOKEN_NAME)

if infisicalToken == "" {
hasUserLoggedInbefore, loggedInUserEmail, err := IsUserLoggedIn()
if err != nil {
log.Info("Unexpected issue occurred while checking login status. To see more details, add flag --debug")
log.Debugln(err)
return envsFromApi, err
return nil, err
}

if !hasUserLoggedInbefore {
log.Infoln("No logged in user. To login, please run command [infisical login]")
return envsFromApi, fmt.Errorf("user not logged in")
return nil, fmt.Errorf("user not logged in")
}

userCreds, err := GetUserCredsFromKeyRing(loggedInUserEmail)
if err != nil {
log.Infoln("Unable to get user creds from key ring")
log.Debug(err)
return envsFromApi, err
return nil, err
}

workspaceConfigs, err := GetAllWorkSpaceConfigsStartingFromCurrentPath()
Expand All @@ -226,25 +225,28 @@ func GetAllEnvironmentVariables(projectId string, envName string) ([]models.Sing

if len(workspaceConfigs) == 0 {
log.Infoln("Your local project is not connected to a Infisical project yet. Run command [infisical init]")
return envsFromApi, fmt.Errorf("project not initialized")
return nil, fmt.Errorf("project not initialized")
}

envsFromApi, err = GetSecretsFromAPIUsingCurrentLoggedInUser(envName, userCreds)
envsFromApi, err := 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 envsFromApi, err
return nil, err
}

return envsFromApi, nil

} else {
envsFromApi, err := 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)
return envsFromApi, err
return nil, err
}
}

return envsFromApi, nil
return envsFromApi, nil
}
}

func GetWorkSpacesFromAPI(userCreds models.UserCredentials) (workspaces []models.Workspace, err error) {
Expand Down

0 comments on commit aa55440

Please sign in to comment.