allow export by explicit projectId

This commit is contained in:
Maidul Islam
2023-03-01 17:36:02 -05:00
parent 1f05d6ea4d
commit d3d5ead6ed
3 changed files with 12 additions and 1 deletions
+7 -1
View File
@@ -49,6 +49,11 @@ var exportCmd = &cobra.Command{
util.HandleError(err) util.HandleError(err)
} }
projectId, err := cmd.Flags().GetString("projectId")
if err != nil {
util.HandleError(err)
}
format, err := cmd.Flags().GetString("format") format, err := cmd.Flags().GetString("format")
if err != nil { if err != nil {
util.HandleError(err) util.HandleError(err)
@@ -69,7 +74,7 @@ var exportCmd = &cobra.Command{
util.HandleError(err, "Unable to parse flag") util.HandleError(err, "Unable to parse flag")
} }
secrets, err := util.GetAllEnvironmentVariables(models.GetAllSecretsParameters{Environment: environmentName, InfisicalToken: infisicalToken, TagSlugs: tagSlugs}) secrets, err := util.GetAllEnvironmentVariables(models.GetAllSecretsParameters{Environment: environmentName, InfisicalToken: infisicalToken, TagSlugs: tagSlugs, WorkspaceId: projectId})
if err != nil { if err != nil {
util.HandleError(err, "Unable to fetch secrets") util.HandleError(err, "Unable to fetch secrets")
} }
@@ -106,6 +111,7 @@ func init() {
exportCmd.Flags().Bool("secret-overriding", true, "Prioritizes personal secrets, if any, with the same name over shared secrets") exportCmd.Flags().Bool("secret-overriding", true, "Prioritizes personal secrets, if any, with the same name over shared secrets")
exportCmd.Flags().String("token", "", "Fetch secrets using the Infisical Token") exportCmd.Flags().String("token", "", "Fetch secrets using the Infisical Token")
exportCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs") exportCmd.Flags().StringP("tags", "t", "", "filter secrets by tag slugs")
exportCmd.Flags().String("projectId", "", "manually set the projectId to fetch secrets from")
} }
// Format according to the format flag // Format according to the format flag
+1
View File
@@ -55,4 +55,5 @@ type GetAllSecretsParameters struct {
EnvironmentPassedViaFlag bool EnvironmentPassedViaFlag bool
InfisicalToken string InfisicalToken string
TagSlugs string TagSlugs string
WorkspaceId string
} }
+4
View File
@@ -152,6 +152,10 @@ func GetAllEnvironmentVariables(params models.GetAllSecretsParameters) ([]models
return nil, err return nil, err
} }
if params.WorkspaceId != "" {
workspaceFile.WorkspaceId = params.WorkspaceId
}
// Verify environment // Verify environment
err = ValidateEnvironmentName(params.Environment, workspaceFile.WorkspaceId, loggedInUserDetails.UserCredentials) err = ValidateEnvironmentName(params.Environment, workspaceFile.WorkspaceId, loggedInUserDetails.UserCredentials)
if err != nil { if err != nil {