enclave

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
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

func Collect

func Collect[T any](
	seq iter.Seq2[T, error],
) ([]T, error)

Collect drains an iter.Seq2[T, error] into a slice, stopping at the first error.

Types

type APIError

type APIError struct {
	StatusCode int
	Message    string
	Sentinel   error
}

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)).

func (*APIError) Error

func (e *APIError) Error() string

Error implements the error interface.

func (*APIError) Unwrap

func (e *APIError) Unwrap() error

Unwrap returns the sentinel error.

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

func New(
	serverURL string,
	username string,
	password string,
) (*Client, error)

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

func (c *Client) CreatePolicy(
	ctx context.Context,
	policy Policy,
) error

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

func (c *Client) CreateRole(
	ctx context.Context,
	name string,
	users []string,
) (Role, error)

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

func (c *Client) DeleteMe(
	ctx context.Context,
) (User, error)

DeleteMe deletes the currently authenticated user and returns the deleted user.

func (*Client) DeletePolicy

func (c *Client) DeletePolicy(
	ctx context.Context,
	policy Policy,
) error

DeletePolicy deletes an RBAC policy. Success is indicated by a 200 status with no response body.

func (*Client) DeleteResourceGroup

func (c *Client) DeleteResourceGroup(
	ctx context.Context,
	name string,
) (ResourceGroup, error)

DeleteResourceGroup deletes a resource group by name and returns the deleted resource.

func (*Client) DeleteRole

func (c *Client) DeleteRole(
	ctx context.Context,
	name string,
) (Role, error)

DeleteRole deletes a role by name and returns the deleted role.

func (*Client) DeleteUser

func (c *Client) DeleteUser(
	ctx context.Context,
	username string,
) (User, error)

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) GetMe

func (c *Client) GetMe(
	ctx context.Context,
) (User, error)

GetMe retrieves the currently authenticated user.

func (*Client) GetResourceGroup

func (c *Client) GetResourceGroup(
	ctx context.Context,
	name string,
) (ResourceGroup, error)

GetResourceGroup retrieves a single resource group by name.

func (*Client) GetRole

func (c *Client) GetRole(
	ctx context.Context,
	name string,
) (Role, error)

GetRole retrieves a single role by name.

func (*Client) GetTask

func (c *Client) GetTask(
	ctx context.Context,
	id string,
) (Task, error)

GetTask retrieves a single task by ID.

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) GetUser

func (c *Client) GetUser(
	ctx context.Context,
	username string,
) (User, error)

GetUser retrieves a single user by username.

func (*Client) ListArtifactNamespaces

func (c *Client) ListArtifactNamespaces(
	ctx context.Context,
) iter.Seq2[Artifact, error]

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

func (c *Client) ListArtifacts(
	ctx context.Context,
	namespace string,
) iter.Seq2[Artifact, error]

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

func (c *Client) ListRoles(
	ctx context.Context,
	opts ...ListRolesOption,
) iter.Seq2[Role, error]

ListRoles returns an iterator over all roles, fetching pages transparently. Use FilterByRole to narrow results.

func (*Client) ListTasks

func (c *Client) ListTasks(
	ctx context.Context,
	opts ...ListTasksOption,
) iter.Seq2[Task, error]

ListTasks returns a paginated iterator over all tasks. Use FilterByState to narrow results.

func (*Client) ListUsers

func (c *Client) ListUsers(
	ctx context.Context,
	opts ...ListUsersOption,
) iter.Seq2[User, error]

ListUsers returns a paginated iterator over all users. Use Collect to drain the iterator into a slice.

func (*Client) ResourceGroupExists

func (c *Client) ResourceGroupExists(
	ctx context.Context,
	name string,
) (bool, error)

ResourceGroupExists checks whether a resource group with the given name exists.

func (*Client) RoleExists

func (c *Client) RoleExists(
	ctx context.Context,
	name string,
) (bool, error)

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

func (c *Client) UpdateMe(
	ctx context.Context,
	opts ...UpdateUserOption,
) (User, error)

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.

func (*Client) UploadArtifact

func (c *Client) UploadArtifact(
	ctx context.Context,
	namespace string,
	name string,
	body io.Reader,
) (UploadResult, error)

UploadArtifact uploads an artifact and returns the resulting version hash.

func (*Client) UserExists

func (c *Client) UserExists(
	ctx context.Context,
	username string,
) (bool, error)

UserExists checks whether a user with the given username exists. Returns (true, nil) for 200, (false, nil) for 404, and an error otherwise.

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

type EnvironmentVariable struct {
	Key   string
	Value string
}

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

type ResourceGroup struct {
	Name      string
	Endpoints []string
}

ResourceGroup is a named resource group with its assigned API endpoints.

type Role

type Role struct {
	Name  string
	Users []string
}

Role is a named role with its assigned users.

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 TaskLog

type TaskLog struct {
	Timestamp time.Time
	Level     string
	Issuer    string
	Message   string
}

TaskLog is a single log entry 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 WithPassword

func WithPassword(pw string) UpdateUserOption

WithPassword sets the password.

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.

type User

type User struct {
	Name        string
	DisplayName string
	Roles       []string
}

User is the response model for a user.

Jump to

Keyboard shortcuts

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