Documentation
¶
Overview ¶
Package enclave provides an idiomatic Go SDK for EnclaveRunner.
The package wraps the generated OpenAPI transport client and exposes pointer-reduced request/response models, native Go errors, and transparent limit/offset pagination through iterator, channel, and list-all APIs.
Authentication is configured at client construction time and currently uses required basic-auth credentials.
Index ¶
- Variables
- func Collect[T any](seq iter.Seq2[T, error]) ([]T, error)
- type APIError
- type Artifact
- type Client
- func (c *Client) CreatePolicy(ctx context.Context, policy Policy) error
- func (c *Client) CreateResourceGroup(ctx context.Context, name string, endpoints []string) (ResourceGroup, error)
- func (c *Client) CreateRole(ctx context.Context, name string, users []string) (Role, error)
- func (c *Client) CreateTask(ctx context.Context, source string, opts ...CreateTaskOption) (Task, error)
- func (c *Client) CreateUser(ctx context.Context, username string, password string, displayName string, ...) (User, error)
- func (c *Client) DeleteArtifactByHash(ctx context.Context, namespace string, name string, hash string) (Artifact, error)
- func (c *Client) DeleteArtifactByTag(ctx context.Context, namespace string, name string, tag string) (Artifact, error)
- func (c *Client) DeleteMe(ctx context.Context) (User, error)
- func (c *Client) DeletePolicy(ctx context.Context, policy Policy) error
- func (c *Client) DeleteResourceGroup(ctx context.Context, name string) (ResourceGroup, error)
- func (c *Client) DeleteRole(ctx context.Context, name string) (Role, error)
- func (c *Client) DeleteUser(ctx context.Context, username string) (User, error)
- func (c *Client) DownloadArtifactByHash(ctx context.Context, namespace string, name string, hash string) (io.ReadCloser, error)
- func (c *Client) DownloadArtifactByTag(ctx context.Context, namespace string, name string, tag string) (io.ReadCloser, error)
- func (c *Client) GetArtifactByHash(ctx context.Context, namespace string, name string, hash string) (Artifact, error)
- func (c *Client) GetArtifactByTag(ctx context.Context, namespace string, name string, tag string) (Artifact, error)
- func (c *Client) GetMe(ctx context.Context) (User, error)
- func (c *Client) GetResourceGroup(ctx context.Context, name string) (ResourceGroup, error)
- func (c *Client) GetRole(ctx context.Context, name string) (Role, error)
- func (c *Client) GetTask(ctx context.Context, id string) (Task, error)
- func (c *Client) GetTaskLogs(ctx context.Context, id string, opts ...TaskLogOption) ([]TaskLog, error)
- func (c *Client) GetUser(ctx context.Context, username string) (User, error)
- func (c *Client) ListArtifactNamespaces(ctx context.Context) iter.Seq2[Artifact, error]
- func (c *Client) ListArtifactVersions(ctx context.Context, namespace string, name string) iter.Seq2[Artifact, error]
- func (c *Client) ListArtifacts(ctx context.Context, namespace string) iter.Seq2[Artifact, error]
- func (c *Client) ListPolicies(ctx context.Context, opts ...ListPoliciesOption) iter.Seq2[Policy, error]
- func (c *Client) ListResourceGroups(ctx context.Context, opts ...ListResourceGroupsOption) iter.Seq2[ResourceGroup, error]
- func (c *Client) ListRoles(ctx context.Context, opts ...ListRolesOption) iter.Seq2[Role, error]
- func (c *Client) ListTasks(ctx context.Context, opts ...ListTasksOption) iter.Seq2[Task, error]
- func (c *Client) ListUsers(ctx context.Context, opts ...ListUsersOption) iter.Seq2[User, error]
- func (c *Client) ResourceGroupExists(ctx context.Context, name string) (bool, error)
- func (c *Client) RoleExists(ctx context.Context, name string) (bool, error)
- func (c *Client) UpdateArtifactTagsByHash(ctx context.Context, namespace string, name string, hash string, tags []string) (Artifact, error)
- func (c *Client) UpdateArtifactTagsByTag(ctx context.Context, namespace string, name string, tag string, tags []string) (Artifact, error)
- func (c *Client) UpdateMe(ctx context.Context, opts ...UpdateUserOption) (User, error)
- func (c *Client) UpdateUser(ctx context.Context, username string, opts ...UpdateUserOption) (User, error)
- func (c *Client) UploadArtifact(ctx context.Context, namespace string, name string, body io.Reader) (UploadResult, error)
- func (c *Client) UserExists(ctx context.Context, username string) (bool, error)
- type CreateTaskOption
- type CreateUserOption
- type EnvironmentVariable
- type ListPoliciesOption
- type ListResourceGroupsOption
- type ListRolesOption
- type ListTasksOption
- type ListUsersOption
- type Policy
- type PolicyMethod
- type ResourceGroup
- type Role
- type Task
- type TaskLog
- type TaskLogOption
- type TaskStatus
- type UpdateUserOption
- type UploadResult
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrBadRequest = errors.New( "bad request", ) ErrUnauthenticated = errors.New( "unauthenticated", ) ErrForbidden = errors.New( "forbidden", ) ErrNotFound = errors.New( "not found", ) ErrConflict = errors.New( "conflict", ) ErrTooLarge = errors.New( "request too large", ) ErrInternal = errors.New( "internal server error", ) )
Sentinel errors for API response status codes.
Functions ¶
Types ¶
type APIError ¶
APIError is a structured error returned by the Enclave API. Use errors.Is to check the underlying sentinel (e.g. errors.Is(err, enclave.ErrNotFound)).
type Artifact ¶
type Artifact struct {
Namespace string
Name string
VersionHash string
CreatedAt time.Time
Pulls int
Tags []string
}
Artifact is metadata for an artifact version.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the Enclave SDK client. Create one with New.
func New ¶
New creates a new Enclave SDK client. Both username and password are required for basic authentication. The serverURL is the base URL of the Enclave API (e.g. "https://enclave.example.com").
func (*Client) CreatePolicy ¶
CreatePolicy creates a new RBAC policy binding a role, resource group, and HTTP method. Success is indicated by a 201 status with no response body.
func (*Client) CreateResourceGroup ¶
func (c *Client) CreateResourceGroup( ctx context.Context, name string, endpoints []string, ) (ResourceGroup, error)
CreateResourceGroup creates a new resource group with the given name and endpoint list.
func (*Client) CreateRole ¶
CreateRole creates a new role with the given name and user assignments.
func (*Client) CreateTask ¶
func (c *Client) CreateTask( ctx context.Context, source string, opts ...CreateTaskOption, ) (Task, error)
CreateTask creates a new task from the given source. Use WithArgs, WithCallback, WithEnv, WithParams, WithRetention, or WithRetries to configure optional fields.
func (*Client) CreateUser ¶
func (c *Client) CreateUser( ctx context.Context, username string, password string, displayName string, opts ...CreateUserOption, ) (User, error)
CreateUser creates a new user with the given username, password, and display name. Use WithRoles to assign roles.
func (*Client) DeleteArtifactByHash ¶
func (c *Client) DeleteArtifactByHash( ctx context.Context, namespace string, name string, hash string, ) (Artifact, error)
DeleteArtifactByHash deletes an artifact version by hash and returns the deleted artifact.
func (*Client) DeleteArtifactByTag ¶
func (c *Client) DeleteArtifactByTag( ctx context.Context, namespace string, name string, tag string, ) (Artifact, error)
DeleteArtifactByTag deletes an artifact version by tag and returns the deleted artifact.
func (*Client) DeleteMe ¶
DeleteMe deletes the currently authenticated user and returns the deleted user.
func (*Client) DeletePolicy ¶
DeletePolicy deletes an RBAC policy. Success is indicated by a 200 status with no response body.
func (*Client) DeleteResourceGroup ¶
DeleteResourceGroup deletes a resource group by name and returns the deleted resource.
func (*Client) DeleteRole ¶
DeleteRole deletes a role by name and returns the deleted role.
func (*Client) DeleteUser ¶
DeleteUser deletes a user by username and returns the deleted user.
func (*Client) DownloadArtifactByHash ¶
func (c *Client) DownloadArtifactByHash( ctx context.Context, namespace string, name string, hash string, ) (io.ReadCloser, error)
DownloadArtifactByHash downloads the raw artifact content by hash. The caller must close the returned io.ReadCloser.
func (*Client) DownloadArtifactByTag ¶
func (c *Client) DownloadArtifactByTag( ctx context.Context, namespace string, name string, tag string, ) (io.ReadCloser, error)
DownloadArtifactByTag downloads the raw artifact content by tag. The caller must close the returned io.ReadCloser.
func (*Client) GetArtifactByHash ¶
func (c *Client) GetArtifactByHash( ctx context.Context, namespace string, name string, hash string, ) (Artifact, error)
GetArtifactByHash retrieves artifact metadata by version hash.
func (*Client) GetArtifactByTag ¶
func (c *Client) GetArtifactByTag( ctx context.Context, namespace string, name string, tag string, ) (Artifact, error)
GetArtifactByTag retrieves artifact metadata by tag.
func (*Client) GetResourceGroup ¶
GetResourceGroup retrieves a single resource group by name.
func (*Client) GetTaskLogs ¶
func (c *Client) GetTaskLogs( ctx context.Context, id string, opts ...TaskLogOption, ) ([]TaskLog, error)
GetTaskLogs retrieves the log entries for a task. Use FilterLogByLevel, FilterLogByIssuer, or FilterLogByTimeRange to narrow results.
func (*Client) ListArtifactNamespaces ¶
ListArtifactNamespaces returns a paginated iterator over all artifact namespaces.
func (*Client) ListArtifactVersions ¶
func (c *Client) ListArtifactVersions( ctx context.Context, namespace string, name string, ) iter.Seq2[Artifact, error]
ListArtifactVersions returns a paginated iterator over all versions of an artifact.
func (*Client) ListArtifacts ¶
ListArtifacts returns a paginated iterator over all artifacts in a namespace.
func (*Client) ListPolicies ¶
func (c *Client) ListPolicies( ctx context.Context, opts ...ListPoliciesOption, ) iter.Seq2[Policy, error]
ListPolicies returns an iterator over all RBAC policies, fetching pages transparently. Use FilterPolicyByRole, FilterPolicyByResourceGroup, or FilterPolicyByMethod to narrow results.
func (*Client) ListResourceGroups ¶
func (c *Client) ListResourceGroups( ctx context.Context, opts ...ListResourceGroupsOption, ) iter.Seq2[ResourceGroup, error]
ListResourceGroups returns an iterator over all resource groups. Use FilterResourceGroupsByRole to narrow results.
func (*Client) ListRoles ¶
ListRoles returns an iterator over all roles, fetching pages transparently. Use FilterByRole to narrow results.
func (*Client) ListTasks ¶
ListTasks returns a paginated iterator over all tasks. Use FilterByState to narrow results.
func (*Client) ListUsers ¶
ListUsers returns a paginated iterator over all users. Use Collect to drain the iterator into a slice.
func (*Client) ResourceGroupExists ¶
ResourceGroupExists checks whether a resource group with the given name exists.
func (*Client) RoleExists ¶
RoleExists checks whether a role with the given name exists. Returns true when the API responds with 200 OK, false for 404.
func (*Client) UpdateArtifactTagsByHash ¶
func (c *Client) UpdateArtifactTagsByHash( ctx context.Context, namespace string, name string, hash string, tags []string, ) (Artifact, error)
UpdateArtifactTagsByHash replaces the tags on the artifact version identified by hash.
func (*Client) UpdateArtifactTagsByTag ¶
func (c *Client) UpdateArtifactTagsByTag( ctx context.Context, namespace string, name string, tag string, tags []string, ) (Artifact, error)
UpdateArtifactTagsByTag replaces the tags on the artifact version identified by tag.
func (*Client) UpdateMe ¶
UpdateMe updates the currently authenticated user. Use WithDisplayName, WithPassword, or WithUserRoles to set fields.
func (*Client) UpdateUser ¶
func (c *Client) UpdateUser( ctx context.Context, username string, opts ...UpdateUserOption, ) (User, error)
UpdateUser updates an existing user by username. Use WithDisplayName, WithPassword, or WithUserRoles to set fields.
type CreateTaskOption ¶
type CreateTaskOption func(*createTaskConfig)
CreateTaskOption configures optional fields when creating a task.
func WithArgs ¶
func WithArgs(args ...string) CreateTaskOption
WithArgs sets the argument list for a task.
func WithCallback ¶
func WithCallback(url string) CreateTaskOption
WithCallback sets the callback URL.
func WithEnv ¶
func WithEnv( env ...EnvironmentVariable, ) CreateTaskOption
WithEnv sets environment variables for a task.
func WithParams ¶
func WithParams(params ...any) CreateTaskOption
WithParams sets the parameters for a task.
func WithRetention ¶
func WithRetention(d string) CreateTaskOption
WithRetention sets the retention duration.
func WithRetries ¶
func WithRetries(n int) CreateTaskOption
WithRetries sets the maximum number of retries.
type CreateUserOption ¶
type CreateUserOption func(*createUserConfig)
CreateUserOption configures optional fields when creating a user.
func WithRoles ¶
func WithRoles(roles ...string) CreateUserOption
WithRoles sets the roles for a new user.
type EnvironmentVariable ¶
EnvironmentVariable is a key-value pair supplied to a task.
type ListPoliciesOption ¶
type ListPoliciesOption func(*listPoliciesConfig)
ListPoliciesOption configures filters for ListPolicies.
func FilterPolicyByMethod ¶
func FilterPolicyByMethod( method string, ) ListPoliciesOption
FilterPolicyByMethod filters policies by HTTP method.
func FilterPolicyByResourceGroup ¶
func FilterPolicyByResourceGroup( rg string, ) ListPoliciesOption
FilterPolicyByResourceGroup filters policies by resource group.
func FilterPolicyByRole ¶
func FilterPolicyByRole( role string, ) ListPoliciesOption
FilterPolicyByRole filters policies by role.
type ListResourceGroupsOption ¶
type ListResourceGroupsOption func( *listResourceGroupsConfig, )
ListResourceGroupsOption configures filters for ListResourceGroups.
func FilterResourceGroupsByRole ¶
func FilterResourceGroupsByRole( role string, ) ListResourceGroupsOption
FilterResourceGroupsByRole filters resource groups by associated role.
type ListRolesOption ¶
type ListRolesOption func(*listRolesConfig)
ListRolesOption configures filters for ListRoles.
func FilterByRole ¶
func FilterByRole(role string) ListRolesOption
FilterByRole filters roles by name.
type ListTasksOption ¶
type ListTasksOption func(*listTasksConfig)
ListTasksOption configures filters for ListTasks.
func FilterByState ¶
func FilterByState(state string) ListTasksOption
FilterByState filters tasks by state.
type ListUsersOption ¶
type ListUsersOption func(*listUsersConfig)
ListUsersOption configures filters for ListUsers.
func FilterByDisplayName ¶
func FilterByDisplayName( name string, ) ListUsersOption
FilterByDisplayName filters users by display name.
func FilterByName ¶
func FilterByName(name string) ListUsersOption
FilterByName filters users by exact username.
type Policy ¶
type Policy struct {
Role string
ResourceGroup string
Method PolicyMethod
}
Policy is an RBAC policy binding a role, resource group, and HTTP method.
type PolicyMethod ¶
type PolicyMethod string
PolicyMethod is the HTTP method in an RBAC policy.
const ( PolicyMethodGet PolicyMethod = "GET" PolicyMethodPost PolicyMethod = "POST" PolicyMethodPut PolicyMethod = "PUT" PolicyMethodPatch PolicyMethod = "PATCH" PolicyMethodDelete PolicyMethod = "DELETE" PolicyMethodHead PolicyMethod = "HEAD" PolicyMethodAll PolicyMethod = "*" )
PolicyMethod constants.
type ResourceGroup ¶
ResourceGroup is a named resource group with its assigned API endpoints.
type Task ¶
type Task struct {
ID string
Source string
Status TaskStatus
Args []string
Callback string
Env []EnvironmentVariable
Params []any
Retention string
Retries int
}
Task is the response model for a task.
type TaskLogOption ¶
type TaskLogOption func(*taskLogConfig)
TaskLogOption configures filters for GetTaskLogs.
func FilterLogByIssuer ¶
func FilterLogByIssuer(issuer string) TaskLogOption
FilterLogByIssuer filters logs by issuer.
func FilterLogByLevel ¶
func FilterLogByLevel(level string) TaskLogOption
FilterLogByLevel filters logs by level.
func FilterLogByTimeRange ¶
func FilterLogByTimeRange( from time.Time, to time.Time, ) TaskLogOption
FilterLogByTimeRange filters logs by time range.
type TaskStatus ¶
type TaskStatus struct {
State string
Retries int
CompletedAt time.Time
LastFailedAt time.Time
NextProcessAt time.Time
LastError string
ResultPayload string
}
TaskStatus holds the execution state of a task.
type UpdateUserOption ¶
type UpdateUserOption func(*updateUserConfig)
UpdateUserOption configures optional fields when updating a user or the current user.
func WithDisplayName ¶
func WithDisplayName( name string, ) UpdateUserOption
WithDisplayName sets the display name.
func WithUserRoles ¶
func WithUserRoles( roles ...string, ) UpdateUserOption
WithUserRoles sets the roles.
type UploadResult ¶
type UploadResult struct {
VersionHash string
}
UploadResult is returned after uploading an artifact.