Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow users to expose project ID as env #2959

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cli/packages/cmd/dynamic_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func getDynamicSecretList(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -143,7 +143,7 @@ func createDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -270,7 +270,7 @@ func renewDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -373,7 +373,7 @@ func revokeDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -470,7 +470,7 @@ func listDynamicSecretLeaseByName(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down
4 changes: 2 additions & 2 deletions cli/packages/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ var exportCmd = &cobra.Command{
util.HandleError(err)
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err)
util.HandleError(err, "Unable to parse flag")
}

token, err := util.GetInfisicalToken(cmd)
Expand Down
6 changes: 3 additions & 3 deletions cli/packages/cmd/folder.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var getCmd = &cobra.Command{
}
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -86,7 +86,7 @@ var createCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -158,7 +158,7 @@ var deleteCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down
2 changes: 1 addition & 1 deletion cli/packages/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ var runCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down
10 changes: 5 additions & 5 deletions cli/packages/cmd/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ var secretsCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -162,7 +162,7 @@ var secretsSetCmd = &cobra.Command{
}
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -246,7 +246,7 @@ var secretsDeleteCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -335,7 +335,7 @@ func getSecretsByNames(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down Expand Up @@ -447,7 +447,7 @@ func generateExampleEnv(cmd *cobra.Command, args []string) {
util.HandleError(err, "Unable to parse flag")
}

projectId, err := cmd.Flags().GetString("projectId")
projectId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down
2 changes: 1 addition & 1 deletion cli/packages/cmd/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ var tokensCreateCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag")
}

workspaceId, err := cmd.Flags().GetString("projectId")
workspaceId, err := util.GetProjectId(cmd)
if err != nil {
util.HandleError(err, "Unable to parse flag")
}
Expand Down
13 changes: 13 additions & 0 deletions cli/packages/util/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ func GetInfisicalToken(cmd *cobra.Command) (token *models.TokenDetails, err erro

}

func GetProjectId(cmd *cobra.Command) (string, error) {
projectId, err := cmd.Flags().GetString("projectId")
if err != nil {
return "", err
}

if projectId == "" {
projectId = os.Getenv("INFISICAL_PROJECT_ID")
}

return projectId, nil
}

func UniversalAuthLogin(clientId string, clientSecret string) (api.UniversalAuthLoginResponse, error) {
httpClient := resty.New()
httpClient.SetRetryCount(10000).
Expand Down