This repository was archived by the owner on Aug 30, 2024. It is now read-only.
- Notifications
You must be signed in to change notification settings - Fork18
Add ability to create new environments and images to the coder-sdk#100
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
66 changes: 43 additions & 23 deletionscoder-sdk/env.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletionscoder-sdk/image.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package coder | ||
import ( | ||
"context" | ||
"net/http" | ||
) | ||
// Image describes a Coder Image | ||
type Image struct { | ||
ID string `json:"id"` | ||
OrganizationID string `json:"organization_id"` | ||
Repository string `json:"repository"` | ||
Description string `json:"description"` | ||
URL string `json:"url"` // user-supplied URL for image | ||
DefaultCPUCores float32 `json:"default_cpu_cores"` | ||
DefaultMemoryGB int `json:"default_memory_gb"` | ||
DefaultDiskGB int `json:"default_disk_gb"` | ||
Deprecated bool `json:"deprecated"` | ||
} | ||
// NewRegistryRequest describes a docker registry used in importing an image | ||
type NewRegistryRequest struct { | ||
FriendlyName string `json:"friendly_name"` | ||
Registry string `json:"registry"` | ||
Username string `json:"username"` | ||
Password string `json:"password"` | ||
} | ||
// ImportImageRequest is used to import new images and registries into Coder | ||
type ImportImageRequest struct { | ||
// RegistryID is used to import images to existing registries. | ||
RegistryID *string `json:"registry_id"` | ||
// NewRegistry is used when adding a new registry. | ||
NewRegistry *NewRegistryRequest `json:"new_registry"` | ||
// Repository refers to the image. For example: "codercom/ubuntu". | ||
Repository string `json:"repository"` | ||
Tag string `json:"tag"` | ||
DefaultCPUCores float32 `json:"default_cpu_cores"` | ||
DefaultMemoryGB int `json:"default_memory_gb"` | ||
DefaultDiskGB int `json:"default_disk_gb"` | ||
Description string `json:"description"` | ||
URL string `json:"url"` | ||
} | ||
// ImportImage creates a new image and optionally a new registry | ||
func (c Client) ImportImage(ctx context.Context, orgID string, req ImportImageRequest) (*Image, error) { | ||
var img *Image | ||
err := c.requestBody( | ||
ctx, | ||
http.MethodPost, "/api/orgs/"+orgID+"/images", | ||
req, | ||
img, | ||
) | ||
return img, err | ||
} |
33 changes: 33 additions & 0 deletionscoder-sdk/ws.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package coder | ||
import ( | ||
"context" | ||
"nhooyr.io/websocket" | ||
) | ||
func (c Client) dialWs(ctx context.Context, path string) (*websocket.Conn, error) { | ||
u := c.copyURL() | ||
if c.BaseURL.Scheme == "https" { | ||
u.Scheme = "wss" | ||
} else { | ||
u.Scheme = "ws" | ||
} | ||
u.Path = path | ||
conn, resp, err := websocket.Dial(ctx, u.String(), | ||
&websocket.DialOptions{ | ||
HTTPHeader: map[string][]string{ | ||
"Session-Token": {c.Token}, | ||
}, | ||
}, | ||
) | ||
if err != nil { | ||
if resp != nil { | ||
return nil, bodyError(resp) | ||
} | ||
return nil, err | ||
} | ||
return conn, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.