api

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package api wraps HTTP calls to the DBGorilla backend.

v0.1.0 surface is minimal -- only the endpoints needed for login, identity lookup, and MCP API key management. All requests carry a Bearer token from the keychain when one is present; refresh-on-401 happens automatically via the refresh token if available.

Security notes:

  • When the client is not in insecure mode, the redirect policy refuses to follow a redirect that would downgrade to a non-https URL. This prevents a malicious server from steering a Bearer-bearing request to plaintext (which Go's stdlib already strips Authorization on for cross-host redirects, but a same-host http downgrade would still expose other custom headers).
  • The User-Agent advertises the CLI version so backend abuse-detection and forensic logs can identify the client.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetUserAgentVersion

func SetUserAgentVersion(v string)

SetUserAgentVersion lets cmd inject the build-time version string into the User-Agent header at startup. Safe to call from any goroutine before the first request.

Types

type Client

type Client struct {
	BaseURL    string
	HTTPClient *http.Client
}

Client wraps HTTP calls to the DBGorilla backend API.

func NewClient

func NewClient(baseURL string) *Client

NewClient creates an API client for the given base URL.

func NewInsecureClient

func NewInsecureClient(baseURL string) *Client

NewInsecureClient skips TLS certificate verification. Use only for internal/dev environments with self-signed certs.

func (*Client) Do

func (c *Client) Do(method, path string, body any) ([]byte, int, error)

Do performs an authenticated HTTP request. Returns the response body bytes, status code, and any error.

func (*Client) Get

func (c *Client) Get(path string) ([]byte, int, error)

Get performs an authenticated GET request.

func (*Client) Post

func (c *Client) Post(path string, body any) ([]byte, int, error)

Post performs an authenticated POST request.

type ErrorResponse

type ErrorResponse struct {
	Detail string `json:"detail"`
}

ErrorResponse is the standard FastAPI error response.

type UserInfo

type UserInfo struct {
	Username       string `json:"username"`
	Email          string `json:"email"`
	Tenant         string `json:"tenant"`
	UserID         string `json:"user_id"`
	TenantID       string `json:"tenant_id"`
	IsAdmin        bool   `json:"is_admin"`
	IsSystemTenant bool   `json:"is_system_tenant"`
}

UserInfo matches GET /api/v0_1/auth/user on backend release-202603.007. `tenant` is the organization display name; `tenant_id` is the UUID.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL