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

Commit ae35620

Browse files
authored
chore: update API routes to use /api/v0 (#222)
1 parent c38df0b commit ae35620

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

coder-sdk/devurl.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type delDevURLRequest struct {
2323

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

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

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

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

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

coder-sdk/env.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func (c Client) CreateEnvironment(ctx context.Context, req CreateEnvironmentRequ
9898
// TODO: add the filter options, explore performance issue.
9999
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
100100
var envs []Environment
101-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/environments", nil, &envs); err != nil {
101+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/environments", nil, &envs); err != nil {
102102
return nil, err
103103
}
104104
return envs, nil
@@ -122,12 +122,12 @@ func (c Client) UserEnvironmentsByOrganization(ctx context.Context, userID, orgI
122122

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

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

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

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

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

156156
// DialWsep dials an environments command execution interface

coder-sdk/org.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (c Client) OrganizationByID(ctx context.Context, orgID string) (*Organizati
5858
// OrganizationMembers get all members of the given organization.
5959
func (c Client) OrganizationMembers(ctx context.Context, orgID string) ([]OrganizationUser, error) {
6060
var members []OrganizationUser
61-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/members", nil, &members); err != nil {
61+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/orgs/"+orgID+"/members", nil, &members); err != nil {
6262
return nil, err
6363
}
6464
return members, nil
@@ -76,7 +76,7 @@ type UpdateOrganizationReq struct {
7676

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

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

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

9898
// DeleteOrganization deletes an organization.
9999
func (c Client) DeleteOrganization(ctx context.Context, orgID string) error {
100-
return c.requestBody(ctx, http.MethodDelete, "/api/private/orgs/"+orgID, nil, nil)
100+
return c.requestBody(ctx, http.MethodDelete, "/api/v0/orgs/"+orgID, nil, nil)
101101
}

coder-sdk/tags.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,21 +42,21 @@ type CreateImageTagReq struct {
4242
// CreateImageTag creates a new image tag resource.
4343
func (c Client) CreateImageTag(ctx context.Context, imageID string, req CreateImageTagReq) (*ImageTag, error) {
4444
var tag ImageTag
45-
if err := c.requestBody(ctx, http.MethodPost, "/api/private/images/"+imageID+"/tags", req, tag); err != nil {
45+
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/images/"+imageID+"/tags", req, tag); err != nil {
4646
return nil, err
4747
}
4848
return &tag, nil
4949
}
5050

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

5656
// ImageTags fetch all image tags.
5757
func (c Client) ImageTags(ctx context.Context, imageID string) ([]ImageTag, error) {
5858
var tags []ImageTag
59-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/images/"+imageID+"/tags", nil, &tags); err != nil {
59+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images/"+imageID+"/tags", nil, &tags); err != nil {
6060
return nil, err
6161
}
6262
return tags, nil
@@ -65,7 +65,7 @@ func (c Client) ImageTags(ctx context.Context, imageID string) ([]ImageTag, erro
6565
// ImageTagByID fetch an image tag by ID.
6666
func (c Client) ImageTagByID(ctx context.Context, imageID, tagID string) (*ImageTag, error) {
6767
var tag ImageTag
68-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
68+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
6969
return nil, err
7070
}
7171
return &tag, nil

coder-sdk/tokens.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type createAPITokenResp struct {
2727
// CreateAPIToken creates a new APIToken for making authenticated requests to Coder Enterprise.
2828
func (c Client) CreateAPIToken(ctx context.Context, userID string, req CreateAPITokenReq) (token string, _ error) {
2929
var resp createAPITokenResp
30-
err := c.requestBody(ctx, http.MethodPost, "/api/private/api-keys/"+userID, req, &resp)
30+
err := c.requestBody(ctx, http.MethodPost, "/api/v0/api-keys/"+userID, req, &resp)
3131
if err != nil {
3232
return "", err
3333
}
@@ -37,7 +37,7 @@ func (c Client) CreateAPIToken(ctx context.Context, userID string, req CreateAPI
3737
// APITokens fetches all APITokens owned by the given user.
3838
func (c Client) APITokens(ctx context.Context, userID string) ([]APIToken, error) {
3939
var tokens []APIToken
40-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/api-keys/"+userID, nil, &tokens); err != nil {
40+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/api-keys/"+userID, nil, &tokens); err != nil {
4141
return nil, err
4242
}
4343
return tokens, nil
@@ -46,21 +46,21 @@ func (c Client) APITokens(ctx context.Context, userID string) ([]APIToken, error
4646
// APITokenByID fetches the metadata for a given APIToken.
4747
func (c Client) APITokenByID(ctx context.Context, userID, tokenID string) (*APIToken, error) {
4848
var token APIToken
49-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/api-keys/"+userID+"/"+tokenID, nil, &token); err != nil {
49+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/api-keys/"+userID+"/"+tokenID, nil, &token); err != nil {
5050
return nil, err
5151
}
5252
return &token, nil
5353
}
5454

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

6060
// RegenerateAPIToken regenerates the given APIToken and returns the new value.
6161
func (c Client) RegenerateAPIToken(ctx context.Context, userID, tokenID string) (token string, _ error) {
6262
var resp createAPITokenResp
63-
if err := c.requestBody(ctx, http.MethodPost, "/api/private/api-keys/"+userID+"/"+tokenID+"/regen", nil, &resp); err != nil {
63+
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/api-keys/"+userID+"/"+tokenID+"/regen", nil, &resp); err != nil {
6464
return "", err
6565
}
6666
return resp.Key, nil

coder-sdk/users.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type SSHKey struct {
6464
// SSHKey gets the current SSH kepair of the authenticated user.
6565
func (c Client) SSHKey(ctx context.Context) (*SSHKey, error) {
6666
var key SSHKey
67-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users/me/sshkey", nil, &key); err != nil {
67+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/users/me/sshkey", nil, &key); err != nil {
6868
return nil, err
6969
}
7070
return &key, nil
@@ -73,7 +73,7 @@ func (c Client) SSHKey(ctx context.Context) (*SSHKey, error) {
7373
// Users gets the list of user accounts.
7474
func (c Client) Users(ctx context.Context) ([]User, error) {
7575
var u []User
76-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users", nil, &u); err != nil {
76+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/users", nil, &u); err != nil {
7777
return nil, err
7878
}
7979
return u, nil
@@ -111,7 +111,7 @@ type UpdateUserReq struct {
111111

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

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

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

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

0 commit comments

Comments
 (0)