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:
Rhythm Bhiwani
2024-03-03 12:12:25 +05:30
parent 2192985291
commit 756c1e5098
8 changed files with 69 additions and 37 deletions

View File

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