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

Commit e5d55d0

Browse files
authored
Merge pull request #137 from cdr/resource-manager
Initial prototype of resources top command
2 parents 592bea6 + 1a1b6e3 commit e5d55d0

27 files changed

+406
-15
lines changed

ci/steps/gendocs.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ echo "Generating docs..."
77
cd "$(dirname "$0")"
88
cd ../../
99

10+
rm -rf ./docs
11+
mkdir ./docs
1012
go run ./cmd/coder gen-docs ./docs
1113

1214
# remove cobra footer from each file
1315
for filename in ./docs/*.md; do
1416
trimmed=$(head -n -1 "$filename")
15-
echo "$trimmed" > $filename
17+
echo "$trimmed" >$filename
1618
done
1719

18-
1920
if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
2021
echo "Documentation needs generation:"
2122
git -c color.ui=always status | grep --color=no '\e\[31m'

coder-sdk/env.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type Environment struct {
2121
UserID string `json:"user_id" tab:"-"`
2222
LastBuiltAt time.Time `json:"last_built_at" tab:"-"`
2323
CPUCores float32 `json:"cpu_cores" tab:"CPUCores"`
24-
MemoryGB int `json:"memory_gb" tab:"MemoryGB"`
24+
MemoryGB float32 `json:"memory_gb" tab:"MemoryGB"`
2525
DiskGB int `json:"disk_gb" tab:"DiskGB"`
2626
GPUs int `json:"gpus" tab:"GPUs"`
2727
Updating bool `json:"updating" tab:"Updating"`
@@ -93,6 +93,16 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
9393
return &env, nil
9494
}
9595

96+
// Environments lists environments returned by the given filter.
97+
// TODO: add the filter options, explore performance issues
98+
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
99+
var envs []Environment
100+
if err := c.requestBody(ctx, http.MethodGet, "/api/environments", nil, &envs); err != nil {
101+
return nil, err
102+
}
103+
return envs, nil
104+
}
105+
96106
// EnvironmentsByOrganization gets the list of environments owned by the given user.
97107
func (c Client) EnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error) {
98108
var envs []Environment

coder-sdk/org.go

+35-8
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,47 @@ package coder
33
import (
44
"context"
55
"net/http"
6+
"time"
67
)
78

8-
// Org describes an Organization in Coder
9-
type Org struct {
10-
ID string `json:"id"`
11-
Name string `json:"name"`
12-
Members []User `json:"members"`
9+
// Organization describes an Organization in Coder
10+
type Organization struct {
11+
ID string `json:"id"`
12+
Name string `json:"name"`
13+
Members []OrganizationUser `json:"members"`
1314
}
1415

15-
// Orgs gets all Organizations
16-
func (c Client) Orgs(ctx context.Context) ([]Org, error) {
17-
var orgs []Org
16+
// OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization
17+
type OrganizationUser struct {
18+
User
19+
OrganizationRoles []OrganizationRole `json:"organization_roles"`
20+
RolesUpdatedAt time.Time `json:"roles_updated_at"`
21+
}
22+
23+
// OrganizationRole defines an organization OrganizationRole
24+
type OrganizationRole string
25+
26+
// The OrganizationRole enum values
27+
const (
28+
RoleOrgMember OrganizationRole = "organization-member"
29+
RoleOrgAdmin OrganizationRole = "organization-admin"
30+
RoleOrgManager OrganizationRole = "organization-manager"
31+
)
32+
33+
// Organizations gets all Organizations
34+
func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
35+
var orgs []Organization
1836
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs", nil, &orgs); err != nil {
1937
return nil, err
2038
}
2139
return orgs, nil
2240
}
41+
42+
// OrgMembers get all members of the given organization
43+
func (c Client) OrgMembers(ctx context.Context, orgID string) ([]OrganizationUser, error) {
44+
var members []OrganizationUser
45+
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/members", nil, &members); err != nil {
46+
return nil, err
47+
}
48+
return members, nil
49+
}

docs/coder.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ coder provides a CLI for working with an existing Coder Enterprise installation
99
### Options
1010

1111
```
12-
-h, --help help for coder
12+
-h, --help help for coder
13+
-v, --verbose show verbose output
1314
```
1415

1516
### SEE ALSO

docs/coder_completion.md

+6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ MacOS:
5858
-h, --help help for completion
5959
```
6060

61+
### Options inherited from parent commands
62+
63+
```
64+
-v, --verbose show verbose output
65+
```
66+
6167
### SEE ALSO
6268

6369
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_config-ssh.md

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ coder config-ssh [flags]
1818
--remove remove the auto-generated Coder Enterprise ssh config
1919
```
2020

21+
### Options inherited from parent commands
22+
23+
```
24+
-v, --verbose show verbose output
25+
```
26+
2127
### SEE ALSO
2228

2329
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_envs.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Perform operations on the Coder environments owned by the active user.
1313
--user string Specify the user whose resources to target (default "me")
1414
```
1515

16+
### Options inherited from parent commands
17+
18+
```
19+
-v, --verbose show verbose output
20+
```
21+
1622
### SEE ALSO
1723

1824
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_envs_ls.md

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ coder envs ls [flags]
2121

2222
```
2323
--user string Specify the user whose resources to target (default "me")
24+
-v, --verbose show verbose output
2425
```
2526

2627
### SEE ALSO

docs/coder_envs_stop.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ coder envs stop [environment_name] [flags]
2020

2121
```
2222
--user string Specify the user whose resources to target (default "me")
23+
-v, --verbose show verbose output
2324
```
2425

2526
### SEE ALSO

docs/coder_login.md

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ coder login [Coder Enterprise URL eg. https://my.coder.domain/] [flags]
1616
-h, --help help for login
1717
```
1818

19+
### Options inherited from parent commands
20+
21+
```
22+
-v, --verbose show verbose output
23+
```
24+
1925
### SEE ALSO
2026

2127
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_logout.md

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ coder logout [flags]
1616
-h, --help help for logout
1717
```
1818

19+
### Options inherited from parent commands
20+
21+
```
22+
-v, --verbose show verbose output
23+
```
24+
1925
### SEE ALSO
2026

2127
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_secrets.md

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ Interact with secrets objects owned by the active user.
1313
--user string Specify the user whose resources to target (default "me")
1414
```
1515

16+
### Options inherited from parent commands
17+
18+
```
19+
-v, --verbose show verbose output
20+
```
21+
1622
### SEE ALSO
1723

1824
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_secrets_create.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ coder secrets create aws-credentials --from-file ./credentials.json
3232

3333
```
3434
--user string Specify the user whose resources to target (default "me")
35+
-v, --verbose show verbose output
3536
```
3637

3738
### SEE ALSO

docs/coder_secrets_ls.md

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ coder secrets ls [flags]
2020

2121
```
2222
--user string Specify the user whose resources to target (default "me")
23+
-v, --verbose show verbose output
2324
```
2425

2526
### SEE ALSO

docs/coder_secrets_rm.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ coder secrets rm mysql-password mysql-user
2626

2727
```
2828
--user string Specify the user whose resources to target (default "me")
29+
-v, --verbose show verbose output
2930
```
3031

3132
### SEE ALSO

docs/coder_secrets_view.md

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ coder secrets view mysql-password
2626

2727
```
2828
--user string Specify the user whose resources to target (default "me")
29+
-v, --verbose show verbose output
2930
```
3031

3132
### SEE ALSO

docs/coder_sh.md

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ coder sh backend-env
2222
-h, --help help for sh
2323
```
2424

25+
### Options inherited from parent commands
26+
27+
```
28+
-v, --verbose show verbose output
29+
```
30+
2531
### SEE ALSO
2632

2733
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_sync.md

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ coder sync [local directory] [<env name>:<remote directory>] [flags]
1717
--init do initial transfer and exit
1818
```
1919

20+
### Options inherited from parent commands
21+
22+
```
23+
-v, --verbose show verbose output
24+
```
25+
2026
### SEE ALSO
2127

2228
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_urls.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Interact with environment DevURLs
1212
-h, --help help for urls
1313
```
1414

15+
### Options inherited from parent commands
16+
17+
```
18+
-v, --verbose show verbose output
19+
```
20+
1521
### SEE ALSO
1622

1723
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_urls_create.md

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ coder urls create [env_name] [port] [--access <level>] [--name <name>] [flags]
1818
--name string DevURL name
1919
```
2020

21+
### Options inherited from parent commands
22+
23+
```
24+
-v, --verbose show verbose output
25+
```
26+
2127
### SEE ALSO
2228

2329
* [coder urls](coder_urls.md) - Interact with environment DevURLs

docs/coder_urls_ls.md

+6
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ coder urls ls [environment_name] [flags]
1717
-o, --output string human|json (default "human")
1818
```
1919

20+
### Options inherited from parent commands
21+
22+
```
23+
-v, --verbose show verbose output
24+
```
25+
2026
### SEE ALSO
2127

2228
* [coder urls](coder_urls.md) - Interact with environment DevURLs

docs/coder_urls_rm.md

+6
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ coder urls rm [environment_name] [port] [flags]
1616
-h, --help help for rm
1717
```
1818

19+
### Options inherited from parent commands
20+
21+
```
22+
-v, --verbose show verbose output
23+
```
24+
1925
### SEE ALSO
2026

2127
* [coder urls](coder_urls.md) - Interact with environment DevURLs

docs/coder_users.md

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Interact with Coder user accounts
1212
-h, --help help for users
1313
```
1414

15+
### Options inherited from parent commands
16+
17+
```
18+
-v, --verbose show verbose output
19+
```
20+
1521
### SEE ALSO
1622

1723
* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation

docs/coder_users_ls.md

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ coder users ls -o json | jq .[] | jq -r .email
2424
-o, --output string human | json (default "human")
2525
```
2626

27+
### Options inherited from parent commands
28+
29+
```
30+
-v, --verbose show verbose output
31+
```
32+
2733
### SEE ALSO
2834

2935
* [coder users](coder_users.md) - Interact with Coder user accounts

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/cmd.go

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import (
77
"github.com/spf13/cobra/doc"
88
)
99

10+
// verbose is a global flag for specifying that a command should give verbose output
11+
var verbose bool = false
12+
1013
// Make constructs the "coder" root command
1114
func Make() *cobra.Command {
1215
app := &cobra.Command{
@@ -24,9 +27,11 @@ func Make() *cobra.Command {
2427
makeEnvsCommand(),
2528
makeSyncCmd(),
2629
makeURLCmd(),
30+
makeResourceCmd(),
2731
completionCmd,
2832
genDocs(app),
2933
)
34+
app.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
3035
return app
3136
}
3237

0 commit comments

Comments
 (0)