Reverted backend api changes

In CLI, now first asking org, then projects
This commit is contained in:
Rhythm Bhiwani
2024-03-05 03:08:13 +05:30
parent 756c1e5098
commit c7bbe82f4a
7 changed files with 67 additions and 56 deletions

View File

@@ -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
}