From 58185687634402108e8c7ac38849c8046d3923d3 Mon Sep 17 00:00:00 2001 From: Guy Ben Aharon Date: Tue, 19 May 2026 18:52:10 +0300 Subject: [PATCH] featmigrate API prefix from /api to /v1 and default to api.onecli.sh --- cmd/onecli/migrate.go | 2 +- internal/api/agents.go | 18 +++++++++--------- internal/api/apps.go | 12 ++++++------ internal/api/client_test.go | 22 +++++++++++----------- internal/api/health.go | 6 +++--- internal/api/migrate.go | 2 +- internal/api/projects.go | 10 +++++----- internal/api/projects_test.go | 20 ++++++++++---------- internal/api/rules.go | 10 +++++----- internal/api/run.go | 4 ++-- internal/api/secrets.go | 8 ++++---- internal/api/skill.go | 2 +- internal/api/user.go | 6 +++--- internal/config/config.go | 2 +- internal/config/config_test.go | 4 ++-- pkg/validate/validate_test.go | 2 +- 16 files changed, 65 insertions(+), 65 deletions(-) diff --git a/cmd/onecli/migrate.go b/cmd/onecli/migrate.go index 79c121e..462f46c 100644 --- a/cmd/onecli/migrate.go +++ b/cmd/onecli/migrate.go @@ -22,7 +22,7 @@ func (c *MigrateCmd) Run(out *output.Writer) error { if c.DryRun { return out.WriteDryRun("Would migrate data to OneCLI Cloud", map[string]string{ "source": config.APIHost(), - "target": "https://app.onecli.sh", + "target": "https://api.onecli.sh", }) } diff --git a/internal/api/agents.go b/internal/api/agents.go index 960d719..373c05c 100644 --- a/internal/api/agents.go +++ b/internal/api/agents.go @@ -51,7 +51,7 @@ type SuccessResponse struct { // ListAgents returns all agents for the authenticated user. // If projectID is non-empty, results are scoped to that project. func (c *Client) ListAgents(ctx context.Context, projectID string) ([]Agent, error) { - path := withProjectQuery("/api/agents", projectID) + path := withProjectQuery("/v1/agents", projectID) var agents []Agent if err := c.do(ctx, http.MethodGet, path, nil, &agents); err != nil { return nil, fmt.Errorf("listing agents: %w", err) @@ -62,7 +62,7 @@ func (c *Client) ListAgents(ctx context.Context, projectID string) ([]Agent, err // GetDefaultAgent returns the user's default agent. func (c *Client) GetDefaultAgent(ctx context.Context) (*Agent, error) { var agent Agent - if err := c.do(ctx, http.MethodGet, "/api/agents/default", nil, &agent); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/agents/default", nil, &agent); err != nil { return nil, fmt.Errorf("getting default agent: %w", err) } return &agent, nil @@ -71,7 +71,7 @@ func (c *Client) GetDefaultAgent(ctx context.Context) (*Agent, error) { // CreateAgent creates a new agent. // If projectID is non-empty, the agent is created in that project. func (c *Client) CreateAgent(ctx context.Context, projectID string, input CreateAgentInput) (*Agent, error) { - path := withProjectQuery("/api/agents", projectID) + path := withProjectQuery("/v1/agents", projectID) var agent Agent if err := c.do(ctx, http.MethodPost, path, input, &agent); err != nil { return nil, fmt.Errorf("creating agent: %w", err) @@ -81,7 +81,7 @@ func (c *Client) CreateAgent(ctx context.Context, projectID string, input Create // DeleteAgent deletes an agent by ID. func (c *Client) DeleteAgent(ctx context.Context, id string) error { - if err := c.do(ctx, http.MethodDelete, "/api/agents/"+id, nil, nil); err != nil { + if err := c.do(ctx, http.MethodDelete, "/v1/agents/"+id, nil, nil); err != nil { return fmt.Errorf("deleting agent: %w", err) } return nil @@ -90,7 +90,7 @@ func (c *Client) DeleteAgent(ctx context.Context, id string) error { // RenameAgent renames an agent. func (c *Client) RenameAgent(ctx context.Context, id string, input RenameAgentInput) error { var resp SuccessResponse - if err := c.do(ctx, http.MethodPatch, "/api/agents/"+id, input, &resp); err != nil { + if err := c.do(ctx, http.MethodPatch, "/v1/agents/"+id, input, &resp); err != nil { return fmt.Errorf("renaming agent: %w", err) } return nil @@ -99,7 +99,7 @@ func (c *Client) RenameAgent(ctx context.Context, id string, input RenameAgentIn // RegenerateAgentToken regenerates an agent's access token. func (c *Client) RegenerateAgentToken(ctx context.Context, id string) (*RegenerateTokenResponse, error) { var resp RegenerateTokenResponse - if err := c.do(ctx, http.MethodPost, "/api/agents/"+id+"/regenerate-token", nil, &resp); err != nil { + if err := c.do(ctx, http.MethodPost, "/v1/agents/"+id+"/regenerate-token", nil, &resp); err != nil { return nil, fmt.Errorf("regenerating agent token: %w", err) } return &resp, nil @@ -108,7 +108,7 @@ func (c *Client) RegenerateAgentToken(ctx context.Context, id string) (*Regenera // GetAgentSecrets returns the secret IDs assigned to an agent. func (c *Client) GetAgentSecrets(ctx context.Context, id string) ([]string, error) { var secretIDs []string - if err := c.do(ctx, http.MethodGet, "/api/agents/"+id+"/secrets", nil, &secretIDs); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/agents/"+id+"/secrets", nil, &secretIDs); err != nil { return nil, fmt.Errorf("getting agent secrets: %w", err) } return secretIDs, nil @@ -117,7 +117,7 @@ func (c *Client) GetAgentSecrets(ctx context.Context, id string) ([]string, erro // SetAgentSecrets replaces an agent's secret assignments. func (c *Client) SetAgentSecrets(ctx context.Context, id string, input SetAgentSecretsInput) error { var resp SuccessResponse - if err := c.do(ctx, http.MethodPut, "/api/agents/"+id+"/secrets", input, &resp); err != nil { + if err := c.do(ctx, http.MethodPut, "/v1/agents/"+id+"/secrets", input, &resp); err != nil { return fmt.Errorf("setting agent secrets: %w", err) } return nil @@ -126,7 +126,7 @@ func (c *Client) SetAgentSecrets(ctx context.Context, id string, input SetAgentS // SetAgentSecretMode updates an agent's secret mode. func (c *Client) SetAgentSecretMode(ctx context.Context, id string, input SetSecretModeInput) error { var resp SuccessResponse - if err := c.do(ctx, http.MethodPatch, "/api/agents/"+id+"/secret-mode", input, &resp); err != nil { + if err := c.do(ctx, http.MethodPatch, "/v1/agents/"+id+"/secret-mode", input, &resp); err != nil { return fmt.Errorf("setting agent secret mode: %w", err) } return nil diff --git a/internal/api/apps.go b/internal/api/apps.go index 15cc74f..ed817ac 100644 --- a/internal/api/apps.go +++ b/internal/api/apps.go @@ -6,7 +6,7 @@ import ( "net/http" ) -// App represents an app from the /api/apps endpoints. +// App represents an app from the /v1/apps endpoints. type App struct { ID string `json:"id"` Name string `json:"name"` @@ -40,7 +40,7 @@ type ConfigAppInput struct { // ListApps returns all apps with their config and connection status. func (c *Client) ListApps(ctx context.Context) ([]App, error) { var apps []App - if err := c.do(ctx, http.MethodGet, "/api/apps", nil, &apps); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/apps", nil, &apps); err != nil { return nil, fmt.Errorf("listing apps: %w", err) } return apps, nil @@ -49,7 +49,7 @@ func (c *Client) ListApps(ctx context.Context) ([]App, error) { // GetApp returns a single app by provider name. func (c *Client) GetApp(ctx context.Context, provider string) (*App, error) { var app App - if err := c.do(ctx, http.MethodGet, "/api/apps/"+provider, nil, &app); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/apps/"+provider, nil, &app); err != nil { return nil, fmt.Errorf("getting app: %w", err) } return &app, nil @@ -58,7 +58,7 @@ func (c *Client) GetApp(ctx context.Context, provider string) (*App, error) { // ConfigureApp saves BYOC credentials for a provider. func (c *Client) ConfigureApp(ctx context.Context, provider string, input ConfigAppInput) error { var resp SuccessResponse - if err := c.do(ctx, http.MethodPost, "/api/apps/"+provider+"/config", input, &resp); err != nil { + if err := c.do(ctx, http.MethodPost, "/v1/apps/"+provider+"/config", input, &resp); err != nil { return fmt.Errorf("configuring app: %w", err) } return nil @@ -66,7 +66,7 @@ func (c *Client) ConfigureApp(ctx context.Context, provider string, input Config // UnconfigureApp removes BYOC credentials for a provider. func (c *Client) UnconfigureApp(ctx context.Context, provider string) error { - if err := c.do(ctx, http.MethodDelete, "/api/apps/"+provider+"/config", nil, nil); err != nil { + if err := c.do(ctx, http.MethodDelete, "/v1/apps/"+provider+"/config", nil, nil); err != nil { return fmt.Errorf("unconfiguring app: %w", err) } return nil @@ -74,7 +74,7 @@ func (c *Client) UnconfigureApp(ctx context.Context, provider string) error { // DisconnectApp removes the OAuth connection for a provider. func (c *Client) DisconnectApp(ctx context.Context, provider string) error { - if err := c.do(ctx, http.MethodDelete, "/api/apps/"+provider+"/connection", nil, nil); err != nil { + if err := c.do(ctx, http.MethodDelete, "/v1/apps/"+provider+"/connection", nil, nil); err != nil { return fmt.Errorf("disconnecting app: %w", err) } return nil diff --git a/internal/api/client_test.go b/internal/api/client_test.go index 6fe8d49..681f0de 100644 --- a/internal/api/client_test.go +++ b/internal/api/client_test.go @@ -239,10 +239,10 @@ func TestDoSendsCorrectPath(t *testing.T) { defer srv.Close() client := New(srv.URL, "") - _ = client.do(context.Background(), http.MethodGet, "/api/agents", nil, nil) + _ = client.do(context.Background(), http.MethodGet, "/v1/agents", nil, nil) - if gotPath != "/api/agents" { - t.Errorf("path = %q, want /api/agents", gotPath) + if gotPath != "/v1/agents" { + t.Errorf("path = %q, want /v1/agents", gotPath) } } @@ -255,27 +255,27 @@ func TestWithProjectQuery(t *testing.T) { }{ { name: "empty project returns path unchanged", - path: "/api/agents", + path: "/v1/agents", projectID: "", - want: "/api/agents", + want: "/v1/agents", }, { name: "appends projectId query param", - path: "/api/agents", + path: "/v1/agents", projectID: "my-project", - want: "/api/agents?projectId=my-project", + want: "/v1/agents?projectId=my-project", }, { name: "preserves existing query params", - path: "/api/agents?foo=bar", + path: "/v1/agents?foo=bar", projectID: "proj", - want: "/api/agents?foo=bar&projectId=proj", + want: "/v1/agents?foo=bar&projectId=proj", }, { name: "encodes special characters", - path: "/api/secrets", + path: "/v1/secrets", projectID: "has space&more", - want: "/api/secrets?projectId=has+space%26more", + want: "/v1/secrets?projectId=has+space%26more", }, } for _, tt := range tests { diff --git a/internal/api/health.go b/internal/api/health.go index 8abfa40..3b9237f 100644 --- a/internal/api/health.go +++ b/internal/api/health.go @@ -2,16 +2,16 @@ package api import "context" -// HealthResponse is the response from /api/health. +// HealthResponse is the response from /v1/health. type HealthResponse struct { Status string `json:"status"` Version string `json:"version"` } -// GetHealth calls the /api/health endpoint. +// GetHealth calls the /v1/health endpoint. func (c *Client) GetHealth(ctx context.Context) (*HealthResponse, error) { var resp HealthResponse - if err := c.do(ctx, "GET", "/api/health", nil, &resp); err != nil { + if err := c.do(ctx, "GET", "/v1/health", nil, &resp); err != nil { return nil, err } return &resp, nil diff --git a/internal/api/migrate.go b/internal/api/migrate.go index 690b29a..3b436bc 100644 --- a/internal/api/migrate.go +++ b/internal/api/migrate.go @@ -34,7 +34,7 @@ func (c *Client) MigrateToCloud(ctx context.Context, cloudKey string) (*MigrateR "cloudApiKey": cloudKey, } var result MigrateResult - if err := c.do(ctx, http.MethodPost, "/api/migrate/export", body, &result); err != nil { + if err := c.do(ctx, http.MethodPost, "/v1/migrate/export", body, &result); err != nil { return nil, fmt.Errorf("migrating to cloud: %w", err) } return &result, nil diff --git a/internal/api/projects.go b/internal/api/projects.go index a003296..b53df18 100644 --- a/internal/api/projects.go +++ b/internal/api/projects.go @@ -27,7 +27,7 @@ type UpdateProjectInput struct { // ListProjects returns all projects for the authenticated user. func (c *Client) ListProjects(ctx context.Context) ([]Project, error) { var projects []Project - if err := c.do(ctx, http.MethodGet, "/api/projects", nil, &projects); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/projects", nil, &projects); err != nil { return nil, fmt.Errorf("listing projects: %w", err) } return projects, nil @@ -36,7 +36,7 @@ func (c *Client) ListProjects(ctx context.Context) ([]Project, error) { // GetProject returns a single project by ID. func (c *Client) GetProject(ctx context.Context, id string) (*Project, error) { var project Project - if err := c.do(ctx, http.MethodGet, "/api/projects/"+id, nil, &project); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/projects/"+id, nil, &project); err != nil { return nil, fmt.Errorf("getting project: %w", err) } return &project, nil @@ -45,7 +45,7 @@ func (c *Client) GetProject(ctx context.Context, id string) (*Project, error) { // CreateProject creates a new project. func (c *Client) CreateProject(ctx context.Context, input CreateProjectInput) (*Project, error) { var project Project - if err := c.do(ctx, http.MethodPost, "/api/projects", input, &project); err != nil { + if err := c.do(ctx, http.MethodPost, "/v1/projects", input, &project); err != nil { return nil, fmt.Errorf("creating project: %w", err) } return &project, nil @@ -54,7 +54,7 @@ func (c *Client) CreateProject(ctx context.Context, input CreateProjectInput) (* // UpdateProject updates an existing project and returns the updated project. func (c *Client) UpdateProject(ctx context.Context, id string, input UpdateProjectInput) (*Project, error) { var project Project - if err := c.do(ctx, http.MethodPatch, "/api/projects/"+id, input, &project); err != nil { + if err := c.do(ctx, http.MethodPatch, "/v1/projects/"+id, input, &project); err != nil { return nil, fmt.Errorf("updating project: %w", err) } return &project, nil @@ -62,7 +62,7 @@ func (c *Client) UpdateProject(ctx context.Context, id string, input UpdateProje // DeleteProject deletes a project by ID. func (c *Client) DeleteProject(ctx context.Context, id string) error { - if err := c.do(ctx, http.MethodDelete, "/api/projects/"+id, nil, nil); err != nil { + if err := c.do(ctx, http.MethodDelete, "/v1/projects/"+id, nil, nil); err != nil { return fmt.Errorf("deleting project: %w", err) } return nil diff --git a/internal/api/projects_test.go b/internal/api/projects_test.go index e2baa5d..e09f643 100644 --- a/internal/api/projects_test.go +++ b/internal/api/projects_test.go @@ -13,8 +13,8 @@ func TestListProjects(t *testing.T) { if r.Method != http.MethodGet { t.Errorf("method = %q, want GET", r.Method) } - if r.URL.Path != "/api/projects" { - t.Errorf("path = %q, want /api/projects", r.URL.Path) + if r.URL.Path != "/v1/projects" { + t.Errorf("path = %q, want /v1/projects", r.URL.Path) } w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode([]Project{ @@ -38,8 +38,8 @@ func TestGetProject(t *testing.T) { if r.Method != http.MethodGet { t.Errorf("method = %q, want GET", r.Method) } - if r.URL.Path != "/api/projects/p1" { - t.Errorf("path = %q, want /api/projects/p1", r.URL.Path) + if r.URL.Path != "/v1/projects/p1" { + t.Errorf("path = %q, want /v1/projects/p1", r.URL.Path) } w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(Project{ID: "p1", Name: "Alpha", Slug: "alpha"}) @@ -62,8 +62,8 @@ func TestCreateProject(t *testing.T) { if r.Method != http.MethodPost { t.Errorf("method = %q, want POST", r.Method) } - if r.URL.Path != "/api/projects" { - t.Errorf("path = %q, want /api/projects", r.URL.Path) + if r.URL.Path != "/v1/projects" { + t.Errorf("path = %q, want /v1/projects", r.URL.Path) } _ = json.NewDecoder(r.Body).Decode(&gotBody) w.WriteHeader(http.StatusOK) @@ -89,8 +89,8 @@ func TestUpdateProject(t *testing.T) { if r.Method != http.MethodPatch { t.Errorf("method = %q, want PATCH", r.Method) } - if r.URL.Path != "/api/projects/p1" { - t.Errorf("path = %q, want /api/projects/p1", r.URL.Path) + if r.URL.Path != "/v1/projects/p1" { + t.Errorf("path = %q, want /v1/projects/p1", r.URL.Path) } w.WriteHeader(http.StatusOK) _ = json.NewEncoder(w).Encode(Project{ID: "p1", Name: "Renamed", Slug: "alpha"}) @@ -113,8 +113,8 @@ func TestDeleteProject(t *testing.T) { if r.Method != http.MethodDelete { t.Errorf("method = %q, want DELETE", r.Method) } - if r.URL.Path != "/api/projects/p1" { - t.Errorf("path = %q, want /api/projects/p1", r.URL.Path) + if r.URL.Path != "/v1/projects/p1" { + t.Errorf("path = %q, want /v1/projects/p1", r.URL.Path) } w.WriteHeader(http.StatusNoContent) })) diff --git a/internal/api/rules.go b/internal/api/rules.go index 5034be3..29a74e4 100644 --- a/internal/api/rules.go +++ b/internal/api/rules.go @@ -50,7 +50,7 @@ type UpdateRuleInput struct { // ListRules returns all policy rules for the authenticated user. // If projectID is non-empty, results are scoped to that project. func (c *Client) ListRules(ctx context.Context, projectID string) ([]Rule, error) { - path := withProjectQuery("/api/rules", projectID) + path := withProjectQuery("/v1/rules", projectID) var rules []Rule if err := c.do(ctx, http.MethodGet, path, nil, &rules); err != nil { return nil, fmt.Errorf("listing rules: %w", err) @@ -61,7 +61,7 @@ func (c *Client) ListRules(ctx context.Context, projectID string) ([]Rule, error // GetRule returns a single policy rule by ID. func (c *Client) GetRule(ctx context.Context, id string) (*Rule, error) { var rule Rule - if err := c.do(ctx, http.MethodGet, "/api/rules/"+id, nil, &rule); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/rules/"+id, nil, &rule); err != nil { return nil, fmt.Errorf("getting rule: %w", err) } return &rule, nil @@ -70,7 +70,7 @@ func (c *Client) GetRule(ctx context.Context, id string) (*Rule, error) { // CreateRule creates a new policy rule. // If projectID is non-empty, the rule is created in that project. func (c *Client) CreateRule(ctx context.Context, projectID string, input CreateRuleInput) (*Rule, error) { - path := withProjectQuery("/api/rules", projectID) + path := withProjectQuery("/v1/rules", projectID) var rule Rule if err := c.do(ctx, http.MethodPost, path, input, &rule); err != nil { return nil, fmt.Errorf("creating rule: %w", err) @@ -81,7 +81,7 @@ func (c *Client) CreateRule(ctx context.Context, projectID string, input CreateR // UpdateRule updates an existing policy rule and returns the updated rule. func (c *Client) UpdateRule(ctx context.Context, id string, input UpdateRuleInput) (*Rule, error) { var rule Rule - if err := c.do(ctx, http.MethodPatch, "/api/rules/"+id, input, &rule); err != nil { + if err := c.do(ctx, http.MethodPatch, "/v1/rules/"+id, input, &rule); err != nil { return nil, fmt.Errorf("updating rule: %w", err) } return &rule, nil @@ -89,7 +89,7 @@ func (c *Client) UpdateRule(ctx context.Context, id string, input UpdateRuleInpu // DeleteRule deletes a policy rule by ID. func (c *Client) DeleteRule(ctx context.Context, id string) error { - if err := c.do(ctx, http.MethodDelete, "/api/rules/"+id, nil, nil); err != nil { + if err := c.do(ctx, http.MethodDelete, "/v1/rules/"+id, nil, nil); err != nil { return fmt.Errorf("deleting rule: %w", err) } return nil diff --git a/internal/api/run.go b/internal/api/run.go index 67803d2..734ea48 100644 --- a/internal/api/run.go +++ b/internal/api/run.go @@ -7,7 +7,7 @@ import ( "net/url" ) -// ContainerConfig is the response from GET /api/container-config. +// ContainerConfig is the response from GET /v1/container-config. // The server controls all env var names, values, and paths. type ContainerConfig struct { Env map[string]string `json:"env"` @@ -19,7 +19,7 @@ type ContainerConfig struct { // GetContainerConfig returns gateway configuration for a local agent process. // agentIdentifier may be empty, in which case the server uses the default agent. func (c *Client) GetContainerConfig(ctx context.Context, agentIdentifier string) (*ContainerConfig, error) { - path := "/api/container-config" + path := "/v1/container-config" if agentIdentifier != "" { q := url.Values{} q.Set("agent", agentIdentifier) diff --git a/internal/api/secrets.go b/internal/api/secrets.go index de8a922..51dba52 100644 --- a/internal/api/secrets.go +++ b/internal/api/secrets.go @@ -50,7 +50,7 @@ type UpdateSecretInput struct { // ListSecrets returns all secrets for the authenticated user. // If projectID is non-empty, results are scoped to that project. func (c *Client) ListSecrets(ctx context.Context, projectID string) ([]Secret, error) { - path := withProjectQuery("/api/secrets", projectID) + path := withProjectQuery("/v1/secrets", projectID) var secrets []Secret if err := c.do(ctx, http.MethodGet, path, nil, &secrets); err != nil { return nil, fmt.Errorf("listing secrets: %w", err) @@ -61,7 +61,7 @@ func (c *Client) ListSecrets(ctx context.Context, projectID string) ([]Secret, e // CreateSecret creates a new secret. // If projectID is non-empty, the secret is created in that project. func (c *Client) CreateSecret(ctx context.Context, projectID string, input CreateSecretInput) (*Secret, error) { - path := withProjectQuery("/api/secrets", projectID) + path := withProjectQuery("/v1/secrets", projectID) var secret Secret if err := c.do(ctx, http.MethodPost, path, input, &secret); err != nil { return nil, fmt.Errorf("creating secret: %w", err) @@ -72,7 +72,7 @@ func (c *Client) CreateSecret(ctx context.Context, projectID string, input Creat // UpdateSecret updates an existing secret. func (c *Client) UpdateSecret(ctx context.Context, id string, input UpdateSecretInput) error { var resp SuccessResponse - if err := c.do(ctx, http.MethodPatch, "/api/secrets/"+id, input, &resp); err != nil { + if err := c.do(ctx, http.MethodPatch, "/v1/secrets/"+id, input, &resp); err != nil { return fmt.Errorf("updating secret: %w", err) } return nil @@ -80,7 +80,7 @@ func (c *Client) UpdateSecret(ctx context.Context, id string, input UpdateSecret // DeleteSecret deletes a secret by ID. func (c *Client) DeleteSecret(ctx context.Context, id string) error { - if err := c.do(ctx, http.MethodDelete, "/api/secrets/"+id, nil, nil); err != nil { + if err := c.do(ctx, http.MethodDelete, "/v1/secrets/"+id, nil, nil); err != nil { return fmt.Errorf("deleting secret: %w", err) } return nil diff --git a/internal/api/skill.go b/internal/api/skill.go index 2494d36..f73593b 100644 --- a/internal/api/skill.go +++ b/internal/api/skill.go @@ -9,7 +9,7 @@ import ( // GetGatewaySkill fetches the gateway skill markdown from the API. func (c *Client) GetGatewaySkill(ctx context.Context) (string, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/api/skill/gateway", nil) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, c.baseURL+"/v1/skill/gateway", nil) if err != nil { return "", fmt.Errorf("creating request: %w", err) } diff --git a/internal/api/user.go b/internal/api/user.go index 666d77b..eac7f83 100644 --- a/internal/api/user.go +++ b/internal/api/user.go @@ -22,7 +22,7 @@ type APIKeyResponse struct { // GetUser returns the authenticated user's profile. func (c *Client) GetUser(ctx context.Context) (*User, error) { var user User - if err := c.do(ctx, http.MethodGet, "/api/user", nil, &user); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/user", nil, &user); err != nil { return nil, fmt.Errorf("getting user: %w", err) } return &user, nil @@ -31,7 +31,7 @@ func (c *Client) GetUser(ctx context.Context) (*User, error) { // GetAPIKey returns the authenticated user's API key. func (c *Client) GetAPIKey(ctx context.Context) (*APIKeyResponse, error) { var resp APIKeyResponse - if err := c.do(ctx, http.MethodGet, "/api/user/api-key", nil, &resp); err != nil { + if err := c.do(ctx, http.MethodGet, "/v1/user/api-key", nil, &resp); err != nil { return nil, fmt.Errorf("getting API key: %w", err) } return &resp, nil @@ -40,7 +40,7 @@ func (c *Client) GetAPIKey(ctx context.Context) (*APIKeyResponse, error) { // RegenerateAPIKey regenerates the authenticated user's API key. func (c *Client) RegenerateAPIKey(ctx context.Context) (*APIKeyResponse, error) { var resp APIKeyResponse - if err := c.do(ctx, http.MethodPost, "/api/user/api-key/regenerate", nil, &resp); err != nil { + if err := c.do(ctx, http.MethodPost, "/v1/user/api-key/regenerate", nil, &resp); err != nil { return nil, fmt.Errorf("regenerating API key: %w", err) } return &resp, nil diff --git a/internal/config/config.go b/internal/config/config.go index c5f4217..48d10e3 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,7 +17,7 @@ const ( envProduction = "production" envDev = "dev" - defaultAPIHost = "https://app.onecli.sh" + defaultAPIHost = "https://api.onecli.sh" keychainServiceProd = "onecli-api-key" keychainServiceDev = "onecli-api-key-dev" diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 2296e64..b1aa52b 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -34,7 +34,7 @@ func TestAPIHostDefault(t *testing.T) { t.Setenv("ONECLI_API_HOST", "") // Env var not set and no config file → default got := APIHost() - if got != "https://app.onecli.sh" { + if got != "https://api.onecli.sh" { t.Errorf("APIHost() = %q, want default", got) } } @@ -214,7 +214,7 @@ func TestGetConfigValueDefaultWhenNoFile(t *testing.T) { if err != nil { t.Fatal(err) } - if val != "https://app.onecli.sh" { + if val != "https://api.onecli.sh" { t.Errorf("got %q, want default", val) } } diff --git a/pkg/validate/validate_test.go b/pkg/validate/validate_test.go index 8d06e0c..952b4d4 100644 --- a/pkg/validate/validate_test.go +++ b/pkg/validate/validate_test.go @@ -67,7 +67,7 @@ func TestURL(t *testing.T) { }{ {name: "https", url: "https://example.com", wantErr: false}, {name: "http", url: "http://localhost:3000", wantErr: false}, - {name: "https with path", url: "https://app.onecli.sh/api/v1", wantErr: false}, + {name: "https with path", url: "https://api.onecli.sh/v1", wantErr: false}, {name: "empty", url: "", wantErr: true}, {name: "ftp scheme", url: "ftp://example.com", wantErr: true}, {name: "no scheme", url: "example.com", wantErr: true},