Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

Commitb04eb60

Browse files
authored
chore: update API-breaking environment routes (#218)
- The structure of our routing tree is being refactored as part of the effort to prepare our API for public consumption. This PR fixes some routes that were broken in a way that was not backwards compatible.
1 parentfb4ac31 commitb04eb60

File tree

7 files changed

+30
-19
lines changed

7 files changed

+30
-19
lines changed

‎coder-sdk/env.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ const (
7575
typeCreateEnvironmentRequeststruct {
7676
Namestring`json:"name"`
7777
ImageIDstring`json:"image_id"`
78+
OrgIDstring`json:"org_id"`
7879
ImageTagstring`json:"image_tag"`
7980
CPUCoresfloat32`json:"cpu_cores"`
8081
MemoryGBfloat32`json:"memory_gb"`
@@ -85,9 +86,9 @@ type CreateEnvironmentRequest struct {
8586
}
8687

8788
// CreateEnvironment sends a request to create an environment.
88-
func (cClient)CreateEnvironment(ctx context.Context,orgIDstring,reqCreateEnvironmentRequest) (*Environment,error) {
89+
func (cClient)CreateEnvironment(ctx context.Context,reqCreateEnvironmentRequest) (*Environment,error) {
8990
varenvEnvironment
90-
iferr:=c.requestBody(ctx,http.MethodPost,"/api/private/orgs/"+orgID+"/environments",req,&env);err!=nil {
91+
iferr:=c.requestBody(ctx,http.MethodPost,"/api/v0/environments",req,&env);err!=nil {
9192
returnnil,err
9293
}
9394
return&env,nil
@@ -103,10 +104,17 @@ func (c Client) Environments(ctx context.Context) ([]Environment, error) {
103104
returnenvs,nil
104105
}
105106

106-
// EnvironmentsByOrganization gets the list of environments owned by the given user.
107-
func (cClient)EnvironmentsByOrganization(ctx context.Context,userID,orgIDstring) ([]Environment,error) {
108-
varenvs []Environment
109-
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/orgs/"+orgID+"/members/"+userID+"/environments",nil,&envs);err!=nil {
107+
// UserEnvironmentsByOrganization gets the list of environments owned by the given user.
108+
func (cClient)UserEnvironmentsByOrganization(ctx context.Context,userID,orgIDstring) ([]Environment,error) {
109+
var (
110+
envs []Environment
111+
query= url.Values{}
112+
)
113+
114+
query.Add("orgs",orgID)
115+
query.Add("users",userID)
116+
117+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/v0/environments",nil,&envs,withQueryParams(query));err!=nil {
110118
returnnil,err
111119
}
112120
returnenvs,nil

‎coder-sdk/org.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const (
3939
// Organizations gets all Organizations.
4040
func (cClient)Organizations(ctx context.Context) ([]Organization,error) {
4141
varorgs []Organization
42-
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/orgs",nil,&orgs);err!=nil {
42+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/v0/orgs",nil,&orgs);err!=nil {
4343
returnnil,err
4444
}
4545
returnorgs,nil
@@ -48,7 +48,7 @@ func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
4848
// OrganizationByID get the Organization by its ID.
4949
func (cClient)OrganizationByID(ctx context.Context,orgIDstring) (*Organization,error) {
5050
varorgOrganization
51-
err:=c.requestBody(ctx,http.MethodGet,"/api/private/orgs/"+orgID,nil,&org)
51+
err:=c.requestBody(ctx,http.MethodGet,"/api/v0/orgs/"+orgID,nil,&org)
5252
iferr!=nil {
5353
returnnil,err
5454
}

‎coder-sdk/request.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func (c Client) request(ctx context.Context, method, path string, in interface{}
5050

5151
// requestBody is a helper extending the Client.request helper, checking the response code
5252
// and decoding the response payload.
53-
func (cClient)requestBody(ctx context.Context,method,pathstring,in,outinterface{})error {
54-
resp,err:=c.request(ctx,method,path,in)
53+
func (cClient)requestBody(ctx context.Context,method,pathstring,in,outinterface{},opts...requestOption)error {
54+
resp,err:=c.request(ctx,method,path,in,opts...)
5555
iferr!=nil {
5656
returnxerrors.Errorf("Execute request: %q",err)
5757
}

‎coder-sdk/users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (c Client) Me(ctx context.Context) (*User, error) {
4949
// UserByID get the details of a user by their id.
5050
func (cClient)UserByID(ctx context.Context,idstring) (*User,error) {
5151
varuUser
52-
iferr:=c.requestBody(ctx,http.MethodGet,"/api/private/users/"+id,nil,&u);err!=nil {
52+
iferr:=c.requestBody(ctx,http.MethodGet,"/api/v0/users/"+id,nil,&u);err!=nil {
5353
returnnil,err
5454
}
5555
return&u,nil

‎coder-sdk/ws.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,18 @@ import (
1010

1111
typerequestOptionsstruct {
1212
BaseURLOverride*url.URL
13+
Query url.Values
1314
}
1415

1516
typerequestOptionfunc(*requestOptions)
1617

18+
// withQueryParams sets the provided query parameters on the request.
19+
funcwithQueryParams(q url.Values)func(o*requestOptions) {
20+
returnfunc(o*requestOptions) {
21+
o.Query=q
22+
}
23+
}
24+
1725
funcwithBaseURL(base*url.URL)func(o*requestOptions) {
1826
returnfunc(o*requestOptions) {
1927
o.BaseURLOverride=base
@@ -31,12 +39,6 @@ func (c Client) dialWebsocket(ctx context.Context, path string, options ...reque
3139
ifconfig.BaseURLOverride!=nil {
3240
url=*config.BaseURLOverride
3341
}
34-
35-
ifurl.Scheme=="https" {
36-
url.Scheme="wss"
37-
}else {
38-
url.Scheme="ws"
39-
}
4042
url.Path=path
4143

4244
conn,resp,err:=websocket.Dial(ctx,url.String(),&websocket.DialOptions{HTTPHeader: http.Header{"Session-Token": {c.Token}}})

‎internal/cmd/ceapi.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func getEnvs(ctx context.Context, client *coder.Client, email string) ([]coder.E
4848
varallEnvs []coder.Environment
4949

5050
for_,org:=rangeorgs {
51-
envs,err:=client.EnvironmentsByOrganization(ctx,user.ID,org.ID)
51+
envs,err:=client.UserEnvironmentsByOrganization(ctx,user.ID,org.ID)
5252
iferr!=nil {
5353
returnnil,xerrors.Errorf("get envs for %s: %w",org.Name,err)
5454
}

‎internal/cmd/envs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
197197
createReq:=&coder.CreateEnvironmentRequest{
198198
Name:args[0],
199199
ImageID:importedImg.ID,
200+
OrgID:importedImg.OrganizationID,
200201
ImageTag:tag,
201202
CPUCores:cpu,
202203
MemoryGB:memory,
@@ -217,7 +218,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
217218
createReq.DiskGB=importedImg.DefaultDiskGB
218219
}
219220

220-
env,err:=client.CreateEnvironment(ctx,importedImg.OrganizationID,*createReq)
221+
env,err:=client.CreateEnvironment(ctx,*createReq)
221222
iferr!=nil {
222223
returnxerrors.Errorf("create environment: %w",err)
223224
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp