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

chore: update API routes to use /api/v0 #222

Merged
merged 1 commit into from
Jan 21, 2021
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
8 changes: 4 additions & 4 deletions coder-sdk/devurl.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type delDevURLRequest struct {

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

return c.requestBody(ctx, http.MethodDelete, reqURL, delDevURLRequest{
EnvID: envID,
Expand All @@ -42,13 +42,13 @@ type CreateDevURLReq struct {

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

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

// PutDevURL updates an existing devurl for the authenticated user.
func (c Client) PutDevURL(ctx context.Context, envID, urlID string, req PutDevURLReq) error {
return c.requestBody(ctx, http.MethodPut, "/api/private/environments/"+envID+"/devurls/"+urlID, req, nil)
return c.requestBody(ctx, http.MethodPut, "/api/v0/environments/"+envID+"/devurls/"+urlID, req, nil)
}
10 changes: 5 additions & 5 deletions coder-sdk/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func (c Client) CreateEnvironment(ctx context.Context, req CreateEnvironmentRequ
// TODO: add the filter options, explore performance issue.
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
var envs []Environment
if err := c.requestBody(ctx, http.MethodGet, "/api/private/environments", nil, &envs); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/environments", nil, &envs); err != nil {
return nil, err
}
return envs, nil
Expand All @@ -122,12 +122,12 @@ func (c Client) UserEnvironmentsByOrganization(ctx context.Context, userID, orgI

// DeleteEnvironment deletes the environment.
func (c Client) DeleteEnvironment(ctx context.Context, envID string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/environments/"+envID, nil, nil)
return c.requestBody(ctx, http.MethodDelete, "/api/v0/environments/"+envID, nil, nil)
}

// StopEnvironment stops the stops.
func (c Client) StopEnvironment(ctx context.Context, envID string) error {
return c.requestBody(ctx, http.MethodPut, "/api/private/environments/"+envID+"/stop", nil, nil)
return c.requestBody(ctx, http.MethodPut, "/api/v0/environments/"+envID+"/stop", nil, nil)
}

// UpdateEnvironmentReq defines the update operation, only setting
Expand All @@ -145,12 +145,12 @@ type UpdateEnvironmentReq struct {

// RebuildEnvironment requests that the given envID is rebuilt with no changes to its specification.
func (c Client) RebuildEnvironment(ctx context.Context, envID string) error {
return c.requestBody(ctx, http.MethodPatch, "/api/private/environments/"+envID, UpdateEnvironmentReq{}, nil)
return c.requestBody(ctx, http.MethodPatch, "/api/v0/environments/"+envID, UpdateEnvironmentReq{}, nil)
}

// EditEnvironment modifies the environment specification and initiates a rebuild.
func (c Client) EditEnvironment(ctx context.Context, envID string, req UpdateEnvironmentReq) error {
return c.requestBody(ctx, http.MethodPatch, "/api/private/environments/"+envID, req, nil)
return c.requestBody(ctx, http.MethodPatch, "/api/v0/environments/"+envID, req, nil)
}

// DialWsep dials an environments command execution interface
Expand Down
8 changes: 4 additions & 4 deletions coder-sdk/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (c Client) OrganizationByID(ctx context.Context, orgID string) (*Organizati
// OrganizationMembers get all members of the given organization.
func (c Client) OrganizationMembers(ctx context.Context, orgID string) ([]OrganizationUser, error) {
var members []OrganizationUser
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/members", nil, &members); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/orgs/"+orgID+"/members", nil, &members); err != nil {
return nil, err
}
return members, nil
Expand All @@ -76,7 +76,7 @@ type UpdateOrganizationReq struct {

// UpdateOrganization applys a partial update of an Organization resource.
func (c Client) UpdateOrganization(ctx context.Context, orgID string, req UpdateOrganizationReq) error {
return c.requestBody(ctx, http.MethodPatch, "/api/private/orgs/"+orgID, req, nil)
return c.requestBody(ctx, http.MethodPatch, "/api/v0/orgs/"+orgID, req, nil)
}

// CreateOrganizationReq describes the request parameters to create a new Organization.
Expand All @@ -92,10 +92,10 @@ type CreateOrganizationReq struct {

// CreateOrganization creates a new Organization in Coder Enterprise.
func (c Client) CreateOrganization(ctx context.Context, req CreateOrganizationReq) error {
return c.requestBody(ctx, http.MethodPost, "/api/private/orgs", req, nil)
return c.requestBody(ctx, http.MethodPost, "/api/v0/orgs", req, nil)
}

// DeleteOrganization deletes an organization.
func (c Client) DeleteOrganization(ctx context.Context, orgID string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/orgs/"+orgID, nil, nil)
return c.requestBody(ctx, http.MethodDelete, "/api/v0/orgs/"+orgID, nil, nil)
}
8 changes: 4 additions & 4 deletions coder-sdk/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,21 @@ type CreateImageTagReq struct {
// CreateImageTag creates a new image tag resource.
func (c Client) CreateImageTag(ctx context.Context, imageID string, req CreateImageTagReq) (*ImageTag, error) {
var tag ImageTag
if err := c.requestBody(ctx, http.MethodPost, "/api/private/images/"+imageID+"/tags", req, tag); err != nil {
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/images/"+imageID+"/tags", req, tag); err != nil {
return nil, err
}
return &tag, nil
}

// DeleteImageTag deletes an image tag resource.
func (c Client) DeleteImageTag(ctx context.Context, imageID, tag string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/images/"+imageID+"/tags/"+tag, nil, nil)
return c.requestBody(ctx, http.MethodDelete, "/api/v0/images/"+imageID+"/tags/"+tag, nil, nil)
}

// ImageTags fetch all image tags.
func (c Client) ImageTags(ctx context.Context, imageID string) ([]ImageTag, error) {
var tags []ImageTag
if err := c.requestBody(ctx, http.MethodGet, "/api/private/images/"+imageID+"/tags", nil, &tags); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images/"+imageID+"/tags", nil, &tags); err != nil {
return nil, err
}
return tags, nil
Expand All @@ -65,7 +65,7 @@ func (c Client) ImageTags(ctx context.Context, imageID string) ([]ImageTag, erro
// ImageTagByID fetch an image tag by ID.
func (c Client) ImageTagByID(ctx context.Context, imageID, tagID string) (*ImageTag, error) {
var tag ImageTag
if err := c.requestBody(ctx, http.MethodGet, "/api/private/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
return nil, err
}
return &tag, nil
Expand Down
10 changes: 5 additions & 5 deletions coder-sdk/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type createAPITokenResp struct {
// CreateAPIToken creates a new APIToken for making authenticated requests to Coder Enterprise.
func (c Client) CreateAPIToken(ctx context.Context, userID string, req CreateAPITokenReq) (token string, _ error) {
var resp createAPITokenResp
err := c.requestBody(ctx, http.MethodPost, "/api/private/api-keys/"+userID, req, &resp)
err := c.requestBody(ctx, http.MethodPost, "/api/v0/api-keys/"+userID, req, &resp)
if err != nil {
return "", err
}
Expand All @@ -37,7 +37,7 @@ func (c Client) CreateAPIToken(ctx context.Context, userID string, req CreateAPI
// APITokens fetches all APITokens owned by the given user.
func (c Client) APITokens(ctx context.Context, userID string) ([]APIToken, error) {
var tokens []APIToken
if err := c.requestBody(ctx, http.MethodGet, "/api/private/api-keys/"+userID, nil, &tokens); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/api-keys/"+userID, nil, &tokens); err != nil {
return nil, err
}
return tokens, nil
Expand All @@ -46,21 +46,21 @@ func (c Client) APITokens(ctx context.Context, userID string) ([]APIToken, error
// APITokenByID fetches the metadata for a given APIToken.
func (c Client) APITokenByID(ctx context.Context, userID, tokenID string) (*APIToken, error) {
var token APIToken
if err := c.requestBody(ctx, http.MethodGet, "/api/private/api-keys/"+userID+"/"+tokenID, nil, &token); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/api-keys/"+userID+"/"+tokenID, nil, &token); err != nil {
return nil, err
}
return &token, nil
}

// DeleteAPIToken deletes an APIToken.
func (c Client) DeleteAPIToken(ctx context.Context, userID, tokenID string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/api-keys/"+userID+"/"+tokenID, nil, nil)
return c.requestBody(ctx, http.MethodDelete, "/api/v0/api-keys/"+userID+"/"+tokenID, nil, nil)
}

// RegenerateAPIToken regenerates the given APIToken and returns the new value.
func (c Client) RegenerateAPIToken(ctx context.Context, userID, tokenID string) (token string, _ error) {
var resp createAPITokenResp
if err := c.requestBody(ctx, http.MethodPost, "/api/private/api-keys/"+userID+"/"+tokenID+"/regen", nil, &resp); err != nil {
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/api-keys/"+userID+"/"+tokenID+"/regen", nil, &resp); err != nil {
return "", err
}
return resp.Key, nil
Expand Down
10 changes: 5 additions & 5 deletions coder-sdk/users.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ type SSHKey struct {
// SSHKey gets the current SSH kepair of the authenticated user.
func (c Client) SSHKey(ctx context.Context) (*SSHKey, error) {
var key SSHKey
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users/me/sshkey", nil, &key); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/users/me/sshkey", nil, &key); err != nil {
return nil, err
}
return &key, nil
Expand All @@ -73,7 +73,7 @@ func (c Client) SSHKey(ctx context.Context) (*SSHKey, error) {
// Users gets the list of user accounts.
func (c Client) Users(ctx context.Context) ([]User, error) {
var u []User
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users", nil, &u); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/users", nil, &u); err != nil {
return nil, err
}
return u, nil
Expand Down Expand Up @@ -111,7 +111,7 @@ type UpdateUserReq struct {

// UpdateUser applyes the partial update to the given user.
func (c Client) UpdateUser(ctx context.Context, userID string, req UpdateUserReq) error {
return c.requestBody(ctx, http.MethodPatch, "/api/private/users/"+userID, req, nil)
return c.requestBody(ctx, http.MethodPatch, "/api/v0/users/"+userID, req, nil)
}

// UpdateUXState applies a partial update of the user's UX State.
Expand All @@ -135,10 +135,10 @@ type CreateUserReq struct {

// CreateUser creates a new user account.
func (c Client) CreateUser(ctx context.Context, req CreateUserReq) error {
return c.requestBody(ctx, http.MethodPost, "/api/private/users", req, nil)
return c.requestBody(ctx, http.MethodPost, "/api/v0/users", req, nil)
}

// DeleteUser deletes a user account.
func (c Client) DeleteUser(ctx context.Context, userID string) error {
return c.requestBody(ctx, http.MethodDelete, "/api/private/users/"+userID, nil, nil)
return c.requestBody(ctx, http.MethodDelete, "/api/v0/users/"+userID, nil, nil)
}