Skip to content

Commit

Permalink
fix commands (#1491)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunkickr authored Jan 18, 2024
1 parent 287c2e3 commit 3162afc
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 50 deletions.
32 changes: 19 additions & 13 deletions cloud/organization/organization_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func AddOrgTokenToWorkspace(id, name, role, workspace string, out io.Writer, cli
return err
}
} else {
token, err = getOrganizationTokenByID(id, ctx.OrganizationShortName, client)
token, err = getOrganizationTokenByID(id, ctx.Organization, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -110,7 +110,7 @@ func AddOrgTokenToWorkspace(id, name, role, workspace string, out io.Writer, cli
Roles: updateOrganizationAPITokenRoles,
}

resp, err := client.UpdateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.OrganizationShortName, apiTokenID, updateOrganizationAPITokenRequest)
resp, err := client.UpdateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.Organization, apiTokenID, updateOrganizationAPITokenRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -167,7 +167,7 @@ func getOrganizationTokens(client astrocore.CoreClient) ([]astrocore.ApiToken, e
return []astrocore.ApiToken{}, user.ErrNoShortName
}

resp, err := client.ListOrganizationApiTokensWithResponse(httpContext.Background(), ctx.OrganizationShortName, &astrocore.ListOrganizationApiTokensParams{})
resp, err := client.ListOrganizationApiTokensWithResponse(httpContext.Background(), ctx.Organization, &astrocore.ListOrganizationApiTokensParams{})
if err != nil {
return []astrocore.ApiToken{}, err
}
Expand Down Expand Up @@ -259,8 +259,14 @@ func ListTokens(client astrocore.CoreClient, out io.Writer) error {
}
}
created := TimeAgo(apiTokens[i].CreatedAt)
createdBy := apiTokens[i].CreatedBy.FullName
tab.AddRow([]string{id, name, description, string(scope), role, created, *createdBy}, false)
var createdBy string
switch {
case apiTokens[i].CreatedBy.FullName != nil:
createdBy = *apiTokens[i].CreatedBy.FullName
case apiTokens[i].CreatedBy.ApiTokenName != nil:
createdBy = *apiTokens[i].CreatedBy.ApiTokenName
}
tab.AddRow([]string{id, name, description, string(scope), role, created, createdBy}, false)
}
tab.Print(out)

Expand All @@ -284,7 +290,7 @@ func ListTokenRoles(id string, client astrocore.CoreClient, out io.Writer) (err
if err != nil {
return err
}
apiToken, err = getOrganizationTokenByID(id, ctx.OrganizationShortName, client)
apiToken, err = getOrganizationTokenByID(id, ctx.Organization, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -327,7 +333,7 @@ func CreateToken(name, description, role string, expiration int, cleanOutput boo
if expiration != 0 {
CreateOrganizationAPITokenRequest.TokenExpiryPeriodInDays = &expiration
}
resp, err := client.CreateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.OrganizationShortName, CreateOrganizationAPITokenRequest)
resp, err := client.CreateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.Organization, CreateOrganizationAPITokenRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -368,7 +374,7 @@ func UpdateToken(id, name, newName, description, role string, out io.Writer, cli
return err
}
} else {
token, err = getOrganizationTokenByID(id, ctx.OrganizationShortName, client)
token, err = getOrganizationTokenByID(id, ctx.Organization, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -424,7 +430,7 @@ func UpdateToken(id, name, newName, description, role string, out io.Writer, cli
UpdateOrganizationAPITokenRequest.Roles = updateOrganizationAPITokenRoles
}

resp, err := client.UpdateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.OrganizationShortName, apiTokenID, UpdateOrganizationAPITokenRequest)
resp, err := client.UpdateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.Organization, apiTokenID, UpdateOrganizationAPITokenRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -458,7 +464,7 @@ func RotateToken(id, name string, cleanOutput, force bool, out io.Writer, client
return err
}
} else {
token, err = getOrganizationTokenByID(id, ctx.OrganizationShortName, client)
token, err = getOrganizationTokenByID(id, ctx.Organization, client)
if err != nil {
return err
}
Expand All @@ -475,7 +481,7 @@ func RotateToken(id, name string, cleanOutput, force bool, out io.Writer, client
return nil
}
}
resp, err := client.RotateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.OrganizationShortName, apiTokenID)
resp, err := client.RotateOrganizationApiTokenWithResponse(httpContext.Background(), ctx.Organization, apiTokenID)
if err != nil {
return err
}
Expand Down Expand Up @@ -517,7 +523,7 @@ func DeleteToken(id, name string, force bool, out io.Writer, client astrocore.Co
return err
}
} else {
token, err = getOrganizationTokenByID(id, ctx.OrganizationShortName, client)
token, err = getOrganizationTokenByID(id, ctx.Organization, client)
if err != nil {
return err
}
Expand Down Expand Up @@ -546,7 +552,7 @@ func DeleteToken(id, name string, force bool, out io.Writer, client astrocore.Co
}
}

resp, err := client.DeleteOrganizationApiTokenWithResponse(httpContext.Background(), ctx.OrganizationShortName, apiTokenID)
resp, err := client.DeleteOrganizationApiTokenWithResponse(httpContext.Background(), ctx.Organization, apiTokenID)
if err != nil {
return err
}
Expand Down
24 changes: 12 additions & 12 deletions cloud/team/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func CreateTeam(name, description, role string, out io.Writer, client astrocore.
Name: name,
OrganizationRole: &role,
}
resp, err := client.CreateTeamWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamCreateRequest)
resp, err := client.CreateTeamWithResponse(httpContext.Background(), ctx.Organization, teamCreateRequest)
if err != nil {
return err
}
Expand All @@ -83,7 +83,7 @@ func GetTeam(client astrocore.CoreClient, teamID string) (team astrocore.Team, e
return team, ErrNoShortName
}

resp, err := client.GetTeamWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamID)
resp, err := client.GetTeamWithResponse(httpContext.Background(), ctx.Organization, teamID)
if err != nil {
return team, err
}
Expand Down Expand Up @@ -139,7 +139,7 @@ func UpdateWorkspaceTeamRole(id, role, workspace string, out io.Writer, client a
teamID := team.Id

teamMutateRequest := astrocore.MutateWorkspaceTeamRoleRequest{Role: role}
resp, err := client.MutateWorkspaceTeamRoleWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, teamID, teamMutateRequest)
resp, err := client.MutateWorkspaceTeamRoleWithResponse(httpContext.Background(), ctx.Organization, workspace, teamID, teamMutateRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -204,7 +204,7 @@ func UpdateTeam(id, name, description, role string, out io.Writer, client astroc
teamUpdateRequest.Description = description
}

resp, err := client.UpdateTeamWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamID, teamUpdateRequest)
resp, err := client.UpdateTeamWithResponse(httpContext.Background(), ctx.Organization, teamID, teamUpdateRequest)
if err != nil {
return err
}
Expand All @@ -220,7 +220,7 @@ func UpdateTeam(id, name, description, role string, out io.Writer, client astroc
return err
}
teamMutateRoleRequest := astrocore.MutateOrgTeamRoleRequest{Role: role}
resp, err := client.MutateOrgTeamRoleWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamID, teamMutateRoleRequest)
resp, err := client.MutateOrgTeamRoleWithResponse(httpContext.Background(), ctx.Organization, teamID, teamMutateRoleRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -269,7 +269,7 @@ func RemoveWorkspaceTeam(id, workspace string, out io.Writer, client astrocore.C
}
}
teamID := team.Id
resp, err := client.DeleteWorkspaceTeamWithResponse(httpContext.Background(), ctx.OrganizationShortName, ctx.Workspace, teamID)
resp, err := client.DeleteWorkspaceTeamWithResponse(httpContext.Background(), ctx.Organization, ctx.Workspace, teamID)
if err != nil {
return err
}
Expand Down Expand Up @@ -324,7 +324,7 @@ func GetWorkspaceTeams(client astrocore.CoreClient, workspace string, limit int)
workspace = ctx.Workspace
}
for {
resp, err := client.ListWorkspaceTeamsWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, &astrocore.ListWorkspaceTeamsParams{
resp, err := client.ListWorkspaceTeamsWithResponse(httpContext.Background(), ctx.Organization, workspace, &astrocore.ListWorkspaceTeamsParams{
Offset: &offset,
Limit: &limit,
})
Expand Down Expand Up @@ -430,7 +430,7 @@ func AddWorkspaceTeam(id, role, workspace string, out io.Writer, client astrocor
mutateUserInput := astrocore.MutateWorkspaceTeamRoleRequest{
Role: role,
}
resp, err := client.MutateWorkspaceTeamRoleWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, teamID, mutateUserInput)
resp, err := client.MutateWorkspaceTeamRoleWithResponse(httpContext.Background(), ctx.Organization, workspace, teamID, mutateUserInput)
if err != nil {
return err
}
Expand All @@ -455,7 +455,7 @@ func GetOrgTeams(client astrocore.CoreClient) ([]astrocore.Team, error) {
}

for {
resp, err := client.ListOrganizationTeamsWithResponse(httpContext.Background(), ctx.OrganizationShortName, &astrocore.ListOrganizationTeamsParams{
resp, err := client.ListOrganizationTeamsWithResponse(httpContext.Background(), ctx.Organization, &astrocore.ListOrganizationTeamsParams{
Offset: &offset,
Limit: &teamPagnationLimit,
})
Expand Down Expand Up @@ -543,7 +543,7 @@ func Delete(id string, out io.Writer, client astrocore.CoreClient) error {
}
}
teamID := team.Id
resp, err := client.DeleteTeamWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamID)
resp, err := client.DeleteTeamWithResponse(httpContext.Background(), ctx.Organization, teamID)
if err != nil {
return err
}
Expand Down Expand Up @@ -618,7 +618,7 @@ func RemoveUser(teamID, teamMemberID string, out io.Writer, client astrocore.Cor
}
userID := teamMemberSelection.UserId

resp, err := client.RemoveTeamMemberWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamID, userID)
resp, err := client.RemoveTeamMemberWithResponse(httpContext.Background(), ctx.Organization, teamID, userID)
if err != nil {
return err
}
Expand Down Expand Up @@ -698,7 +698,7 @@ func AddUser(teamID, userID string, out io.Writer, client astrocore.CoreClient)
MemberIds: []string{userID},
}

resp, err := client.AddTeamMembersWithResponse(httpContext.Background(), ctx.OrganizationShortName, teamID, addTeamMembersRequest)
resp, err := client.AddTeamMembersWithResponse(httpContext.Background(), ctx.Organization, teamID, addTeamMembersRequest)
if err != nil {
return err
}
Expand Down
16 changes: 8 additions & 8 deletions cloud/user/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func CreateInvite(email, role string, out io.Writer, client astrocore.CoreClient
InviteeEmail: email,
Role: role,
}
resp, err := client.CreateUserInviteWithResponse(httpContext.Background(), ctx.OrganizationShortName, userInviteInput)
resp, err := client.CreateUserInviteWithResponse(httpContext.Background(), ctx.Organization, userInviteInput)
if err != nil {
return err
}
Expand Down Expand Up @@ -106,7 +106,7 @@ func UpdateUserRole(email, role string, out io.Writer, client astrocore.CoreClie
mutateUserInput := astrocore.MutateOrgUserRoleRequest{
Role: role,
}
resp, err := client.MutateOrgUserRoleWithResponse(httpContext.Background(), ctx.OrganizationShortName, userID, mutateUserInput)
resp, err := client.MutateOrgUserRoleWithResponse(httpContext.Background(), ctx.Organization, userID, mutateUserInput)
if err != nil {
return err
}
Expand Down Expand Up @@ -192,7 +192,7 @@ func GetOrgUsers(client astrocore.CoreClient) ([]astrocore.User, error) {
}

for {
resp, err := client.ListOrgUsersWithResponse(httpContext.Background(), ctx.OrganizationShortName, &astrocore.ListOrgUsersParams{
resp, err := client.ListOrgUsersWithResponse(httpContext.Background(), ctx.Organization, &astrocore.ListOrgUsersParams{
Offset: &offset,
Limit: &userPagnationLimit,
})
Expand Down Expand Up @@ -274,7 +274,7 @@ func AddWorkspaceUser(email, role, workspace string, out io.Writer, client astro
mutateUserInput := astrocore.MutateWorkspaceUserRoleRequest{
Role: role,
}
resp, err := client.MutateWorkspaceUserRoleWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, userID, mutateUserInput)
resp, err := client.MutateWorkspaceUserRoleWithResponse(httpContext.Background(), ctx.Organization, workspace, userID, mutateUserInput)
if err != nil {
return err
}
Expand Down Expand Up @@ -314,7 +314,7 @@ func UpdateWorkspaceUserRole(email, role, workspace string, out io.Writer, clien
Role: role,
}
fmt.Println("workspace: " + workspace)
resp, err := client.MutateWorkspaceUserRoleWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, userID, mutateUserInput)
resp, err := client.MutateWorkspaceUserRoleWithResponse(httpContext.Background(), ctx.Organization, workspace, userID, mutateUserInput)
if err != nil {
fmt.Println("error in MutateWorkspaceUserRoleWithResponse")
return err
Expand Down Expand Up @@ -370,7 +370,7 @@ func GetWorkspaceUsers(client astrocore.CoreClient, workspace string, limit int)
workspace = ctx.Workspace
}
for {
resp, err := client.ListWorkspaceUsersWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, &astrocore.ListWorkspaceUsersParams{
resp, err := client.ListWorkspaceUsersWithResponse(httpContext.Background(), ctx.Organization, workspace, &astrocore.ListWorkspaceUsersParams{
Offset: &offset,
Limit: &limit,
})
Expand Down Expand Up @@ -439,7 +439,7 @@ func RemoveWorkspaceUser(email, workspace string, out io.Writer, client astrocor
if err != nil {
return err
}
resp, err := client.DeleteWorkspaceUserWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspace, userID)
resp, err := client.DeleteWorkspaceUserWithResponse(httpContext.Background(), ctx.Organization, workspace, userID)
if err != nil {
return err
}
Expand Down Expand Up @@ -478,7 +478,7 @@ func GetUser(client astrocore.CoreClient, userID string) (user astrocore.User, e
return user, ErrNoShortName
}

resp, err := client.GetUserWithResponse(httpContext.Background(), ctx.OrganizationShortName, userID)
resp, err := client.GetUserWithResponse(httpContext.Background(), ctx.Organization, userID)
if err != nil {
return user, err
}
Expand Down
6 changes: 3 additions & 3 deletions cloud/workspace/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func Create(name, description, enforceCD string, out io.Writer, client astrocore
Description: &description,
Name: name,
}
resp, err := client.CreateWorkspaceWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspaceCreateRequest)
resp, err := client.CreateWorkspaceWithResponse(httpContext.Background(), ctx.Organization, workspaceCreateRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func Update(id, name, description, enforceCD string, out io.Writer, client astro
}
workspaceUpdateRequest.ApiKeyOnlyDeploymentsDefault = enforce
}
resp, err := client.UpdateWorkspaceWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspaceID, workspaceUpdateRequest)
resp, err := client.UpdateWorkspaceWithResponse(httpContext.Background(), ctx.Organization, workspaceID, workspaceUpdateRequest)
if err != nil {
return err
}
Expand Down Expand Up @@ -309,7 +309,7 @@ func Delete(id string, out io.Writer, client astrocore.CoreClient) error {
}
}
workspaceID := workspace.Id
resp, err := client.DeleteWorkspaceWithResponse(httpContext.Background(), ctx.OrganizationShortName, workspaceID)
resp, err := client.DeleteWorkspaceWithResponse(httpContext.Background(), ctx.Organization, workspaceID)
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 3162afc

Please sign in to comment.