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

Commit 56ffab3

Browse files
authored
Rename environments to workspaces and use new routes (#350)
* Rename env types to workspace * Rename envs sub-command to workspaces Aliases are `envs` and `workspaces`. * Add a deprecated envs command There doesn't appear to be a way to deprecate an alias so create a new command instead.
1 parent d8e5efe commit 56ffab3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+1003
-992
lines changed

ci/integration/integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ func TestCoderCLI(t *testing.T) {
5353

5454
headlessLogin(ctx, t, c)
5555

56-
c.Run(ctx, "coder envs").Assert(t,
56+
c.Run(ctx, "coder workspaces").Assert(t,
5757
tcli.Success(),
5858
)
5959

60-
c.Run(ctx, "coder envs ls").Assert(t,
60+
c.Run(ctx, "coder workspaces ls").Assert(t,
6161
tcli.Success(),
6262
)
6363

64-
c.Run(ctx, "coder envs ls -o json").Assert(t,
64+
c.Run(ctx, "coder workspaces ls -o json").Assert(t,
6565
tcli.Success(),
6666
)
6767

@@ -93,7 +93,7 @@ func TestCoderCLI(t *testing.T) {
9393
tcli.Success(),
9494
)
9595

96-
c.Run(ctx, "coder envs ls").Assert(t,
96+
c.Run(ctx, "coder workspaces ls").Assert(t,
9797
tcli.Error(),
9898
)
9999

ci/integration/ssh_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@ func TestSSH(t *testing.T) {
1313
run(t, "ssh-coder-cli-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
1414
headlessLogin(ctx, t, c)
1515

16-
// TODO remove this once we can create an environment if there aren't any
17-
var envs []coder.Environment
18-
c.Run(ctx, "coder envs ls --output json").Assert(t,
16+
// TODO remove this once we can create a workspace if there aren't any
17+
var workspaces []coder.Workspace
18+
c.Run(ctx, "coder workspaces ls --output json").Assert(t,
1919
tcli.Success(),
20-
tcli.StdoutJSONUnmarshal(&envs),
20+
tcli.StdoutJSONUnmarshal(&workspaces),
2121
)
2222

2323
assert := tcli.Success()
2424

25-
// if we don't have any environments, "coder config-ssh" will fail
26-
if len(envs) == 0 {
25+
// if we don't have any workspaces, "coder config-ssh" will fail
26+
if len(workspaces) == 0 {
2727
assert = tcli.Error()
2828
}
2929
c.Run(ctx, "coder config-ssh").Assert(t,

ci/integration/statictokens_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ func TestStaticAuth(t *testing.T) {
3535

3636
// make requests with token environment variable authentication
3737
cmd := exec.CommandContext(ctx, "sh", "-c",
38-
fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder envs ls", os.Getenv("CODER_URL")),
38+
fmt.Sprintf("export CODER_URL=%s && export CODER_TOKEN=$(cat) && coder workspaces ls", os.Getenv("CODER_URL")),
3939
)
4040
cmd.Stdin = strings.NewReader(string(result.Stdout))
4141
c.RunCmd(cmd).Assert(t,
4242
tcli.Success(),
4343
)
4444

45-
// should error when the environment variabels aren't set
46-
c.Run(ctx, "coder envs ls").Assert(t,
45+
// should error when the environment variables aren't set
46+
c.Run(ctx, "coder workspaces ls").Assert(t,
4747
tcli.Error(),
4848
)
4949
})

coder-sdk/activity.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ import (
66
)
77

88
type activityRequest struct {
9-
Source string `json:"source"`
10-
EnvironmentID string `json:"environment_id"`
9+
Source string `json:"source"`
10+
WorkspaceID string `json:"workspace_id"`
1111
}
1212

1313
// PushActivity pushes CLI activity to Coder.
14-
func (c *DefaultClient) PushActivity(ctx context.Context, source, envID string) error {
14+
func (c *DefaultClient) PushActivity(ctx context.Context, source, workspaceID string) error {
1515
resp, err := c.request(ctx, http.MethodPost, "/api/private/metrics/usage/push", activityRequest{
16-
Source: source,
17-
EnvironmentID: envID,
16+
Source: source,
17+
WorkspaceID: workspaceID,
1818
})
1919
if err != nil {
2020
return err

coder-sdk/activity_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ func TestPushActivity(t *testing.T) {
1717
t.Parallel()
1818

1919
const source = "test"
20-
const envID = "602d377a-e6b8d763cae7561885c5f1b2"
20+
const workspaceID = "602d377a-e6b8d763cae7561885c5f1b2"
2121
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2222
assert.Equal(t, "PushActivity is a POST", http.MethodPost, r.Method)
2323
assert.Equal(t, "URL matches", "/api/private/metrics/usage/push", r.URL.Path)
2424

2525
expected := map[string]interface{}{
26-
"source": source,
27-
"environment_id": envID,
26+
"source": source,
27+
"workspace_id": workspaceID,
2828
}
2929
var request map[string]interface{}
3030
err := json.NewDecoder(r.Body).Decode(&request)
@@ -46,6 +46,6 @@ func TestPushActivity(t *testing.T) {
4646
})
4747
assert.Success(t, "failed to create coder.Client", err)
4848

49-
err = client.PushActivity(context.Background(), source, envID)
49+
err = client.PushActivity(context.Background(), source, workspaceID)
5050
assert.Success(t, "expected successful response from PushActivity", err)
5151
}

coder-sdk/devurl.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,38 @@ type DevURL struct {
1717
}
1818

1919
type delDevURLRequest struct {
20-
EnvID string `json:"environment_id"`
21-
DevURLID string `json:"url_id"`
20+
WorkspaceID string `json:"workspace_id"`
21+
DevURLID string `json:"url_id"`
2222
}
2323

2424
// DeleteDevURL deletes the specified devurl.
25-
func (c *DefaultClient) DeleteDevURL(ctx context.Context, envID, urlID string) error {
26-
reqURL := fmt.Sprintf("/api/v0/environments/%s/devurls/%s", envID, urlID)
25+
func (c *DefaultClient) DeleteDevURL(ctx context.Context, workspaceID, urlID string) error {
26+
reqURL := fmt.Sprintf("/api/v0/workspaces/%s/devurls/%s", workspaceID, urlID)
2727

2828
return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{
29-
EnvID: envID,
30-
DevURLID: urlID,
29+
WorkspaceID: workspaceID,
30+
DevURLID: urlID,
3131
}, nil)
3232
}
3333

3434
// CreateDevURLReq defines the request parameters for creating a new DevURL.
3535
type CreateDevURLReq struct {
36-
EnvID string `json:"environment_id"`
37-
Port int `json:"port"`
38-
Access string `json:"access"`
39-
Name string `json:"name"`
40-
Scheme string `json:"scheme"`
36+
WorkspaceID string `json:"workspace_id"`
37+
Port int `json:"port"`
38+
Access string `json:"access"`
39+
Name string `json:"name"`
40+
Scheme string `json:"scheme"`
4141
}
4242

4343
// CreateDevURL inserts a new dev URL for the authenticated user.
44-
func (c *DefaultClient) CreateDevURL(ctx context.Context, envID string, req CreateDevURLReq) error {
45-
return c.requestBody(ctx, http.MethodPost, "/api/v0/environments/"+envID+"/devurls", req, nil)
44+
func (c *DefaultClient) CreateDevURL(ctx context.Context, workspaceID string, req CreateDevURLReq) error {
45+
return c.requestBody(ctx, http.MethodPost, "/api/v0/workspaces/"+workspaceID+"/devurls", req, nil)
4646
}
4747

48-
// DevURLs fetches the Dev URLs for a given environment.
49-
func (c *DefaultClient) DevURLs(ctx context.Context, envID string) ([]DevURL, error) {
48+
// DevURLs fetches the Dev URLs for a given workspace.
49+
func (c *DefaultClient) DevURLs(ctx context.Context, workspaceID string) ([]DevURL, error) {
5050
var devurls []DevURL
51-
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/environments/"+envID+"/devurls", nil, &devurls); err != nil {
51+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/workspaces/"+workspaceID+"/devurls", nil, &devurls); err != nil {
5252
return nil, err
5353
}
5454
return devurls, nil
@@ -58,6 +58,6 @@ func (c *DefaultClient) DevURLs(ctx context.Context, envID string) ([]DevURL, er
5858
type PutDevURLReq CreateDevURLReq
5959

6060
// PutDevURL updates an existing devurl for the authenticated user.
61-
func (c *DefaultClient) PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error {
62-
return c.requestBody(ctx, http.MethodPut, "/api/v0/environments/"+envID+"/devurls/"+urlID, req, nil)
61+
func (c *DefaultClient) PutDevURL(ctx context.Context, workspaceID, urlID string, req PutDevURLReq) error {
62+
return c.requestBody(ctx, http.MethodPut, "/api/v0/workspaces/"+workspaceID+"/devurls/"+urlID, req, nil)
6363
}

coder-sdk/interface.go

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
// This is an interface to allow for mocking of coder-sdk client usage.
1313
type Client interface {
1414
// PushActivity pushes CLI activity to Coder.
15-
PushActivity(ctx context.Context, source, envID string) error
15+
PushActivity(ctx context.Context, source, workspaceID string) error
1616

1717
// Me gets the details of the authenticated user.
1818
Me(ctx context.Context) (*User, error)
@@ -66,75 +66,75 @@ type Client interface {
6666
SiteConfigWorkspaces(ctx context.Context) (*ConfigWorkspaces, error)
6767

6868
// DeleteDevURL deletes the specified devurl.
69-
DeleteDevURL(ctx context.Context, envID, urlID string) error
69+
DeleteDevURL(ctx context.Context, workspaceID, urlID string) error
7070

7171
// CreateDevURL inserts a new devurl for the authenticated user.
72-
CreateDevURL(ctx context.Context, envID string, req CreateDevURLReq) error
72+
CreateDevURL(ctx context.Context, workspaceID string, req CreateDevURLReq) error
7373

74-
// DevURLs fetches the Dev URLs for a given environment.
75-
DevURLs(ctx context.Context, envID string) ([]DevURL, error)
74+
// DevURLs fetches the Dev URLs for a given workspace.
75+
DevURLs(ctx context.Context, workspaceID string) ([]DevURL, error)
7676

7777
// PutDevURL updates an existing devurl for the authenticated user.
78-
PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error
78+
PutDevURL(ctx context.Context, workspaceID, urlID string, req PutDevURLReq) error
7979

80-
// CreateEnvironment sends a request to create an environment.
81-
CreateEnvironment(ctx context.Context, req CreateEnvironmentRequest) (*Environment, error)
80+
// CreateWorkspace sends a request to create a workspace.
81+
CreateWorkspace(ctx context.Context, req CreateWorkspaceRequest) (*Workspace, error)
8282

8383
// ParseTemplate parses a template config. It support both remote repositories and local files.
8484
// If a local file is specified then all other values in the request are ignored.
8585
ParseTemplate(ctx context.Context, req ParseTemplateRequest) (*TemplateVersion, error)
8686

87-
// CreateEnvironmentFromRepo sends a request to create an environment from a repository.
88-
CreateEnvironmentFromRepo(ctx context.Context, orgID string, req TemplateVersion) (*Environment, error)
87+
// CreateWorkspaceFromRepo sends a request to create a workspace from a repository.
88+
CreateWorkspaceFromRepo(ctx context.Context, orgID string, req TemplateVersion) (*Workspace, error)
8989

90-
// Environments lists environments returned by the given filter.
91-
Environments(ctx context.Context) ([]Environment, error)
90+
// Workspaces lists workspaces returned by the given filter.
91+
Workspaces(ctx context.Context) ([]Workspace, error)
9292

93-
// UserEnvironmentsByOrganization gets the list of environments owned by the given user.
94-
UserEnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error)
93+
// UserWorkspacesByOrganization gets the list of workspaces owned by the given user.
94+
UserWorkspacesByOrganization(ctx context.Context, userID, orgID string) ([]Workspace, error)
9595

96-
// DeleteEnvironment deletes the environment.
97-
DeleteEnvironment(ctx context.Context, envID string) error
96+
// DeleteWorkspace deletes the workspace.
97+
DeleteWorkspace(ctx context.Context, workspaceID string) error
9898

99-
// StopEnvironment stops the environment.
100-
StopEnvironment(ctx context.Context, envID string) error
99+
// StopWorkspace stops the workspace.
100+
StopWorkspace(ctx context.Context, workspaceID string) error
101101

102-
// RebuildEnvironment requests that the given envID is rebuilt with no changes to its specification.
103-
RebuildEnvironment(ctx context.Context, envID string) error
102+
// RebuildWorkspace requests that the given workspaceID is rebuilt with no changes to its specification.
103+
RebuildWorkspace(ctx context.Context, workspaceID string) error
104104

105-
// EditEnvironment modifies the environment specification and initiates a rebuild.
106-
EditEnvironment(ctx context.Context, envID string, req UpdateEnvironmentReq) error
105+
// EditWorkspace modifies the workspace specification and initiates a rebuild.
106+
EditWorkspace(ctx context.Context, workspaceID string, req UpdateWorkspaceReq) error
107107

108-
// DialWsep dials an environments command execution interface
108+
// DialWsep dials a workspace's command execution interface
109109
// See https://github.com/cdr/wsep for details.
110-
DialWsep(ctx context.Context, baseURL *url.URL, envID string) (*websocket.Conn, error)
110+
DialWsep(ctx context.Context, baseURL *url.URL, workspaceID string) (*websocket.Conn, error)
111111

112-
// DialExecutor gives a remote execution interface for performing commands inside an environment.
113-
DialExecutor(ctx context.Context, baseURL *url.URL, envID string) (wsep.Execer, error)
112+
// DialExecutor gives a remote execution interface for performing commands inside a workspace.
113+
DialExecutor(ctx context.Context, baseURL *url.URL, workspaceID string) (wsep.Execer, error)
114114

115-
// DialIDEStatus opens a websocket connection for cpu load metrics on the environment.
116-
DialIDEStatus(ctx context.Context, baseURL *url.URL, envID string) (*websocket.Conn, error)
115+
// DialIDEStatus opens a websocket connection for cpu load metrics on the workspace.
116+
DialIDEStatus(ctx context.Context, baseURL *url.URL, workspaceID string) (*websocket.Conn, error)
117117

118-
// DialEnvironmentBuildLog opens a websocket connection for the environment build log messages.
119-
DialEnvironmentBuildLog(ctx context.Context, envID string) (*websocket.Conn, error)
118+
// DialWorkspaceBuildLog opens a websocket connection for the workspace build log messages.
119+
DialWorkspaceBuildLog(ctx context.Context, workspaceID string) (*websocket.Conn, error)
120120

121-
// FollowEnvironmentBuildLog trails the build log of a Coder environment.
122-
FollowEnvironmentBuildLog(ctx context.Context, envID string) (<-chan BuildLogFollowMsg, error)
121+
// FollowWorkspaceBuildLog trails the build log of a Coder workspace.
122+
FollowWorkspaceBuildLog(ctx context.Context, workspaceID string) (<-chan BuildLogFollowMsg, error)
123123

124-
// DialEnvironmentStats opens a websocket connection for environment stats.
125-
DialEnvironmentStats(ctx context.Context, envID string) (*websocket.Conn, error)
124+
// DialWorkspaceStats opens a websocket connection for workspace stats.
125+
DialWorkspaceStats(ctx context.Context, workspaceID string) (*websocket.Conn, error)
126126

127-
// DialResourceLoad opens a websocket connection for cpu load metrics on the environment.
128-
DialResourceLoad(ctx context.Context, envID string) (*websocket.Conn, error)
127+
// DialResourceLoad opens a websocket connection for cpu load metrics on the workspace.
128+
DialResourceLoad(ctx context.Context, workspaceID string) (*websocket.Conn, error)
129129

130-
// WaitForEnvironmentReady will watch the build log and return when done.
131-
WaitForEnvironmentReady(ctx context.Context, envID string) error
130+
// WaitForWorkspaceReady will watch the build log and return when done.
131+
WaitForWorkspaceReady(ctx context.Context, workspaceID string) error
132132

133-
// EnvironmentByID get the details of an environment by its id.
134-
EnvironmentByID(ctx context.Context, id string) (*Environment, error)
133+
// WorkspaceByID get the details of a workspace by its id.
134+
WorkspaceByID(ctx context.Context, id string) (*Workspace, error)
135135

136-
// EnvironmentsByWorkspaceProvider returns environments that belong to a particular workspace provider.
137-
EnvironmentsByWorkspaceProvider(ctx context.Context, wpID string) ([]Environment, error)
136+
// WorkspacesByWorkspaceProvider returns workspaces that belong to a particular workspace provider.
137+
WorkspacesByWorkspaceProvider(ctx context.Context, wpID string) ([]Workspace, error)
138138

139139
// ImportImage creates a new image and optionally a new registry.
140140
ImportImage(ctx context.Context, req ImportImageReq) (*Image, error)

coder-sdk/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ type Organization struct {
1313
Description string `json:"description"`
1414
Default bool `json:"default"`
1515
Members []OrganizationUser `json:"members"`
16-
EnvironmentCount int `json:"environment_count"`
16+
WorkspaceCount int `json:"workspace_count"`
1717
ResourceNamespace string `json:"resource_namespace"`
1818
CreatedAt time.Time `json:"created_at"`
1919
UpdatedAt time.Time `json:"updated_at"`

coder-sdk/tags.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ import (
88

99
// ImageTag is a Docker image tag.
1010
type ImageTag struct {
11-
ImageID string `json:"image_id" table:"-"`
12-
Tag string `json:"tag" table:"Tag"`
13-
LatestHash string `json:"latest_hash" table:"-"`
14-
HashLastUpdatedAt time.Time `json:"hash_last_updated_at" table:"-"`
15-
OSRelease *OSRelease `json:"os_release" table:"OS"`
16-
Environments []*Environment `json:"environments" table:"-"`
17-
UpdatedAt time.Time `json:"updated_at" table:"UpdatedAt"`
18-
CreatedAt time.Time `json:"created_at" table:"-"`
11+
ImageID string `json:"image_id" table:"-"`
12+
Tag string `json:"tag" table:"Tag"`
13+
LatestHash string `json:"latest_hash" table:"-"`
14+
HashLastUpdatedAt time.Time `json:"hash_last_updated_at" table:"-"`
15+
OSRelease *OSRelease `json:"os_release" table:"OS"`
16+
Workspaces []*Workspace `json:"workspaces" table:"-"`
17+
UpdatedAt time.Time `json:"updated_at" table:"UpdatedAt"`
18+
CreatedAt time.Time `json:"created_at" table:"-"`
1919
}
2020

2121
func (i ImageTag) String() string {

0 commit comments

Comments
 (0)