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

chore: update API-breaking environment routes#218

Merged
sreya merged 1 commit intomasterfromupdate-routes
Jan 15, 2021
Merged
Show file tree
Hide file tree
Changes fromall 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
20 changes: 14 additions & 6 deletionscoder-sdk/env.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -75,6 +75,7 @@ const (
type CreateEnvironmentRequest struct {
Name string `json:"name"`
ImageID string `json:"image_id"`
OrgID string `json:"org_id"`
ImageTag string `json:"image_tag"`
CPUCores float32 `json:"cpu_cores"`
MemoryGB float32 `json:"memory_gb"`
Expand All@@ -85,9 +86,9 @@ type CreateEnvironmentRequest struct {
}

// CreateEnvironment sends a request to create an environment.
func (c Client) CreateEnvironment(ctx context.Context,orgID string,req CreateEnvironmentRequest) (*Environment, error) {
func (c Client) CreateEnvironment(ctx context.Context, req CreateEnvironmentRequest) (*Environment, error) {
var env Environment
if err := c.requestBody(ctx, http.MethodPost, "/api/private/orgs/"+orgID+"/environments", req, &env); err != nil {
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/environments", req, &env); err != nil {
return nil, err
}
return &env, nil
Expand All@@ -103,10 +104,17 @@ func (c Client) Environments(ctx context.Context) ([]Environment, error) {
return envs, nil
}

// EnvironmentsByOrganization gets the list of environments owned by the given user.
func (c Client) EnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error) {
var envs []Environment
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/members/"+userID+"/environments", nil, &envs); err != nil {
// UserEnvironmentsByOrganization gets the list of environments owned by the given user.
func (c Client) UserEnvironmentsByOrganization(ctx context.Context, userID, orgID string) ([]Environment, error) {
var (
envs []Environment
query = url.Values{}
)

query.Add("orgs", orgID)
query.Add("users", userID)

if err := c.requestBody(ctx, http.MethodGet, "/api/v0/environments", nil, &envs, withQueryParams(query)); err != nil {
return nil, err
}
return envs, nil
Expand Down
4 changes: 2 additions & 2 deletionscoder-sdk/org.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -39,7 +39,7 @@ const (
// Organizations gets all Organizations.
func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
var orgs []Organization
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs", nil, &orgs); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/orgs", nil, &orgs); err != nil {
return nil, err
}
return orgs, nil
Expand All@@ -48,7 +48,7 @@ func (c Client) Organizations(ctx context.Context) ([]Organization, error) {
// OrganizationByID get the Organization by its ID.
func (c Client) OrganizationByID(ctx context.Context, orgID string) (*Organization, error) {
var org Organization
err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID, nil, &org)
err := c.requestBody(ctx, http.MethodGet, "/api/v0/orgs/"+orgID, nil, &org)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletionscoder-sdk/request.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -50,8 +50,8 @@ func (c Client) request(ctx context.Context, method, path string, in interface{}

// requestBody is a helper extending the Client.request helper, checking the response code
// and decoding the response payload.
func (c Client) requestBody(ctx context.Context, method, path string, in, out interface{}) error {
resp, err := c.request(ctx, method, path, in)
func (c Client) requestBody(ctx context.Context, method, path string, in, out interface{}, opts ...requestOption) error {
resp, err := c.request(ctx, method, path, in, opts...)
if err != nil {
return xerrors.Errorf("Execute request: %q", err)
}
Expand Down
2 changes: 1 addition & 1 deletioncoder-sdk/users.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -49,7 +49,7 @@ func (c Client) Me(ctx context.Context) (*User, error) {
// UserByID get the details of a user by their id.
func (c Client) UserByID(ctx context.Context, id string) (*User, error) {
var u User
if err := c.requestBody(ctx, http.MethodGet, "/api/private/users/"+id, nil, &u); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/users/"+id, nil, &u); err != nil {
return nil, err
}
return &u, nil
Expand Down
14 changes: 8 additions & 6 deletionscoder-sdk/ws.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -10,10 +10,18 @@ import (

type requestOptions struct {
BaseURLOverride *url.URL
Query url.Values
}

type requestOption func(*requestOptions)

// withQueryParams sets the provided query parameters on the request.
func withQueryParams(q url.Values) func(o *requestOptions) {
return func(o *requestOptions) {
o.Query = q
}
}

func withBaseURL(base *url.URL) func(o *requestOptions) {
return func(o *requestOptions) {
o.BaseURLOverride = base
Expand All@@ -31,12 +39,6 @@ func (c Client) dialWebsocket(ctx context.Context, path string, options ...reque
if config.BaseURLOverride != nil {
url = *config.BaseURLOverride
}

if url.Scheme == "https" {
url.Scheme = "wss"
} else {
url.Scheme = "ws"
}
url.Path = path

conn, resp, err := websocket.Dial(ctx, url.String(), &websocket.DialOptions{HTTPHeader: http.Header{"Session-Token": {c.Token}}})
Expand Down
2 changes: 1 addition & 1 deletioninternal/cmd/ceapi.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -48,7 +48,7 @@ func getEnvs(ctx context.Context, client *coder.Client, email string) ([]coder.E
var allEnvs []coder.Environment

for _, org := range orgs {
envs, err := client.EnvironmentsByOrganization(ctx, user.ID, org.ID)
envs, err := client.UserEnvironmentsByOrganization(ctx, user.ID, org.ID)
if err != nil {
return nil, xerrors.Errorf("get envs for %s: %w", org.Name, err)
}
Expand Down
3 changes: 2 additions & 1 deletioninternal/cmd/envs.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -197,6 +197,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
createReq := &coder.CreateEnvironmentRequest{
Name: args[0],
ImageID: importedImg.ID,
OrgID: importedImg.OrganizationID,
ImageTag: tag,
CPUCores: cpu,
MemoryGB: memory,
Expand All@@ -217,7 +218,7 @@ coder envs create my-new-powerful-env --cpu 12 --disk 100 --memory 16 --image ub
createReq.DiskGB = importedImg.DefaultDiskGB
}

env, err := client.CreateEnvironment(ctx,importedImg.OrganizationID,*createReq)
env, err := client.CreateEnvironment(ctx, *createReq)
if err != nil {
return xerrors.Errorf("create environment: %w", err)
}
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp