Documentation
¶
Overview ¶
Package client is a typed Go client for the aptly REST API.
It decodes aptly's JSON error envelope into friendly errors, supports optional HTTP Basic auth that is triggered only when the server answers 401, and wraps aptly's asynchronous task API for live progress reporting.
Index ¶
- Constants
- func TaskError(task *Task, output string) error
- type APIError
- type Client
- func (c *Client) AddPackagesFromDir(repo, dir string) (*Task, error)
- func (c *Client) BaseURL() string
- func (c *Client) CreateRepo(req CreateRepoRequest) (*Repo, error)
- func (c *Client) DeleteRepo(name string, force bool) error
- func (c *Client) DeleteUploadDir(dir string) error
- func (c *Client) EditRepo(name string, req EditRepoRequest) (*Repo, error)
- func (c *Client) GetTask(id int) (*Task, error)
- func (c *Client) ListPublished() ([]PublishedRepo, error)
- func (c *Client) ListRepos() ([]Repo, error)
- func (c *Client) ListTasks() ([]Task, error)
- func (c *Client) ListUploadDirs() ([]string, error)
- func (c *Client) ListUploadedFiles(dir string) ([]string, error)
- func (c *Client) RepoPackages(name, query string) ([]string, error)
- func (c *Client) ShowPackage(key string) (map[string]any, error)
- func (c *Client) ShowRepo(name string) (*Repo, error)
- func (c *Client) StreamTask(id int, onChunk func(string)) (*Task, error)
- func (c *Client) TaskOutput(id int) (string, error)
- func (c *Client) UpdatePublished(prefix, distribution string, req UpdatePublishRequest) (*Task, error)
- func (c *Client) UploadFiles(dir string, paths []string) ([]string, error)
- func (c *Client) Version() (*Version, error)
- func (c *Client) WaitTask(id int) (*Task, error)
- type CreateRepoRequest
- type EditRepoRequest
- type Options
- type Prompter
- type PublishedRepo
- type PublishedSource
- type Repo
- type Signing
- type Task
- type TerminalPrompter
- type UpdatePublishRequest
- type Version
Constants ¶
const ( TaskInit = iota TaskRunning TaskSucceeded TaskFailed )
Task states reported by aptly.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to a single aptly API server.
func (*Client) AddPackagesFromDir ¶
AddPackagesFromDir adds previously uploaded files (in upload dir) to a repository asynchronously, returning the task to wait on.
func (*Client) CreateRepo ¶
func (c *Client) CreateRepo(req CreateRepoRequest) (*Repo, error)
CreateRepo creates a new local repository.
func (*Client) DeleteRepo ¶
DeleteRepo removes a local repository. When force is true, it is removed even if referenced by published repositories or snapshots.
func (*Client) DeleteUploadDir ¶
DeleteUploadDir removes an upload directory and its contents.
func (*Client) EditRepo ¶
func (c *Client) EditRepo(name string, req EditRepoRequest) (*Repo, error)
EditRepo updates a local repository's configuration.
func (*Client) ListPublished ¶
func (c *Client) ListPublished() ([]PublishedRepo, error)
ListPublished returns all published repositories.
func (*Client) ListUploadDirs ¶
ListUploadDirs lists the existing upload directories.
func (*Client) ListUploadedFiles ¶
ListUploadedFiles lists files within an upload directory.
func (*Client) RepoPackages ¶
RepoPackages lists package keys in a repository, optionally filtered by an aptly query (e.g. `nginx (>= 1.20)`).
func (*Client) ShowPackage ¶
ShowPackage returns the raw detail map for a package key (e.g. "Pamd64 nginx 1.20.1-1 abc..."). The shape varies by package, so it is returned as a generic map.
func (*Client) StreamTask ¶
StreamTask polls a task until completion, invoking onChunk with each newly appended slice of output for live progress. It returns the final task state.
func (*Client) TaskOutput ¶
TaskOutput returns the accumulated output text of a task.
func (*Client) UpdatePublished ¶
func (c *Client) UpdatePublished(prefix, distribution string, req UpdatePublishRequest) (*Task, error)
UpdatePublished re-publishes a (prefix, distribution) publication asynchronously, returning the task to wait on. Used after adding packages to a local repo so the changes go live.
func (*Client) UploadFiles ¶
UploadFiles uploads local package files into the named upload directory, returning the server-side file list.
type CreateRepoRequest ¶
type CreateRepoRequest struct {
Name string `json:"Name"`
Comment string `json:"Comment,omitempty"`
DefaultDistribution string `json:"DefaultDistribution,omitempty"`
DefaultComponent string `json:"DefaultComponent,omitempty"`
}
CreateRepoRequest is the body for POST /api/repos.
type EditRepoRequest ¶
type EditRepoRequest struct {
Comment string `json:"Comment,omitempty"`
DefaultDistribution string `json:"DefaultDistribution,omitempty"`
DefaultComponent string `json:"DefaultComponent,omitempty"`
}
EditRepoRequest is the body for PUT /api/repos/:name.
type Options ¶
type Options struct {
BaseURL string
User string
Password string
HasAuth bool // true when a password was supplied up front
Insecure bool
Timeout time.Duration
Prompt Prompter // used on 401 when no credentials are known
}
Options configures a Client.
type Prompter ¶
type Prompter interface {
// Credentials returns the username and password to authenticate with.
// defaultUser is the configured user (may be empty).
Credentials(realm, defaultUser string) (user, pass string, err error)
}
Prompter supplies Basic-auth credentials when the server issues a 401 challenge and none were preconfigured.
type PublishedRepo ¶
type PublishedRepo struct {
Storage string `json:"Storage"`
Prefix string `json:"Prefix"`
Distribution string `json:"Distribution"`
SourceKind string `json:"SourceKind"`
Sources []PublishedSource `json:"Sources"`
Architectures []string `json:"Architectures"`
Label string `json:"Label"`
Origin string `json:"Origin"`
}
PublishedRepo is an entry from GET /api/publish.
type PublishedSource ¶
PublishedSource is a component/source pair within a publication.
type Repo ¶
type Repo struct {
Name string `json:"Name"`
Comment string `json:"Comment"`
DefaultDistribution string `json:"DefaultDistribution"`
DefaultComponent string `json:"DefaultComponent"`
}
Repo is a local repository (GET /api/repos).
type Signing ¶
type Signing struct {
Skip bool `json:"Skip,omitempty"`
GpgKey string `json:"GpgKey,omitempty"`
Keyring string `json:"Keyring,omitempty"`
Passphrase string `json:"Passphrase,omitempty"`
Batch bool `json:"Batch,omitempty"`
}
Signing controls GPG signing options on publish operations.
type Task ¶
Task is an asynchronous aptly task (returned when ?_async=1 is used).
func (Task) StateString ¶
StateString renders a task state as a human label.
type TerminalPrompter ¶
type TerminalPrompter struct{}
TerminalPrompter reads credentials interactively from the controlling terminal, reading the password without echo.
func (TerminalPrompter) Credentials ¶
func (TerminalPrompter) Credentials(realm, defaultUser string) (string, string, error)
Credentials implements Prompter against the terminal. It fails clearly when no interactive terminal is attached (e.g. in scripts or --json runs) rather than blocking.
type UpdatePublishRequest ¶
type UpdatePublishRequest struct {
Signing Signing `json:"Signing"`
ForceOverwrite bool `json:"ForceOverwrite,omitempty"`
}
UpdatePublishRequest is the body for PUT /api/publish/:prefix/:distribution.