Documentation
¶
Index ¶
- Constants
- Variables
- func JSONError(w http.ResponseWriter, err, details any, jobId string, code int)
- func JSONResponse(w http.ResponseWriter, content any, jobId string, code int)
- func ResolveRequestIP(remoteAddr, trustedProxyHeader string, headers http.Header, ...) string
- type APIKey
- type ErrorResponse
- type Grant
- type Keyring
- type Permission
- type Response
- type Role
Constants ¶
const KeyHeader = "x-api-key" // Header for API key
Variables ¶
Functions ¶
func JSONError ¶ added in v0.115.0
func JSONError(w http.ResponseWriter, err, details any, jobId string, code int)
JSONError writes an error response to the client in JSON format.
func JSONResponse ¶ added in v0.115.0
func JSONResponse(w http.ResponseWriter, content any, jobId string, code int)
JSONResponse writes a successful response in the common JSON envelope.
Types ¶
type APIKey ¶ added in v0.134.0
type APIKey struct {
Key string `yaml:"key" json:"-"`
Role Role `yaml:"role,omitempty"`
Permissions []Permission `yaml:"permissions,omitempty"`
}
APIKey binds a credential to a role or an explicit set of permissions.
type ErrorResponse ¶ added in v0.115.0
ErrorResponse inherits from Response and adds an error message.
type Grant ¶ added in v0.134.0
type Grant struct {
Role Role
// contains filtered or unexported fields
}
Grant contains the permissions associated with an authenticated API key.
func (Grant) Allows ¶ added in v0.134.0
func (grant Grant) Allows(required Permission) bool
Allows reports whether the grant contains the required permission.
type Keyring ¶ added in v0.134.0
type Keyring []APIKey
Keyring contains the configured API credentials.
func (Keyring) Authenticate ¶ added in v0.134.0
Authenticate returns the grant associated with the request's API key.
type Permission ¶ added in v0.134.0
type Permission string
Permission identifies an API capability granted to a key.
const ( PermissionHealthRead Permission = "health:read" PermissionJobsRead Permission = "jobs:read" PermissionJobsTrigger Permission = "jobs:trigger" PermissionMirrorsCompact Permission = "mirrors:compact" PermissionPollTrigger Permission = "poll:trigger" PermissionProjectsControl Permission = "projects:control" PermissionProjectsDelete Permission = "projects:delete" PermissionProjectsInspect Permission = "projects:inspect" PermissionRunsRead Permission = "runs:read" PermissionStacksControl Permission = "stacks:control" PermissionStacksDelete Permission = "stacks:delete" PermissionStacksInspect Permission = "stacks:inspect" PermissionSyncWindowsRead Permission = "sync_windows:read" )
type Response ¶ added in v0.115.0
type Response struct {
Content any `json:"content,omitempty"`
JobID string `json:"job_id,omitempty"`
}
Response is the common JSON envelope for successful REST responses.
type Role ¶ added in v0.134.0
type Role string
Role identifies the operations an API key can perform.
func MinimumRole ¶ added in v0.134.0
func MinimumRole(permission Permission) (Role, bool)
MinimumRole returns the least-privileged preset that grants a permission.
func (Role) Allows ¶ added in v0.134.0
func (role Role) Allows(required Permission) bool
Allows reports whether the role grants the required permission.