Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion cmd/onecli/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
})
}

Expand Down
18 changes: 9 additions & 9 deletions internal/api/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 6 additions & 6 deletions internal/api/apps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -58,23 +58,23 @@ 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
}

// 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
}

// 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
Expand Down
22 changes: 11 additions & 11 deletions internal/api/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions internal/api/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion internal/api/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions internal/api/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -54,15 +54,15 @@ 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
}

// 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
Expand Down
20 changes: 10 additions & 10 deletions internal/api/projects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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"})
Expand All @@ -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)
Expand All @@ -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"})
Expand All @@ -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)
}))
Expand Down
10 changes: 5 additions & 5 deletions internal/api/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -81,15 +81,15 @@ 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
}

// 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
Expand Down
4 changes: 2 additions & 2 deletions internal/api/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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)
Expand Down
Loading
Loading