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

Commit 0e6ae81

Browse files
authored
Migrate all API routes to /api/private (#193)
1 parent 25ae52a commit 0e6ae81

12 files changed

+55
-55
lines changed

coder-sdk/activity.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type activityRequest struct {
1212

1313
// PushActivity pushes CLI activity to Coder.
1414
func (c Client) PushActivity(ctx context.Context, source, envID string) error {
15-
resp, err := c.request(ctx, http.MethodPost, "/api/metrics/usage/push", activityRequest{
15+
resp, err := c.request(ctx, http.MethodPost, "/api/private/metrics/usage/push", activityRequest{
1616
Source: source,
1717
EnvironmentID: envID,
1818
})

coder-sdk/config.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,29 @@ type ConfigOAuth struct {
6767
// SiteConfigAuth fetches the sitewide authentication configuration.
6868
func (c Client) SiteConfigAuth(ctx context.Context) (*ConfigAuth, error) {
6969
var conf ConfigAuth
70-
if err := c.requestBody(ctx, http.MethodGet, "/api/auth/config", nil, &conf); err != nil {
70+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/auth/config", nil, &conf); err != nil {
7171
return nil, err
7272
}
7373
return &conf, nil
7474
}
7575

7676
// PutSiteConfigAuth sets the sitewide authentication configuration.
7777
func (c Client) PutSiteConfigAuth(ctx context.Context, req ConfigAuth) error {
78-
return c.requestBody(ctx, http.MethodPut, "/api/auth/config", req, nil)
78+
return c.requestBody(ctx, http.MethodPut, "/api/private/auth/config", req, nil)
7979
}
8080

8181
// SiteConfigOAuth fetches the sitewide git provider OAuth configuration.
8282
func (c Client) SiteConfigOAuth(ctx context.Context) (*ConfigOAuth, error) {
8383
var conf ConfigOAuth
84-
if err := c.requestBody(ctx, http.MethodGet, "/api/oauth/config", nil, &conf); err != nil {
84+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/oauth/config", nil, &conf); err != nil {
8585
return nil, err
8686
}
8787
return &conf, nil
8888
}
8989

9090
// PutSiteConfigOAuth sets the sitewide git provider OAuth configuration.
9191
func (c Client) PutSiteConfigOAuth(ctx context.Context, req ConfigOAuth) error {
92-
return c.requestBody(ctx, http.MethodPut, "/api/oauth/config", req, nil)
92+
return c.requestBody(ctx, http.MethodPut, "/api/private/oauth/config", req, nil)
9393
}
9494

9595
type configSetupMode struct {
@@ -99,7 +99,7 @@ type configSetupMode struct {
9999
// SiteSetupModeEnabled fetches the current setup_mode state of a Coder Enterprise deployment.
100100
func (c Client) SiteSetupModeEnabled(ctx context.Context) (bool, error) {
101101
var conf configSetupMode
102-
if err := c.requestBody(ctx, http.MethodGet, "/api/config/setup-mode", nil, &conf); err != nil {
102+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/config/setup-mode", nil, &conf); err != nil {
103103
return false, err
104104
}
105105
return conf.SetupMode, nil
@@ -127,13 +127,13 @@ type ConfigExtensionMarketplace struct {
127127
// SiteConfigExtensionMarketplace fetches the extension marketplace configuration.
128128
func (c Client) SiteConfigExtensionMarketplace(ctx context.Context) (*ConfigExtensionMarketplace, error) {
129129
var conf ConfigExtensionMarketplace
130-
if err := c.requestBody(ctx, http.MethodGet, "/api/extensions/config", nil, &conf); err != nil {
130+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/extensions/config", nil, &conf); err != nil {
131131
return nil, err
132132
}
133133
return &conf, nil
134134
}
135135

136136
// PutSiteConfigExtensionMarketplace sets the extension marketplace configuration.
137137
func (c Client) PutSiteConfigExtensionMarketplace(ctx context.Context, req ConfigExtensionMarketplace) error {
138-
return c.requestBody(ctx, http.MethodPut, "/api/extensions/config", req, nil)
138+
return c.requestBody(ctx, http.MethodPut, "/api/private/extensions/config", req, nil)
139139
}

coder-sdk/devurl.go

+3-3
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/environments/%s/devurls/%s", envID, urlID)
26+
reqURL := fmt.Sprintf("/api/private/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/environments/"+envID+"/devurls", req, nil)
45+
return c.requestBody(ctx, http.MethodPost, "/api/private/environments/"+envID+"/devurls", req, nil)
4646
}
4747

4848
// PutDevURLReq defines the request parameters for overwriting a DevURL.
4949
type PutDevURLReq CreateDevURLReq
5050

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

coder-sdk/env.go

+10-10
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ type CreateEnvironmentRequest struct {
8383
// CreateEnvironment sends a request to create an environment.
8484
func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateEnvironmentRequest) (*Environment, error) {
8585
var env Environment
86-
if err := c.requestBody(ctx, http.MethodPost, "/api/orgs/"+orgID+"/environments", req, &env); err != nil {
86+
if err := c.requestBody(ctx, http.MethodPost, "/api/private/orgs/"+orgID+"/environments", req, &env); err != nil {
8787
return nil, err
8888
}
8989
return &env, nil
@@ -93,7 +93,7 @@ func (c Client) CreateEnvironment(ctx context.Context, orgID string, req CreateE
9393
// TODO: add the filter options, explore performance issue.
9494
func (c Client) Environments(ctx context.Context) ([]Environment, error) {
9595
var envs []Environment
96-
if err := c.requestBody(ctx, http.MethodGet, "/api/environments", nil, &envs); err != nil {
96+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/environments", nil, &envs); err != nil {
9797
return nil, err
9898
}
9999
return envs, nil
@@ -102,20 +102,20 @@ func (c Client) Environments(ctx context.Context) ([]Environment, error) {
102102
// EnvironmentsByOrganization gets the list of environments owned by the given user.
103103
func (c Client) EnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error) {
104104
var envs []Environment
105-
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/members/"+userID+"/environments", nil, &envs); err != nil {
105+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/members/"+userID+"/environments", nil, &envs); err != nil {
106106
return nil, err
107107
}
108108
return envs, nil
109109
}
110110

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

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

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

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

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

144144
// DialWsep dials an environments command execution interface
@@ -163,7 +163,7 @@ func (c Client) DialIDEStatus(ctx context.Context, envID string) (*websocket.Con
163163

164164
// DialEnvironmentBuildLog opens a websocket connection for the environment build log messages.
165165
func (c Client) DialEnvironmentBuildLog(ctx context.Context, envID string) (*websocket.Conn, error) {
166-
return c.dialWebsocket(ctx, "/api/environments/"+envID+"/watch-update")
166+
return c.dialWebsocket(ctx, "/api/private/environments/"+envID+"/watch-update")
167167
}
168168

169169
// BuildLog defines a build log record for a Coder environment.
@@ -211,12 +211,12 @@ func (c Client) FollowEnvironmentBuildLog(ctx context.Context, envID string) (<-
211211

212212
// DialEnvironmentStats opens a websocket connection for environment stats.
213213
func (c Client) DialEnvironmentStats(ctx context.Context, envID string) (*websocket.Conn, error) {
214-
return c.dialWebsocket(ctx, "/api/environments/"+envID+"/watch-stats")
214+
return c.dialWebsocket(ctx, "/api/private/environments/"+envID+"/watch-stats")
215215
}
216216

217217
// DialResourceLoad opens a websocket connection for cpu load metrics on the environment.
218218
func (c Client) DialResourceLoad(ctx context.Context, envID string) (*websocket.Conn, error) {
219-
return c.dialWebsocket(ctx, "/api/environments/"+envID+"/watch-resource-load")
219+
return c.dialWebsocket(ctx, "/api/private/environments/"+envID+"/watch-resource-load")
220220
}
221221

222222
// BuildLogType describes the type of an event.

coder-sdk/image.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ type UpdateImageReq struct {
5858
// ImportImage creates a new image and optionally a new registry.
5959
func (c Client) ImportImage(ctx context.Context, orgID string, req ImportImageReq) (*Image, error) {
6060
var img Image
61-
if err := c.requestBody(ctx, http.MethodPost, "/api/orgs/"+orgID+"/images", req, &img); err != nil {
61+
if err := c.requestBody(ctx, http.MethodPost, "/api/private/orgs/"+orgID+"/images", req, &img); err != nil {
6262
return nil, err
6363
}
6464
return &img, nil
@@ -67,13 +67,13 @@ func (c Client) ImportImage(ctx context.Context, orgID string, req ImportImageRe
6767
// OrganizationImages returns all of the images imported for orgID.
6868
func (c Client) OrganizationImages(ctx context.Context, orgID string) ([]Image, error) {
6969
var imgs []Image
70-
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/images", nil, &imgs); err != nil {
70+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/images", nil, &imgs); err != nil {
7171
return nil, err
7272
}
7373
return imgs, nil
7474
}
7575

7676
// UpdateImage applies a partial update to an image resource.
7777
func (c Client) UpdateImage(ctx context.Context, imageID string, req UpdateImageReq) error {
78-
return c.requestBody(ctx, http.MethodPatch, "/api/images/"+imageID, req, nil)
78+
return c.requestBody(ctx, http.MethodPatch, "/api/private/images/"+imageID, req, nil)
7979
}

coder-sdk/org.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const (
3939
// Organizations gets all Organizations.
4040
func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
4141
var orgs []Organization
42-
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs", nil, &orgs); err != nil {
42+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs", nil, &orgs); err != nil {
4343
return nil, err
4444
}
4545
return orgs, nil
@@ -48,7 +48,7 @@ func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
4848
// OrganizationByID get the Organization by its ID.
4949
func (c Client) OrganizationByID(ctx context.Context, orgID string) (*Organization, error) {
5050
var org Organization
51-
err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID, nil, &org)
51+
err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID, nil, &org)
5252
if err != nil {
5353
return nil, err
5454
}
@@ -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/orgs/"+orgID+"/members", nil, &members); err != nil {
61+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/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/orgs/"+orgID, req, nil)
79+
return c.requestBody(ctx, http.MethodPatch, "/api/private/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/orgs", req, nil)
95+
return c.requestBody(ctx, http.MethodPost, "/api/private/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/orgs/"+orgID, nil, nil)
100+
return c.requestBody(ctx, http.MethodDelete, "/api/private/orgs/"+orgID, nil, nil)
101101
}

coder-sdk/registries.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type Registry struct {
1919
// Registries fetches all registries in an organization.
2020
func (c Client) Registries(ctx context.Context, orgID string) ([]Registry, error) {
2121
var r []Registry
22-
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/registries", nil, &r); err != nil {
22+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/registries", nil, &r); err != nil {
2323
return nil, err
2424
}
2525
return r, nil
@@ -28,7 +28,7 @@ func (c Client) Registries(ctx context.Context, orgID string) ([]Registry, error
2828
// RegistryByID fetches a registry resource by its ID.
2929
func (c Client) RegistryByID(ctx context.Context, orgID, registryID string) (*Registry, error) {
3030
var r Registry
31-
if err := c.requestBody(ctx, http.MethodGet, "/api/orgs/"+orgID+"/registries/"+registryID, nil, &r); err != nil {
31+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/registries/"+registryID, nil, &r); err != nil {
3232
return nil, err
3333
}
3434
return &r, nil
@@ -44,10 +44,10 @@ type UpdateRegistryReq struct {
4444

4545
// UpdateRegistry applies a partial update to a registry resource.
4646
func (c Client) UpdateRegistry(ctx context.Context, orgID, registryID string, req UpdateRegistryReq) error {
47-
return c.requestBody(ctx, http.MethodPatch, "/api/orgs/"+orgID+"/registries/"+registryID, req, nil)
47+
return c.requestBody(ctx, http.MethodPatch, "/api/private/orgs/"+orgID+"/registries/"+registryID, req, nil)
4848
}
4949

5050
// DeleteRegistry deletes a registry resource by its ID.
5151
func (c Client) DeleteRegistry(ctx context.Context, orgID, registryID string) error {
52-
return c.requestBody(ctx, http.MethodDelete, "/api/orgs/"+orgID+"/registries/"+registryID, nil, nil)
52+
return c.requestBody(ctx, http.MethodDelete, "/api/private/orgs/"+orgID+"/registries/"+registryID, nil, nil)
5353
}

coder-sdk/secrets.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type Secret struct {
2323
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
2424
func (c Client) Secrets(ctx context.Context, userID string) ([]Secret, error) {
2525
var secrets []Secret
26-
if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets", nil, &secrets); err != nil {
26+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users/"+userID+"/secrets", nil, &secrets); err != nil {
2727
return nil, err
2828
}
2929
return secrets, nil
@@ -42,7 +42,7 @@ func (c Client) SecretWithValueByName(ctx context.Context, name, userID string)
4242
// NOTE: This is racy, but acceptable. If the secret is gone or the permission changed since we looked up the id,
4343
// the call will simply fail and surface the error to the user.
4444
var secret Secret
45-
if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+s.ID, nil, &secret); err != nil {
45+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users/"+userID+"/secrets/"+s.ID, nil, &secret); err != nil {
4646
return nil, err
4747
}
4848
return &secret, nil
@@ -53,7 +53,7 @@ func (c Client) SecretWithValueByName(ctx context.Context, name, userID string)
5353
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
5454
func (c Client) SecretWithValueByID(ctx context.Context, id, userID string) (*Secret, error) {
5555
var secret Secret
56-
if err := c.requestBody(ctx, http.MethodGet, "/api/users/"+userID+"/secrets/"+id, nil, &secret); err != nil {
56+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users/"+userID+"/secrets/"+id, nil, &secret); err != nil {
5757
return nil, err
5858
}
5959
return &secret, nil
@@ -88,7 +88,7 @@ type InsertSecretReq struct {
8888
//
8989
// Deprecated: Coder Secrets will be removed from Coder Enterprise in a future release.
9090
func (c Client) InsertSecret(ctx context.Context, userID string, req InsertSecretReq) error {
91-
return c.requestBody(ctx, http.MethodPost, "/api/users/"+userID+"/secrets", req, nil)
91+
return c.requestBody(ctx, http.MethodPost, "/api/private/users/"+userID+"/secrets", req, nil)
9292
}
9393

9494
// DeleteSecretByName deletes the authenticated users secret with the given name.
@@ -103,7 +103,7 @@ func (c Client) DeleteSecretByName(ctx context.Context, name, userID string) err
103103
// Delete the secret.
104104
// NOTE: This is racy, but acceptable. If the secret is gone or the permission changed since we looked up the id,
105105
// the call will simply fail and surface the error to the user.
106-
resp, err := c.request(ctx, http.MethodDelete, "/api/users/"+userID+"/secrets/"+secret.ID, nil)
106+
resp, err := c.request(ctx, http.MethodDelete, "/api/private/users/"+userID+"/secrets/"+secret.ID, nil)
107107
if err != nil {
108108
return err
109109
}

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/images/"+imageID+"/tags", req, tag); err != nil {
45+
if err := c.requestBody(ctx, http.MethodPost, "/api/private/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/images/"+imageID+"/tags/"+tag, nil, nil)
53+
return c.requestBody(ctx, http.MethodDelete, "/api/private/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/images/"+imageID+"/tags", nil, &tags); err != nil {
59+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/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/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
68+
if err := c.requestBody(ctx, http.MethodGet, "/api/private/images/"+imageID+"/tags/"+tagID, nil, &tag); err != nil {
6969
return nil, err
7070
}
7171
return &tag, nil

0 commit comments

Comments
 (0)