mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-09-22 13:39:35 +00:00
Reverted backend api changes
In CLI, now first asking org, then projects
This commit is contained in:
@@ -120,12 +120,11 @@ 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:"orgName,omitempty"`
|
||||
DisplayName *string `json:"displayName,omitempty"`
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Plan string `json:"plan,omitempty"`
|
||||
V int `json:"__v"`
|
||||
OrganizationId string `json:"orgId"`
|
||||
} `json:"workspaces"`
|
||||
}
|
||||
|
||||
|
||||
@@ -51,21 +51,19 @@ var initCmd = &cobra.Command{
|
||||
|
||||
httpClient := resty.New()
|
||||
httpClient.SetAuthToken(userCreds.UserCredentials.JTWToken)
|
||||
workspaceResponse, err := api.CallGetAllWorkSpacesUserBelongsTo(httpClient)
|
||||
|
||||
organizationResponse, err := api.CallGetAllOrganizations(httpClient)
|
||||
if err != nil {
|
||||
util.HandleError(err, "Unable to pull projects that belong to you")
|
||||
util.HandleError(err, "Unable to pull organizations that belong to you")
|
||||
}
|
||||
|
||||
workspaces := workspaceResponse.Workspaces
|
||||
organizations := organizationResponse.Organizations
|
||||
|
||||
workspaceNames, err := util.GetWorkspacesNameList(workspaceResponse)
|
||||
if err != nil {
|
||||
util.HandleError(err, "Error extracting workspace names")
|
||||
}
|
||||
organizationNames := util.GetOrganizationsNameList(organizationResponse)
|
||||
|
||||
prompt := promptui.Select{
|
||||
Label: "Which of your Infisical projects would you like to connect this project to?",
|
||||
Items: workspaceNames,
|
||||
Label: "Which of your Infisical organization would you like to get projects from?",
|
||||
Items: organizationNames,
|
||||
Size: 7,
|
||||
}
|
||||
|
||||
@@ -74,7 +72,27 @@ var initCmd = &cobra.Command{
|
||||
util.HandleError(err)
|
||||
}
|
||||
|
||||
err = writeWorkspaceFile(workspaces[index])
|
||||
selectedOrganization := organizations[index]
|
||||
|
||||
workspaceResponse, err := api.CallGetAllWorkSpacesUserBelongsTo(httpClient)
|
||||
if err != nil {
|
||||
util.HandleError(err, "Unable to pull projects that belong to you")
|
||||
}
|
||||
|
||||
filteredWorkspaces, workspaceNames := util.GetWorkspacesInOrganization(workspaceResponse, selectedOrganization.ID)
|
||||
|
||||
prompt = promptui.Select{
|
||||
Label: "Which of your Infisical projects would you like to connect this project to?",
|
||||
Items: workspaceNames,
|
||||
Size: 7,
|
||||
}
|
||||
|
||||
index, _, err = prompt.Run()
|
||||
if err != nil {
|
||||
util.HandleError(err)
|
||||
}
|
||||
|
||||
err = writeWorkspaceFile(filteredWorkspaces[index])
|
||||
if err != nil {
|
||||
util.HandleError(err)
|
||||
}
|
||||
|
||||
@@ -45,12 +45,11 @@ 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:"orgName,omitempty"`
|
||||
DisplayName *string `json:"displayName,omitempty"`
|
||||
ID string `json:"_id"`
|
||||
Name string `json:"name"`
|
||||
Plan string `json:"plan,omitempty"`
|
||||
V int `json:"__v"`
|
||||
OrganizationId string `json:"orgId"`
|
||||
}
|
||||
|
||||
type WorkspaceConfigFile struct {
|
||||
|
||||
@@ -4,24 +4,42 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/Infisical/infisical-merge/packages/api"
|
||||
"github.com/Infisical/infisical-merge/packages/models"
|
||||
)
|
||||
|
||||
func GetWorkspacesNameList(workspaceResponse api.GetWorkSpacesResponse) ([]string, error) {
|
||||
workspaces := workspaceResponse.Workspaces
|
||||
func GetOrganizationsNameList(organizationResponse api.GetOrganizationsResponse) []string {
|
||||
organizations := organizationResponse.Organizations
|
||||
|
||||
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)
|
||||
if len(organizations) == 0 {
|
||||
message := fmt.Sprintf("You don't have any organization created in Infisical. You must first create a organization at %s", INFISICAL_TOKEN_NAME)
|
||||
PrintErrorMessageAndExit(message)
|
||||
}
|
||||
|
||||
var organizationNames []string
|
||||
for _, workspace := range organizations {
|
||||
organizationNames = append(organizationNames, workspace.Name)
|
||||
}
|
||||
|
||||
return organizationNames
|
||||
}
|
||||
|
||||
func GetWorkspacesInOrganization(workspaceResponse api.GetWorkSpacesResponse, orgId string) ([]models.Workspace, []string) {
|
||||
workspaces := workspaceResponse.Workspaces
|
||||
|
||||
var filteredWorkspaces []models.Workspace
|
||||
var workspaceNames []string
|
||||
|
||||
for _, workspace := range workspaces {
|
||||
if workspace.DisplayName != nil {
|
||||
workspaceNames = append(workspaceNames, *workspace.DisplayName)
|
||||
} else {
|
||||
if workspace.OrganizationId == orgId {
|
||||
filteredWorkspaces = append(filteredWorkspaces, workspace)
|
||||
workspaceNames = append(workspaceNames, workspace.Name)
|
||||
}
|
||||
}
|
||||
|
||||
return workspaceNames, nil
|
||||
if len(filteredWorkspaces) == 0 {
|
||||
message := fmt.Sprintf("You don't have any projects created in Infisical organization. You must first create a project at %s", INFISICAL_TOKEN_NAME)
|
||||
PrintErrorMessageAndExit(message)
|
||||
}
|
||||
|
||||
return filteredWorkspaces, workspaceNames
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user