Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit cbcbe0c

Browse files
committed
fixup! Initial prototype of resources command
1 parent 37ade46 commit cbcbe0c

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

coder-sdk/org.go

+14-10
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,40 @@ import (
66
"time"
77
)
88

9-
// Org describes an Organization in Coder
10-
type Org struct {
9+
// Organization describes an Organization in Coder
10+
type Organization struct {
1111
ID string `json:"id"`
1212
Name string `json:"name"`
1313
Members []OrganizationUser `json:"members"`
1414
}
1515

16+
// OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization
1617
type OrganizationUser struct {
1718
User
18-
OrganizationRoles []Role `json:"organization_roles"`
19+
OrganizationRoles []OrganizationRole `json:"organization_roles"`
1920
RolesUpdatedAt time.Time `json:"roles_updated_at"`
2021
}
2122

22-
type Role string
23+
// OrganizationRole defines an organization OrganizationRole
24+
type OrganizationRole string
2325

26+
// The OrganizationRole enum values
2427
const (
25-
RoleOrgMember Role = "organization-member"
26-
RoleOrgAdmin Role = "organization-admin"
27-
RoleOrgManager Role = "organization-manager"
28+
RoleOrgMember OrganizationRole = "organization-member"
29+
RoleOrgAdmin OrganizationRole = "organization-admin"
30+
RoleOrgManager OrganizationRole = "organization-manager"
2831
)
2932

30-
// Orgs gets all Organizations
31-
func (c Client) Orgs(ctx context.Context) ([]Org, error) {
32-
var orgs []Org
33+
// Organizations gets all Organizations
34+
func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
35+
var orgs []Organization
3336
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs", nil, &orgs); err != nil {
3437
return nil, err
3538
}
3639
return orgs, nil
3740
}
3841

42+
// OrgMembers get all members of the given organization
3943
func (c Client) OrgMembers(ctx context.Context, orgID string) ([]OrganizationUser, error) {
4044
var members []OrganizationUser
4145
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/members", nil, &members); err != nil {

internal/cmd/ceapi.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ import (
1212
// Helpers for working with the Coder Enterprise API.
1313

1414
// lookupUserOrgs gets a list of orgs the user is apart of.
15-
func lookupUserOrgs(user *coder.User, orgs []coder.Org) []coder.Org {
15+
func lookupUserOrgs(user *coder.User, orgs []coder.Organization) []coder.Organization {
1616
// NOTE: We don't know in advance how many orgs the user is in so we can't pre-alloc.
17-
var userOrgs []coder.Org
17+
var userOrgs []coder.Organization
1818

1919
for _, org := range orgs {
2020
for _, member := range org.Members {
@@ -36,7 +36,7 @@ func getEnvs(ctx context.Context, client *coder.Client, email string) ([]coder.E
3636
return nil, xerrors.Errorf("get user: %w", err)
3737
}
3838

39-
orgs, err := client.Orgs(ctx)
39+
orgs, err := client.Organizations(ctx)
4040
if err != nil {
4141
return nil, xerrors.Errorf("get orgs: %w", err)
4242
}

internal/cmd/resourcemanager.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ var resourceTop = &cobra.Command{
4343
return err
4444
}
4545

46-
orgs := make(map[string]coder.Org)
47-
orglist, err := client.Orgs(ctx)
46+
orgs := make(map[string]coder.Organization)
47+
orglist, err := client.Organizations(ctx)
4848
if err != nil {
4949
return err
5050
}
@@ -79,7 +79,7 @@ func resourcesFromEnv(env coder.Environment) resources {
7979
}
8080
}
8181

82-
func fmtEnvResources(env coder.Environment, orgs map[string]coder.Org) string {
82+
func fmtEnvResources(env coder.Environment, orgs map[string]coder.Organization) string {
8383
return fmt.Sprintf("%s\t%s\t[org: %s]", env.Name, resourcesFromEnv(env), orgs[env.OrganizationID].Name)
8484
}
8585

0 commit comments

Comments
 (0)