Skip to content

Commit 7130977

Browse files
authored
featmigrate API prefix from /api to /v1 and default to api.onecli.sh (#60)
1 parent f22ac91 commit 7130977

16 files changed

Lines changed: 65 additions & 65 deletions

File tree

cmd/onecli/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (c *MigrateCmd) Run(out *output.Writer) error {
2222
if c.DryRun {
2323
return out.WriteDryRun("Would migrate data to OneCLI Cloud", map[string]string{
2424
"source": config.APIHost(),
25-
"target": "https://app.onecli.sh",
25+
"target": "https://api.onecli.sh",
2626
})
2727
}
2828

internal/api/agents.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type SuccessResponse struct {
5151
// ListAgents returns all agents for the authenticated user.
5252
// If projectID is non-empty, results are scoped to that project.
5353
func (c *Client) ListAgents(ctx context.Context, projectID string) ([]Agent, error) {
54-
path := withProjectQuery("/api/agents", projectID)
54+
path := withProjectQuery("/v1/agents", projectID)
5555
var agents []Agent
5656
if err := c.do(ctx, http.MethodGet, path, nil, &agents); err != nil {
5757
return nil, fmt.Errorf("listing agents: %w", err)
@@ -62,7 +62,7 @@ func (c *Client) ListAgents(ctx context.Context, projectID string) ([]Agent, err
6262
// GetDefaultAgent returns the user's default agent.
6363
func (c *Client) GetDefaultAgent(ctx context.Context) (*Agent, error) {
6464
var agent Agent
65-
if err := c.do(ctx, http.MethodGet, "/api/agents/default", nil, &agent); err != nil {
65+
if err := c.do(ctx, http.MethodGet, "/v1/agents/default", nil, &agent); err != nil {
6666
return nil, fmt.Errorf("getting default agent: %w", err)
6767
}
6868
return &agent, nil
@@ -71,7 +71,7 @@ func (c *Client) GetDefaultAgent(ctx context.Context) (*Agent, error) {
7171
// CreateAgent creates a new agent.
7272
// If projectID is non-empty, the agent is created in that project.
7373
func (c *Client) CreateAgent(ctx context.Context, projectID string, input CreateAgentInput) (*Agent, error) {
74-
path := withProjectQuery("/api/agents", projectID)
74+
path := withProjectQuery("/v1/agents", projectID)
7575
var agent Agent
7676
if err := c.do(ctx, http.MethodPost, path, input, &agent); err != nil {
7777
return nil, fmt.Errorf("creating agent: %w", err)
@@ -81,7 +81,7 @@ func (c *Client) CreateAgent(ctx context.Context, projectID string, input Create
8181

8282
// DeleteAgent deletes an agent by ID.
8383
func (c *Client) DeleteAgent(ctx context.Context, id string) error {
84-
if err := c.do(ctx, http.MethodDelete, "/api/agents/"+id, nil, nil); err != nil {
84+
if err := c.do(ctx, http.MethodDelete, "/v1/agents/"+id, nil, nil); err != nil {
8585
return fmt.Errorf("deleting agent: %w", err)
8686
}
8787
return nil
@@ -90,7 +90,7 @@ func (c *Client) DeleteAgent(ctx context.Context, id string) error {
9090
// RenameAgent renames an agent.
9191
func (c *Client) RenameAgent(ctx context.Context, id string, input RenameAgentInput) error {
9292
var resp SuccessResponse
93-
if err := c.do(ctx, http.MethodPatch, "/api/agents/"+id, input, &resp); err != nil {
93+
if err := c.do(ctx, http.MethodPatch, "/v1/agents/"+id, input, &resp); err != nil {
9494
return fmt.Errorf("renaming agent: %w", err)
9595
}
9696
return nil
@@ -99,7 +99,7 @@ func (c *Client) RenameAgent(ctx context.Context, id string, input RenameAgentIn
9999
// RegenerateAgentToken regenerates an agent's access token.
100100
func (c *Client) RegenerateAgentToken(ctx context.Context, id string) (*RegenerateTokenResponse, error) {
101101
var resp RegenerateTokenResponse
102-
if err := c.do(ctx, http.MethodPost, "/api/agents/"+id+"/regenerate-token", nil, &resp); err != nil {
102+
if err := c.do(ctx, http.MethodPost, "/v1/agents/"+id+"/regenerate-token", nil, &resp); err != nil {
103103
return nil, fmt.Errorf("regenerating agent token: %w", err)
104104
}
105105
return &resp, nil
@@ -108,7 +108,7 @@ func (c *Client) RegenerateAgentToken(ctx context.Context, id string) (*Regenera
108108
// GetAgentSecrets returns the secret IDs assigned to an agent.
109109
func (c *Client) GetAgentSecrets(ctx context.Context, id string) ([]string, error) {
110110
var secretIDs []string
111-
if err := c.do(ctx, http.MethodGet, "/api/agents/"+id+"/secrets", nil, &secretIDs); err != nil {
111+
if err := c.do(ctx, http.MethodGet, "/v1/agents/"+id+"/secrets", nil, &secretIDs); err != nil {
112112
return nil, fmt.Errorf("getting agent secrets: %w", err)
113113
}
114114
return secretIDs, nil
@@ -117,7 +117,7 @@ func (c *Client) GetAgentSecrets(ctx context.Context, id string) ([]string, erro
117117
// SetAgentSecrets replaces an agent's secret assignments.
118118
func (c *Client) SetAgentSecrets(ctx context.Context, id string, input SetAgentSecretsInput) error {
119119
var resp SuccessResponse
120-
if err := c.do(ctx, http.MethodPut, "/api/agents/"+id+"/secrets", input, &resp); err != nil {
120+
if err := c.do(ctx, http.MethodPut, "/v1/agents/"+id+"/secrets", input, &resp); err != nil {
121121
return fmt.Errorf("setting agent secrets: %w", err)
122122
}
123123
return nil
@@ -126,7 +126,7 @@ func (c *Client) SetAgentSecrets(ctx context.Context, id string, input SetAgentS
126126
// SetAgentSecretMode updates an agent's secret mode.
127127
func (c *Client) SetAgentSecretMode(ctx context.Context, id string, input SetSecretModeInput) error {
128128
var resp SuccessResponse
129-
if err := c.do(ctx, http.MethodPatch, "/api/agents/"+id+"/secret-mode", input, &resp); err != nil {
129+
if err := c.do(ctx, http.MethodPatch, "/v1/agents/"+id+"/secret-mode", input, &resp); err != nil {
130130
return fmt.Errorf("setting agent secret mode: %w", err)
131131
}
132132
return nil

internal/api/apps.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"net/http"
77
)
88

9-
// App represents an app from the /api/apps endpoints.
9+
// App represents an app from the /v1/apps endpoints.
1010
type App struct {
1111
ID string `json:"id"`
1212
Name string `json:"name"`
@@ -40,7 +40,7 @@ type ConfigAppInput struct {
4040
// ListApps returns all apps with their config and connection status.
4141
func (c *Client) ListApps(ctx context.Context) ([]App, error) {
4242
var apps []App
43-
if err := c.do(ctx, http.MethodGet, "/api/apps", nil, &apps); err != nil {
43+
if err := c.do(ctx, http.MethodGet, "/v1/apps", nil, &apps); err != nil {
4444
return nil, fmt.Errorf("listing apps: %w", err)
4545
}
4646
return apps, nil
@@ -49,7 +49,7 @@ func (c *Client) ListApps(ctx context.Context) ([]App, error) {
4949
// GetApp returns a single app by provider name.
5050
func (c *Client) GetApp(ctx context.Context, provider string) (*App, error) {
5151
var app App
52-
if err := c.do(ctx, http.MethodGet, "/api/apps/"+provider, nil, &app); err != nil {
52+
if err := c.do(ctx, http.MethodGet, "/v1/apps/"+provider, nil, &app); err != nil {
5353
return nil, fmt.Errorf("getting app: %w", err)
5454
}
5555
return &app, nil
@@ -58,23 +58,23 @@ func (c *Client) GetApp(ctx context.Context, provider string) (*App, error) {
5858
// ConfigureApp saves BYOC credentials for a provider.
5959
func (c *Client) ConfigureApp(ctx context.Context, provider string, input ConfigAppInput) error {
6060
var resp SuccessResponse
61-
if err := c.do(ctx, http.MethodPost, "/api/apps/"+provider+"/config", input, &resp); err != nil {
61+
if err := c.do(ctx, http.MethodPost, "/v1/apps/"+provider+"/config", input, &resp); err != nil {
6262
return fmt.Errorf("configuring app: %w", err)
6363
}
6464
return nil
6565
}
6666

6767
// UnconfigureApp removes BYOC credentials for a provider.
6868
func (c *Client) UnconfigureApp(ctx context.Context, provider string) error {
69-
if err := c.do(ctx, http.MethodDelete, "/api/apps/"+provider+"/config", nil, nil); err != nil {
69+
if err := c.do(ctx, http.MethodDelete, "/v1/apps/"+provider+"/config", nil, nil); err != nil {
7070
return fmt.Errorf("unconfiguring app: %w", err)
7171
}
7272
return nil
7373
}
7474

7575
// DisconnectApp removes the OAuth connection for a provider.
7676
func (c *Client) DisconnectApp(ctx context.Context, provider string) error {
77-
if err := c.do(ctx, http.MethodDelete, "/api/apps/"+provider+"/connection", nil, nil); err != nil {
77+
if err := c.do(ctx, http.MethodDelete, "/v1/apps/"+provider+"/connection", nil, nil); err != nil {
7878
return fmt.Errorf("disconnecting app: %w", err)
7979
}
8080
return nil

internal/api/client_test.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,10 @@ func TestDoSendsCorrectPath(t *testing.T) {
239239
defer srv.Close()
240240

241241
client := New(srv.URL, "")
242-
_ = client.do(context.Background(), http.MethodGet, "/api/agents", nil, nil)
242+
_ = client.do(context.Background(), http.MethodGet, "/v1/agents", nil, nil)
243243

244-
if gotPath != "/api/agents" {
245-
t.Errorf("path = %q, want /api/agents", gotPath)
244+
if gotPath != "/v1/agents" {
245+
t.Errorf("path = %q, want /v1/agents", gotPath)
246246
}
247247
}
248248

@@ -255,27 +255,27 @@ func TestWithProjectQuery(t *testing.T) {
255255
}{
256256
{
257257
name: "empty project returns path unchanged",
258-
path: "/api/agents",
258+
path: "/v1/agents",
259259
projectID: "",
260-
want: "/api/agents",
260+
want: "/v1/agents",
261261
},
262262
{
263263
name: "appends projectId query param",
264-
path: "/api/agents",
264+
path: "/v1/agents",
265265
projectID: "my-project",
266-
want: "/api/agents?projectId=my-project",
266+
want: "/v1/agents?projectId=my-project",
267267
},
268268
{
269269
name: "preserves existing query params",
270-
path: "/api/agents?foo=bar",
270+
path: "/v1/agents?foo=bar",
271271
projectID: "proj",
272-
want: "/api/agents?foo=bar&projectId=proj",
272+
want: "/v1/agents?foo=bar&projectId=proj",
273273
},
274274
{
275275
name: "encodes special characters",
276-
path: "/api/secrets",
276+
path: "/v1/secrets",
277277
projectID: "has space&more",
278-
want: "/api/secrets?projectId=has+space%26more",
278+
want: "/v1/secrets?projectId=has+space%26more",
279279
},
280280
}
281281
for _, tt := range tests {

internal/api/health.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ package api
22

33
import "context"
44

5-
// HealthResponse is the response from /api/health.
5+
// HealthResponse is the response from /v1/health.
66
type HealthResponse struct {
77
Status string `json:"status"`
88
Version string `json:"version"`
99
}
1010

11-
// GetHealth calls the /api/health endpoint.
11+
// GetHealth calls the /v1/health endpoint.
1212
func (c *Client) GetHealth(ctx context.Context) (*HealthResponse, error) {
1313
var resp HealthResponse
14-
if err := c.do(ctx, "GET", "/api/health", nil, &resp); err != nil {
14+
if err := c.do(ctx, "GET", "/v1/health", nil, &resp); err != nil {
1515
return nil, err
1616
}
1717
return &resp, nil

internal/api/migrate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (c *Client) MigrateToCloud(ctx context.Context, cloudKey string) (*MigrateR
3434
"cloudApiKey": cloudKey,
3535
}
3636
var result MigrateResult
37-
if err := c.do(ctx, http.MethodPost, "/api/migrate/export", body, &result); err != nil {
37+
if err := c.do(ctx, http.MethodPost, "/v1/migrate/export", body, &result); err != nil {
3838
return nil, fmt.Errorf("migrating to cloud: %w", err)
3939
}
4040
return &result, nil

internal/api/projects.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type UpdateProjectInput struct {
2727
// ListProjects returns all projects for the authenticated user.
2828
func (c *Client) ListProjects(ctx context.Context) ([]Project, error) {
2929
var projects []Project
30-
if err := c.do(ctx, http.MethodGet, "/api/projects", nil, &projects); err != nil {
30+
if err := c.do(ctx, http.MethodGet, "/v1/projects", nil, &projects); err != nil {
3131
return nil, fmt.Errorf("listing projects: %w", err)
3232
}
3333
return projects, nil
@@ -36,7 +36,7 @@ func (c *Client) ListProjects(ctx context.Context) ([]Project, error) {
3636
// GetProject returns a single project by ID.
3737
func (c *Client) GetProject(ctx context.Context, id string) (*Project, error) {
3838
var project Project
39-
if err := c.do(ctx, http.MethodGet, "/api/projects/"+id, nil, &project); err != nil {
39+
if err := c.do(ctx, http.MethodGet, "/v1/projects/"+id, nil, &project); err != nil {
4040
return nil, fmt.Errorf("getting project: %w", err)
4141
}
4242
return &project, nil
@@ -45,7 +45,7 @@ func (c *Client) GetProject(ctx context.Context, id string) (*Project, error) {
4545
// CreateProject creates a new project.
4646
func (c *Client) CreateProject(ctx context.Context, input CreateProjectInput) (*Project, error) {
4747
var project Project
48-
if err := c.do(ctx, http.MethodPost, "/api/projects", input, &project); err != nil {
48+
if err := c.do(ctx, http.MethodPost, "/v1/projects", input, &project); err != nil {
4949
return nil, fmt.Errorf("creating project: %w", err)
5050
}
5151
return &project, nil
@@ -54,15 +54,15 @@ func (c *Client) CreateProject(ctx context.Context, input CreateProjectInput) (*
5454
// UpdateProject updates an existing project and returns the updated project.
5555
func (c *Client) UpdateProject(ctx context.Context, id string, input UpdateProjectInput) (*Project, error) {
5656
var project Project
57-
if err := c.do(ctx, http.MethodPatch, "/api/projects/"+id, input, &project); err != nil {
57+
if err := c.do(ctx, http.MethodPatch, "/v1/projects/"+id, input, &project); err != nil {
5858
return nil, fmt.Errorf("updating project: %w", err)
5959
}
6060
return &project, nil
6161
}
6262

6363
// DeleteProject deletes a project by ID.
6464
func (c *Client) DeleteProject(ctx context.Context, id string) error {
65-
if err := c.do(ctx, http.MethodDelete, "/api/projects/"+id, nil, nil); err != nil {
65+
if err := c.do(ctx, http.MethodDelete, "/v1/projects/"+id, nil, nil); err != nil {
6666
return fmt.Errorf("deleting project: %w", err)
6767
}
6868
return nil

internal/api/projects_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ func TestListProjects(t *testing.T) {
1313
if r.Method != http.MethodGet {
1414
t.Errorf("method = %q, want GET", r.Method)
1515
}
16-
if r.URL.Path != "/api/projects" {
17-
t.Errorf("path = %q, want /api/projects", r.URL.Path)
16+
if r.URL.Path != "/v1/projects" {
17+
t.Errorf("path = %q, want /v1/projects", r.URL.Path)
1818
}
1919
w.WriteHeader(http.StatusOK)
2020
_ = json.NewEncoder(w).Encode([]Project{
@@ -38,8 +38,8 @@ func TestGetProject(t *testing.T) {
3838
if r.Method != http.MethodGet {
3939
t.Errorf("method = %q, want GET", r.Method)
4040
}
41-
if r.URL.Path != "/api/projects/p1" {
42-
t.Errorf("path = %q, want /api/projects/p1", r.URL.Path)
41+
if r.URL.Path != "/v1/projects/p1" {
42+
t.Errorf("path = %q, want /v1/projects/p1", r.URL.Path)
4343
}
4444
w.WriteHeader(http.StatusOK)
4545
_ = json.NewEncoder(w).Encode(Project{ID: "p1", Name: "Alpha", Slug: "alpha"})
@@ -62,8 +62,8 @@ func TestCreateProject(t *testing.T) {
6262
if r.Method != http.MethodPost {
6363
t.Errorf("method = %q, want POST", r.Method)
6464
}
65-
if r.URL.Path != "/api/projects" {
66-
t.Errorf("path = %q, want /api/projects", r.URL.Path)
65+
if r.URL.Path != "/v1/projects" {
66+
t.Errorf("path = %q, want /v1/projects", r.URL.Path)
6767
}
6868
_ = json.NewDecoder(r.Body).Decode(&gotBody)
6969
w.WriteHeader(http.StatusOK)
@@ -89,8 +89,8 @@ func TestUpdateProject(t *testing.T) {
8989
if r.Method != http.MethodPatch {
9090
t.Errorf("method = %q, want PATCH", r.Method)
9191
}
92-
if r.URL.Path != "/api/projects/p1" {
93-
t.Errorf("path = %q, want /api/projects/p1", r.URL.Path)
92+
if r.URL.Path != "/v1/projects/p1" {
93+
t.Errorf("path = %q, want /v1/projects/p1", r.URL.Path)
9494
}
9595
w.WriteHeader(http.StatusOK)
9696
_ = json.NewEncoder(w).Encode(Project{ID: "p1", Name: "Renamed", Slug: "alpha"})
@@ -113,8 +113,8 @@ func TestDeleteProject(t *testing.T) {
113113
if r.Method != http.MethodDelete {
114114
t.Errorf("method = %q, want DELETE", r.Method)
115115
}
116-
if r.URL.Path != "/api/projects/p1" {
117-
t.Errorf("path = %q, want /api/projects/p1", r.URL.Path)
116+
if r.URL.Path != "/v1/projects/p1" {
117+
t.Errorf("path = %q, want /v1/projects/p1", r.URL.Path)
118118
}
119119
w.WriteHeader(http.StatusNoContent)
120120
}))

internal/api/rules.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ type UpdateRuleInput struct {
5050
// ListRules returns all policy rules for the authenticated user.
5151
// If projectID is non-empty, results are scoped to that project.
5252
func (c *Client) ListRules(ctx context.Context, projectID string) ([]Rule, error) {
53-
path := withProjectQuery("/api/rules", projectID)
53+
path := withProjectQuery("/v1/rules", projectID)
5454
var rules []Rule
5555
if err := c.do(ctx, http.MethodGet, path, nil, &rules); err != nil {
5656
return nil, fmt.Errorf("listing rules: %w", err)
@@ -61,7 +61,7 @@ func (c *Client) ListRules(ctx context.Context, projectID string) ([]Rule, error
6161
// GetRule returns a single policy rule by ID.
6262
func (c *Client) GetRule(ctx context.Context, id string) (*Rule, error) {
6363
var rule Rule
64-
if err := c.do(ctx, http.MethodGet, "/api/rules/"+id, nil, &rule); err != nil {
64+
if err := c.do(ctx, http.MethodGet, "/v1/rules/"+id, nil, &rule); err != nil {
6565
return nil, fmt.Errorf("getting rule: %w", err)
6666
}
6767
return &rule, nil
@@ -70,7 +70,7 @@ func (c *Client) GetRule(ctx context.Context, id string) (*Rule, error) {
7070
// CreateRule creates a new policy rule.
7171
// If projectID is non-empty, the rule is created in that project.
7272
func (c *Client) CreateRule(ctx context.Context, projectID string, input CreateRuleInput) (*Rule, error) {
73-
path := withProjectQuery("/api/rules", projectID)
73+
path := withProjectQuery("/v1/rules", projectID)
7474
var rule Rule
7575
if err := c.do(ctx, http.MethodPost, path, input, &rule); err != nil {
7676
return nil, fmt.Errorf("creating rule: %w", err)
@@ -81,15 +81,15 @@ func (c *Client) CreateRule(ctx context.Context, projectID string, input CreateR
8181
// UpdateRule updates an existing policy rule and returns the updated rule.
8282
func (c *Client) UpdateRule(ctx context.Context, id string, input UpdateRuleInput) (*Rule, error) {
8383
var rule Rule
84-
if err := c.do(ctx, http.MethodPatch, "/api/rules/"+id, input, &rule); err != nil {
84+
if err := c.do(ctx, http.MethodPatch, "/v1/rules/"+id, input, &rule); err != nil {
8585
return nil, fmt.Errorf("updating rule: %w", err)
8686
}
8787
return &rule, nil
8888
}
8989

9090
// DeleteRule deletes a policy rule by ID.
9191
func (c *Client) DeleteRule(ctx context.Context, id string) error {
92-
if err := c.do(ctx, http.MethodDelete, "/api/rules/"+id, nil, nil); err != nil {
92+
if err := c.do(ctx, http.MethodDelete, "/v1/rules/"+id, nil, nil); err != nil {
9393
return fmt.Errorf("deleting rule: %w", err)
9494
}
9595
return nil

internal/api/run.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
"net/url"
88
)
99

10-
// ContainerConfig is the response from GET /api/container-config.
10+
// ContainerConfig is the response from GET /v1/container-config.
1111
// The server controls all env var names, values, and paths.
1212
type ContainerConfig struct {
1313
Env map[string]string `json:"env"`
@@ -19,7 +19,7 @@ type ContainerConfig struct {
1919
// GetContainerConfig returns gateway configuration for a local agent process.
2020
// agentIdentifier may be empty, in which case the server uses the default agent.
2121
func (c *Client) GetContainerConfig(ctx context.Context, agentIdentifier string) (*ContainerConfig, error) {
22-
path := "/api/container-config"
22+
path := "/v1/container-config"
2323
if agentIdentifier != "" {
2424
q := url.Values{}
2525
q.Set("agent", agentIdentifier)

0 commit comments

Comments
 (0)