Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show organization name in infisical init command #1521

Merged
merged 6 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions cli/packages/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,25 @@ func CallLogin2V2(httpClient *resty.Client, request GetLoginTwoV2Request) (GetLo
return loginTwoV2Response, nil
}

func CallGetAllOrganizations(httpClient *resty.Client) (GetOrganizationsResponse, error) {
var orgResponse GetOrganizationsResponse
response, err := httpClient.
R().
SetResult(&orgResponse).
SetHeader("User-Agent", USER_AGENT).
Get(fmt.Sprintf("%v/v1/organization", config.INFISICAL_URL))

if err != nil {
return GetOrganizationsResponse{}, err
}

if response.IsError() {
return GetOrganizationsResponse{}, fmt.Errorf("CallGetAllOrganizations: Unsuccessful response: [response=%v]", response)
}

return orgResponse, nil
}

func CallGetAllWorkSpacesUserBelongsTo(httpClient *resty.Client) (GetWorkSpacesResponse, error) {
var workSpacesResponse GetWorkSpacesResponse
response, err := httpClient.
Expand All @@ -161,6 +180,22 @@ 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
rhythmbhiwani marked this conversation as resolved.
Show resolved Hide resolved
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
}

Expand Down
11 changes: 9 additions & 2 deletions cli/packages/api/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,17 @@ type GetWorkSpacesResponse struct {
Name string `json:"name"`
Plan string `json:"plan,omitempty"`
V int `json:"__v"`
Organization string `json:"organization,omitempty"`
Organization string `json:"orgId,omitempty"`
} `json:"workspaces"`
}

type GetOrganizationsResponse struct {
Organizations []struct {
ID string `json:"id"`
Name string `json:"name"`
} `json:"organizations"`
}

type Secret struct {
SecretKeyCiphertext string `json:"secretKeyCiphertext,omitempty"`
SecretKeyIV string `json:"secretKeyIV,omitempty"`
Expand Down Expand Up @@ -505,5 +512,5 @@ type GetRawSecretsV3Response struct {
SecretComment string `json:"secretComment"`
} `json:"secrets"`
Imports []any `json:"imports"`
ETag string
ETag string
}
2 changes: 1 addition & 1 deletion cli/packages/cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var initCmd = &cobra.Command{

var workspaceNames []string
for _, workspace := range workspaces {
workspaceNames = append(workspaceNames, workspace.Name)
workspaceNames = append(workspaceNames, fmt.Sprintf("%s (%s)", workspace.Name, workspace.Organization))
}

prompt := promptui.Select{
Expand Down
2 changes: 1 addition & 1 deletion cli/packages/models/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ type Workspace struct {
Name string `json:"name"`
Plan string `json:"plan,omitempty"`
V int `json:"__v"`
Organization string `json:"organization,omitempty"`
Organization string `json:"orgId,omitempty"`
}

type WorkspaceConfigFile struct {
Expand Down