mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Added populateOrgName param in /v1/workspace api which adds orgName and displayName in result
Updated the CLI to use this new paramter to display organization name with project name with support for backward compatibility keeping original behaviour for older apis
This commit is contained in:
@@ -170,6 +170,7 @@ func CallGetAllWorkSpacesUserBelongsTo(httpClient *resty.Client) (GetWorkSpacesR
|
||||
R().
|
||||
SetResult(&workSpacesResponse).
|
||||
SetHeader("User-Agent", USER_AGENT).
|
||||
SetQueryParam("populateOrgName", "true").
|
||||
Get(fmt.Sprintf("%v/v1/workspace", config.INFISICAL_URL))
|
||||
|
||||
if err != nil {
|
||||
@@ -180,22 +181,6 @@ func CallGetAllWorkSpacesUserBelongsTo(httpClient *resty.Client) (GetWorkSpacesR
|
||||
return GetWorkSpacesResponse{}, fmt.Errorf("CallGetAllWorkSpacesUserBelongsTo: Unsuccessful response: [response=%v]", response)
|
||||
}
|
||||
|
||||
// Call the organization API
|
||||
orgResponse, err := CallGetAllOrganizations(httpClient)
|
||||
if err != nil {
|
||||
return GetWorkSpacesResponse{}, err
|
||||
}
|
||||
|
||||
// Update organization names in workspacesResponse
|
||||
for i, workspace := range workSpacesResponse.Workspaces {
|
||||
for _, organization := range orgResponse.Organizations {
|
||||
if workspace.Organization == organization.ID {
|
||||
workSpacesResponse.Workspaces[i].Organization = organization.Name
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return workSpacesResponse, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -120,11 +120,12 @@ type PullSecretsByInfisicalTokenResponse struct {
|
||||
|
||||
type GetWorkSpacesResponse struct {
|
||||
Workspaces []struct {
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Plan string `json:"plan,omitempty"`
|
||||
V int `json:"__v"`
|
||||
Organization string `json:"orgId,omitempty"`
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Plan string `json:"plan,omitempty"`
|
||||
V int `json:"__v"`
|
||||
Organization *string `json:"orgName,omitempty"`
|
||||
DisplayName *string `json:"displayName,omitempty"`
|
||||
} `json:"workspaces"`
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/Infisical/infisical-merge/packages/api"
|
||||
"github.com/Infisical/infisical-merge/packages/models"
|
||||
@@ -58,14 +57,10 @@ var initCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
workspaces := workspaceResponse.Workspaces
|
||||
if len(workspaces) == 0 {
|
||||
message := fmt.Sprintf("You don't have any projects created in Infisical. You must first create a project at %s", util.INFISICAL_TOKEN_NAME)
|
||||
util.PrintErrorMessageAndExit(message)
|
||||
}
|
||||
|
||||
var workspaceNames []string
|
||||
for _, workspace := range workspaces {
|
||||
workspaceNames = append(workspaceNames, fmt.Sprintf("%s (%s)", workspace.Name, workspace.Organization))
|
||||
workspaceNames, err := util.GetWorkspacesNameList(workspaceResponse)
|
||||
if err != nil {
|
||||
util.HandleError(err, "Error extracting workspace names")
|
||||
}
|
||||
|
||||
prompt := promptui.Select{
|
||||
|
||||
@@ -45,11 +45,12 @@ type SingleFolder struct {
|
||||
}
|
||||
|
||||
type Workspace struct {
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Plan string `json:"plan,omitempty"`
|
||||
V int `json:"__v"`
|
||||
Organization string `json:"orgId,omitempty"`
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Plan string `json:"plan,omitempty"`
|
||||
V int `json:"__v"`
|
||||
Organization *string `json:"orgName,omitempty"`
|
||||
DisplayName *string `json:"displayName,omitempty"`
|
||||
}
|
||||
|
||||
type WorkspaceConfigFile struct {
|
||||
|
||||
27
cli/packages/util/init.go
Normal file
27
cli/packages/util/init.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Infisical/infisical-merge/packages/api"
|
||||
)
|
||||
|
||||
func GetWorkspacesNameList(workspaceResponse api.GetWorkSpacesResponse) ([]string, error) {
|
||||
workspaces := workspaceResponse.Workspaces
|
||||
|
||||
if len(workspaces) == 0 {
|
||||
message := fmt.Sprintf("You don't have any projects created in Infisical. You must first create a project at %s", INFISICAL_TOKEN_NAME)
|
||||
PrintErrorMessageAndExit(message)
|
||||
}
|
||||
|
||||
var workspaceNames []string
|
||||
for _, workspace := range workspaces {
|
||||
if workspace.DisplayName != nil {
|
||||
workspaceNames = append(workspaceNames, *workspace.DisplayName)
|
||||
} else {
|
||||
workspaceNames = append(workspaceNames, workspace.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return workspaceNames, nil
|
||||
}
|
||||
Reference in New Issue
Block a user