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

Initial prototype of resources command #137

Merged
merged 6 commits into from
Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 3 additions & 2 deletions ci/steps/gendocs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ echo "Generating docs..."
cd "$(dirname "$0")"
cd ../../

rm -rf ./docs
mkdir ./docs
go run ./cmd/coder gen-docs ./docs

# remove cobra footer from each file
for filename in ./docs/*.md; do
trimmed=$(head -n -1 "$filename")
echo "$trimmed" > $filename
echo "$trimmed" >$filename
done


if [[ ${CI-} && $(git ls-files --other --modified --exclude-standard) ]]; then
echo "Documentation needs generation:"
git -c color.ui=always status | grep --color=no '\e\[31m'
Expand Down
12 changes: 11 additions & 1 deletion coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Environment struct {
UserID string `json:"user_id" tab:"-"`
LastBuiltAt time.Time `json:"last_built_at" tab:"-"`
CPUCores float32 `json:"cpu_cores" tab:"CPUCores"`
MemoryGB int `json:"memory_gb" tab:"MemoryGB"`
MemoryGB float32 `json:"memory_gb" tab:"MemoryGB"`
DiskGB int `json:"disk_gb" tab:"DiskGB"`
GPUs int `json:"gpus" tab:"GPUs"`
Updating bool `json:"updating" tab:"Updating"`
Expand Down Expand Up @@ -93,6 +93,16 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
return &env, nil
}

// Environments lists environments returned by the given filter.
// TODO: add the filter options, explore performance issues
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
var envs []Environment
if err := c.requestBody(ctx, http.MethodGet, "/api/environments", nil, &envs); err != nil {
return nil, err
}
return envs, nil
}

// EnvironmentsByOrganization gets the list of environments owned by the given user.
func (c Client) EnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error) {
var envs []Environment
Expand Down
43 changes: 35 additions & 8 deletions coder-sdk/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,47 @@ package coder
import (
"context"
"net/http"
"time"
)

// Org describes an Organization in Coder
type Org struct {
ID string `json:"id"`
Name string `json:"name"`
Members []User `json:"members"`
// Organization describes an Organization in Coder
type Organization struct {
ID string `json:"id"`
Name string `json:"name"`
Members []OrganizationUser `json:"members"`
}

// Orgs gets all Organizations
func (c Client) Orgs(ctx context.Context) ([]Org, error) {
var orgs []Org
// OrganizationUser user wraps the basic User type and adds data specific to the user's membership of an organization
type OrganizationUser struct {
User
OrganizationRoles []OrganizationRole `json:"organization_roles"`
RolesUpdatedAt time.Time `json:"roles_updated_at"`
}

// OrganizationRole defines an organization OrganizationRole
type OrganizationRole string

// The OrganizationRole enum values
const (
RoleOrgMember OrganizationRole = "organization-member"
RoleOrgAdmin OrganizationRole = "organization-admin"
RoleOrgManager OrganizationRole = "organization-manager"
)

// Organizations gets all Organizations
func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
var orgs []Organization
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs", nil, &orgs); err != nil {
return nil, err
}
return orgs, nil
}

// OrgMembers get all members of the given organization
func (c Client) OrgMembers(ctx context.Context, orgID string) ([]OrganizationUser, error) {
var members []OrganizationUser
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/members", nil, &members); err != nil {
return nil, err
}
return members, nil
}
3 changes: 2 additions & 1 deletion docs/coder.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ coder provides a CLI for working with an existing Coder Enterprise installation
### Options

```
-h, --help help for coder
-h, --help help for coder
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
6 changes: 6 additions & 0 deletions docs/coder_completion.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ MacOS:
-h, --help help for completion
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
6 changes: 6 additions & 0 deletions docs/coder_config-ssh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ coder config-ssh [flags]
--remove remove the auto-generated Coder Enterprise ssh config
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
6 changes: 6 additions & 0 deletions docs/coder_envs.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Perform operations on the Coder environments owned by the active user.
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
Expand Down
1 change: 1 addition & 0 deletions docs/coder_envs_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ coder envs ls [flags]

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/coder_envs_stop.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ coder envs stop [environment_name] [flags]

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
6 changes: 6 additions & 0 deletions docs/coder_login.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ coder login [Coder Enterprise URL eg. https://my.coder.domain/] [flags]
-h, --help help for login
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
6 changes: 6 additions & 0 deletions docs/coder_logout.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ coder logout [flags]
-h, --help help for logout
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
6 changes: 6 additions & 0 deletions docs/coder_secrets.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ Interact with secrets objects owned by the active user.
--user string Specify the user whose resources to target (default "me")
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
Expand Down
1 change: 1 addition & 0 deletions docs/coder_secrets_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ coder secrets create aws-credentials --from-file ./credentials.json

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/coder_secrets_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ coder secrets ls [flags]

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/coder_secrets_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ coder secrets rm mysql-password mysql-user

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
1 change: 1 addition & 0 deletions docs/coder_secrets_view.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ coder secrets view mysql-password

```
--user string Specify the user whose resources to target (default "me")
-v, --verbose show verbose output
```

### SEE ALSO
Expand Down
6 changes: 6 additions & 0 deletions docs/coder_sh.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ coder sh backend-env
-h, --help help for sh
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
6 changes: 6 additions & 0 deletions docs/coder_sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ coder sync [local directory] [<env name>:<remote directory>] [flags]
--init do initial transfer and exit
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
6 changes: 6 additions & 0 deletions docs/coder_urls.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Interact with environment DevURLs
-h, --help help for urls
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
Expand Down
6 changes: 6 additions & 0 deletions docs/coder_urls_create.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ coder urls create [env_name] [port] [--access <level>] [--name <name>] [flags]
--name string DevURL name
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder urls](coder_urls.md) - Interact with environment DevURLs
6 changes: 6 additions & 0 deletions docs/coder_urls_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ coder urls ls [environment_name] [flags]
-o, --output string human|json (default "human")
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder urls](coder_urls.md) - Interact with environment DevURLs
6 changes: 6 additions & 0 deletions docs/coder_urls_rm.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ coder urls rm [environment_name] [port] [flags]
-h, --help help for rm
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder urls](coder_urls.md) - Interact with environment DevURLs
6 changes: 6 additions & 0 deletions docs/coder_users.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ Interact with Coder user accounts
-h, --help help for users
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder](coder.md) - coder provides a CLI for working with an existing Coder Enterprise installation
Expand Down
6 changes: 6 additions & 0 deletions docs/coder_users_ls.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ coder users ls -o json | jq .[] | jq -r .email
-o, --output string human | json (default "human")
```

### Options inherited from parent commands

```
-v, --verbose show verbose output
```

### SEE ALSO

* [coder users](coder_users.md) - Interact with Coder user accounts
6 changes: 3 additions & 3 deletions internal/cmd/ceapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
// Helpers for working with the Coder Enterprise API.

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

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

orgs, err := client.Orgs(ctx)
orgs, err := client.Organizations(ctx)
if err != nil {
return nil, xerrors.Errorf("get orgs: %w", err)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import (
"github.com/spf13/cobra/doc"
)

// verbose is a global flag for specifying that a command should give verbose output
var verbose bool = false

// Make constructs the "coder" root command
func Make() *cobra.Command {
app := &cobra.Command{
Expand All @@ -24,9 +27,11 @@ func Make() *cobra.Command {
makeEnvsCommand(),
makeSyncCmd(),
makeURLCmd(),
makeResourceCmd(),
completionCmd,
genDocs(app),
)
app.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "show verbose output")
return app
}

Expand Down
Loading