apikeyep

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Aug 27, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeySvcConfig

type APIKeySvcConfig struct {
	// AuthClient (required) is the auth-service gRPC client.
	AuthClient pb.AuthServiceClient
}

type CreateAPIKeyEndpoint

type CreateAPIKeyEndpoint struct{}

Creates an [API key](https://docs.openmrp.ai/api/api-keys) to authenticate API requests.

The key belongs to the account it was created under and only ever acts on behalf of that account. Keys created under a sandbox account carry an `mrp_sk_test_` prefix; keys created under a production account carry an `mrp_sk_prod_` prefix.

The secret key is returned once and cannot be retrieved later, so you should store it securely. We provide some [recommendations](https://docs.openmrp.ai/api/managing-api-keys) on how you can manage your API keys.

func (*CreateAPIKeyEndpoint) Materialize

type CreateAPIKeyRequest

type CreateAPIKeyRequest struct {
	// ID of the role to assign to the API key.
	//
	// The role determines what requests authenticated with the key are allowed to do. A key keeps its role for life — including through rotation — so issue a new key to use a different one, while changes to the role's own permissions take effect for existing keys immediately.
	RoleID string `json:"role_id" validate:"required"`
	// Human-readable name for the API key.
	//
	// Shown when listing keys and used to match keys when searching, so prefer something that identifies the integration using it.
	Name string `json:"name" validate:"required,max=255"`
	// When the key expires and stops authenticating requests.
	//
	// If omitted, the key keeps working until it is revoked or rotated.
	ExpiresAt field.Optional[time.Time] `json:"expires_at,omitzero"`
}

Request to create an API key.

func (*CreateAPIKeyRequest) SchemaExample

func (*CreateAPIKeyRequest) SchemaExample() any

type GetDocAPIKeyEndpoint

type GetDocAPIKeyEndpoint struct{}

Returns the sandbox API key used to try requests from the API documentation.

Reuses the existing documentation key if it is still valid, rotates it if it has expired, and creates one if none exists. If the key was explicitly revoked, returns an error instead of regenerating it, on the assumption that the revocation was deliberate.

The caller must be signed in as a member of the account they are targeting, and that account must be in sandbox mode; API-key authentication and production accounts are rejected.

type ListAPIKeysEndpoint

type ListAPIKeysEndpoint struct{}

Returns a paginated list of [API keys](https://docs.openmrp.ai/api/api-keys), newest first.

Only keys belonging to the account making the request are returned. The search term matches against the key name.

type ListAPIKeysRequest

type ListAPIKeysRequest struct {
	apiresource.PaginationRequest
	// API key statuses to filter by.
	//
	// - `active`: the key still authenticates requests. A key whose revocation is scheduled for a future time is still active until that time arrives.
	// - `expired`: the key passed its expiration time without having been revoked.
	// - `revoked`: the key was revoked, which takes precedence over expiration.
	//
	// When omitted, keys of every status are returned.
	Statuses []constants.APIKeyStatus `query:"statuses" default:"active,expired,revoked"`
}

Request to list API keys.

type RetrieveAPIKeyEndpoint

type RetrieveAPIKeyEndpoint struct{}

Returns [API key](https://docs.openmrp.ai/api/api-keys) metadata by ID.

Only the redacted key value is returned. The full secret is available only in the response that issued the key, so a lost secret must be replaced by rotating the key.

func (*RetrieveAPIKeyEndpoint) Materialize

type RetrieveAPIKeyRequest

type RetrieveAPIKeyRequest struct {
	// API key ID.
	APIKeyID string `path:"id" validate:"required"`
}

Request to get an API key by ID.

type RevokeAPIKeyEndpoint

type RevokeAPIKeyEndpoint struct{}

Revokes an [API key](https://docs.openmrp.ai/api/api-keys).

Revocation takes effect immediately and cannot be undone; any request still presenting the key is rejected. The key record is kept, so it stays visible in the key list with a `revoked` status. To replace a key without an interruption in access, use Rotate API Key instead.

func (*RevokeAPIKeyEndpoint) Materialize

type RevokeAPIKeyRequest

type RevokeAPIKeyRequest struct {
	// API key ID.
	APIKeyID string `path:"id" validate:"required"`
}

Request to revoke an API key.

type RotateAPIKeyEndpoint

type RotateAPIKeyEndpoint struct{}

Rotates an [API key](https://docs.openmrp.ai/api/api-keys) by revoking the existing key and issuing a replacement with the same name, role, and expiration (unless overridden).

The replacement is a new key with its own ID; the rotated key keeps its ID and stays in the list, moving to a `revoked` status once its revocation takes effect. Use `revoke_at` to keep the old key working while you roll the new secret out.

The secret key is returned once and cannot be retrieved later, so you should store it securely. We provide some [recommendations](https://docs.openmrp.ai/api/managing-api-keys) on how you can manage your API keys.

func (*RotateAPIKeyEndpoint) Materialize

type RotateAPIKeyRequest

type RotateAPIKeyRequest struct {
	// ID of the API key to rotate.
	//
	// The key must not already be revoked.
	APIKeyID string `path:"id" validate:"required"`
	// When the replacement key should expire.
	//
	// If omitted, the replacement inherits the expiration of the key being rotated.
	ExpiresAt field.Optional[time.Time] `json:"expires_at,omitzero"`
	// When the old key should stop authenticating requests.
	//
	// If omitted, the old key is revoked immediately. Set a future timestamp — up to 30 days out — to keep the old key working during a migration window; a timestamp in the past revokes it immediately.
	RevokeAt field.Optional[time.Time] `json:"revoke_at,omitzero" validate:"omitempty,max_days_ahead=30"`
}

Request to rotate an API key.

func (*RotateAPIKeyRequest) SchemaExample

func (*RotateAPIKeyRequest) SchemaExample() any

Jump to

Keyboard shortcuts

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