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 routes for images/registries#220

Merged
sreya merged 1 commit intomasterfromupdate-img-routes
Jan 18, 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
3 changes: 2 additions & 1 deletionci/integration/envs_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -81,8 +81,9 @@ search:
}
if !found {
// ignore this error for now as it causes a race with other parallel tests
_, _ = client.ImportImage(ctx,org.ID,coder.ImportImageReq{
_, _ = client.ImportImage(ctx, coder.ImportImageReq{
RegistryID: &dockerhubID,
OrgID: org.ID,
Repository: img,
Tag: "latest",
DefaultCPUCores: 2.5,
Expand Down
20 changes: 14 additions & 6 deletionscoder-sdk/image.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package coder
import (
"context"
"net/http"
"net/url"
"time"
)

Expand DownExpand Up@@ -36,6 +37,7 @@ type ImportImageReq struct {
RegistryID *string `json:"registry_id"` // Used to import images to existing registries.
NewRegistry *NewRegistryRequest `json:"new_registry"` // Used when adding a new registry.
Repository string `json:"repository"` // Refers to the image. Ex: "codercom/ubuntu".
OrgID string `json:"org_id"`
Tag string `json:"tag"`
DefaultCPUCores float32 `json:"default_cpu_cores"`
DefaultMemoryGB int `json:"default_memory_gb"`
Expand All@@ -56,29 +58,35 @@ type UpdateImageReq struct {
}

// ImportImage creates a new image and optionally a new registry.
func (c Client) ImportImage(ctx context.Context,orgID string,req ImportImageReq) (*Image, error) {
func (c Client) ImportImage(ctx context.Context, req ImportImageReq) (*Image, error) {
var img Image
if err := c.requestBody(ctx, http.MethodPost, "/api/private/orgs/"+orgID+"/images", req, &img); err != nil {
if err := c.requestBody(ctx, http.MethodPost, "/api/v0/images", req, &img); err != nil {
return nil, err
}
return &img, nil
}

// OrganizationImages returns all of the images imported for orgID.
func (c Client) OrganizationImages(ctx context.Context, orgID string) ([]Image, error) {
var imgs []Image
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/images", nil, &imgs); err != nil {
var (
imgs []Image
query = url.Values{}
)

query.Set("org", orgID)

if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images", nil, &imgs, withQueryParams(query)); err != nil {
return nil, err
}
return imgs, nil
}

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

// UpdateImageTags refreshes the latest digests for all tags of the image.
func (c Client) UpdateImageTags(ctx context.Context, imageID string) error {
return c.requestBody(ctx, http.MethodPost, "/api/private/images/"+imageID+"/tags/update", nil, nil)
return c.requestBody(ctx, http.MethodPost, "/api/v0/images/"+imageID+"/tags/update", nil, nil)
}
23 changes: 15 additions & 8 deletionscoder-sdk/registries.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,6 +3,7 @@ package coder
import (
"context"
"net/http"
"net/url"
"time"
)

Expand All@@ -18,17 +19,23 @@ type Registry struct {

// Registries fetches all registries in an organization.
func (c Client) Registries(ctx context.Context, orgID string) ([]Registry, error) {
var r []Registry
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/registries", nil, &r); err != nil {
var (
r []Registry
query = url.Values{}
)

query.Set("org", orgID)

if err := c.requestBody(ctx, http.MethodGet, "/api/v0/registries", nil, &r, withQueryParams(query)); err != nil {
return nil, err
}
return r, nil
}

// RegistryByID fetches a registry resource by its ID.
func (c Client) RegistryByID(ctx context.Context,orgID,registryID string) (*Registry, error) {
func (c Client) RegistryByID(ctx context.Context, registryID string) (*Registry, error) {
var r Registry
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/registries/"+registryID, nil, &r); err != nil {
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/registries/"+registryID, nil, &r); err != nil {
return nil, err
}
return &r, nil
Expand All@@ -43,11 +50,11 @@ type UpdateRegistryReq struct {
}

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

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

[8]ページ先頭

©2009-2025 Movatter.jp