Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 4 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
8 changes: 4 additions & 4 deletions ci/integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ func TestCoderCLI(t *testing.T) {

headlessLogin(ctx, t, c)

c.Run(ctx, "coder envs").Assert(t,
c.Run(ctx, "coder ws").Assert(t,
tcli.Success(),
)

c.Run(ctx, "coder envs ls").Assert(t,
c.Run(ctx, "coder ws ls").Assert(t,
tcli.Success(),
)

c.Run(ctx, "coder envs ls -o json").Assert(t,
c.Run(ctx, "coder ws ls -o json").Assert(t,
tcli.Success(),
)

Expand Down Expand Up @@ -93,7 +93,7 @@ func TestCoderCLI(t *testing.T) {
tcli.Success(),
)

c.Run(ctx, "coder envs ls").Assert(t,
c.Run(ctx, "coder ws ls").Assert(t,
tcli.Error(),
)

Expand Down
12 changes: 6 additions & 6 deletions ci/integration/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ func TestSSH(t *testing.T) {
run(t, "ssh-coder-cli-tests", func(t *testing.T, ctx context.Context, c *tcli.ContainerRunner) {
headlessLogin(ctx, t, c)

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

assert := tcli.Success()

// if we don't have any environments, "coder config-ssh" will fail
if len(envs) == 0 {
// if we don't have any workspaces, "coder config-ssh" will fail
if len(workspaces) == 0 {
assert = tcli.Error()
}
c.Run(ctx, "coder config-ssh").Assert(t,
Expand Down
6 changes: 3 additions & 3 deletions ci/integration/statictokens_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func TestStaticAuth(t *testing.T) {

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

// should error when the environment variabels aren't set
c.Run(ctx, "coder envs ls").Assert(t,
// should error when the environment variables aren't set
c.Run(ctx, "coder ws ls").Assert(t,
tcli.Error(),
)
})
Expand Down
10 changes: 5 additions & 5 deletions coder-sdk/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
)

type activityRequest struct {
Source string `json:"source"`
EnvironmentID string `json:"environment_id"`
Source string `json:"source"`
WorkspaceID string `json:"workspace_id"`
}

// PushActivity pushes CLI activity to Coder.
func (c *DefaultClient) PushActivity(ctx context.Context, source, envID string) error {
func (c *DefaultClient) PushActivity(ctx context.Context, source, workspaceID string) error {
resp, err := c.request(ctx, http.MethodPost, "/api/private/metrics/usage/push", activityRequest{
Source: source,
EnvironmentID: envID,
Source: source,
WorkspaceID: workspaceID,
})
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions coder-sdk/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ func TestPushActivity(t *testing.T) {
t.Parallel()

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

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

err = client.PushActivity(context.Background(), source, envID)
err = client.PushActivity(context.Background(), source, workspaceID)
assert.Success(t, "expected successful response from PushActivity", err)
}
36 changes: 18 additions & 18 deletions coder-sdk/devurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,38 @@ type DevURL struct {
}

type delDevURLRequest struct {
EnvID string `json:"environment_id"`
DevURLID string `json:"url_id"`
WorkspaceID string `json:"workspace_id"`
DevURLID string `json:"url_id"`
}

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

return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{
EnvID: envID,
DevURLID: urlID,
WorkspaceID: workspaceID,
DevURLID: urlID,
}, nil)
}

// CreateDevURLReq defines the request parameters for creating a new DevURL.
type CreateDevURLReq struct {
EnvID string `json:"environment_id"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
Scheme string `json:"scheme"`
WorkspaceID string `json:"workspace_id"`
Port int `json:"port"`
Access string `json:"access"`
Name string `json:"name"`
Scheme string `json:"scheme"`
}

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

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

// PutDevURL updates an existing devurl for the authenticated user.
func (c *DefaultClient) PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error {
return c.requestBody(ctx, http.MethodPut, "/api/v0/environments/"+envID+"/devurls/"+urlID, req, nil)
func (c *DefaultClient) PutDevURL(ctx context.Context, workspaceID, urlID string, req PutDevURLReq) error {
return c.requestBody(ctx, http.MethodPut, "/api/v0/workspaces/"+workspaceID+"/devurls/"+urlID, req, nil)
}
84 changes: 42 additions & 42 deletions coder-sdk/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
// This is an interface to allow for mocking of coder-sdk client usage.
type Client interface {
// PushActivity pushes CLI activity to Coder.
PushActivity(ctx context.Context, source, envID string) error
PushActivity(ctx context.Context, source, workspaceID string) error

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

// DeleteDevURL deletes the specified devurl.
DeleteDevURL(ctx context.Context, envID, urlID string) error
DeleteDevURL(ctx context.Context, workspaceID, urlID string) error

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

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

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

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

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

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

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

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

// DeleteEnvironment deletes the environment.
DeleteEnvironment(ctx context.Context, envID string) error
// DeleteWorkspace deletes the workspace.
DeleteWorkspace(ctx context.Context, workspaceID string) error

// StopEnvironment stops the environment.
StopEnvironment(ctx context.Context, envID string) error
// StopWorkspace stops the workspace.
StopWorkspace(ctx context.Context, workspaceID string) error

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

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

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

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

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

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

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

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

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

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

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

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

// ImportImage creates a new image and optionally a new registry.
ImportImage(ctx context.Context, req ImportImageReq) (*Image, error)
Expand Down
2 changes: 1 addition & 1 deletion coder-sdk/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Organization struct {
Description string `json:"description"`
Default bool `json:"default"`
Members []OrganizationUser `json:"members"`
EnvironmentCount int `json:"environment_count"`
WorkspaceCount int `json:"workspace_count"`
ResourceNamespace string `json:"resource_namespace"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
Expand Down
16 changes: 8 additions & 8 deletions coder-sdk/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import (

// ImageTag is a Docker image tag.
type ImageTag struct {
ImageID string `json:"image_id" table:"-"`
Tag string `json:"tag" table:"Tag"`
LatestHash string `json:"latest_hash" table:"-"`
HashLastUpdatedAt time.Time `json:"hash_last_updated_at" table:"-"`
OSRelease *OSRelease `json:"os_release" table:"OS"`
Environments []*Environment `json:"environments" table:"-"`
UpdatedAt time.Time `json:"updated_at" table:"UpdatedAt"`
CreatedAt time.Time `json:"created_at" table:"-"`
ImageID string `json:"image_id" table:"-"`
Tag string `json:"tag" table:"Tag"`
LatestHash string `json:"latest_hash" table:"-"`
HashLastUpdatedAt time.Time `json:"hash_last_updated_at" table:"-"`
OSRelease *OSRelease `json:"os_release" table:"OS"`
Workspaces []*Workspace `json:"workspaces" table:"-"`
UpdatedAt time.Time `json:"updated_at" table:"UpdatedAt"`
CreatedAt time.Time `json:"created_at" table:"-"`
}

func (i ImageTag) String() string {
Expand Down
Loading