Thanks to visit codestin.com
Credit goes to github.com

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

Commit 2da0a05

Browse files
authored
chore: update API routes for images/registries (#220)
- This is part of an ongoing effort to standardize our API for public consumption. This fixes some routes that broke backwards compatibility (specifically image and registry routes).
1 parent e52bd24 commit 2da0a05

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

ci/integration/envs_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ search:
8181
}
8282
if !found {
8383
// ignore this error for now as it causes a race with other parallel tests
84-
_, _ = client.ImportImage(ctx, org.ID, coder.ImportImageReq{
84+
_, _ = client.ImportImage(ctx, coder.ImportImageReq{
8585
RegistryID: &dockerhubID,
86+
OrgID: org.ID,
8687
Repository: img,
8788
Tag: "latest",
8889
DefaultCPUCores: 2.5,

coder-sdk/image.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coder
33
import (
44
"context"
55
"net/http"
6+
"net/url"
67
"time"
78
)
89

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

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

6769
// OrganizationImages returns all of the images imported for orgID.
6870
func (c Client) OrganizationImages(ctx context.Context, orgID string) ([]Image, error) {
69-
var imgs []Image
70-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/images", nil, &imgs); err != nil {
71+
var (
72+
imgs []Image
73+
query = url.Values{}
74+
)
75+
76+
query.Set("org", orgID)
77+
78+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/images", nil, &imgs, withQueryParams(query)); err != nil {
7179
return nil, err
7280
}
7381
return imgs, nil
7482
}
7583

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

8189
// UpdateImageTags refreshes the latest digests for all tags of the image.
8290
func (c Client) UpdateImageTags(ctx context.Context, imageID string) error {
83-
return c.requestBody(ctx, http.MethodPost, "/api/private/images/"+imageID+"/tags/update", nil, nil)
91+
return c.requestBody(ctx, http.MethodPost, "/api/v0/images/"+imageID+"/tags/update", nil, nil)
8492
}

coder-sdk/registries.go

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package coder
33
import (
44
"context"
55
"net/http"
6+
"net/url"
67
"time"
78
)
89

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

1920
// Registries fetches all registries in an organization.
2021
func (c Client) Registries(ctx context.Context, orgID string) ([]Registry, error) {
21-
var r []Registry
22-
if err := c.requestBody(ctx, http.MethodGet, "/api/private/orgs/"+orgID+"/registries", nil, &r); err != nil {
22+
var (
23+
r []Registry
24+
query = url.Values{}
25+
)
26+
27+
query.Set("org", orgID)
28+
29+
if err := c.requestBody(ctx, http.MethodGet, "/api/v0/registries", nil, &r, withQueryParams(query)); err != nil {
2330
return nil, err
2431
}
2532
return r, nil
2633
}
2734

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

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

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

0 commit comments

Comments
 (0)