Documentation ¶
Overview ¶
Package acl provides functionality for managing API keys with access control lists (ACL).
The ACL service allows creating, listing, fetching, updating, and deleting API keys. It includes methods for various operations such as listing all API keys, retrieving the current API key, fetching an API key by ID, creating a new API key, updating an existing API key, and deleting an API key.
The ACL service utilizes the zenrpc package for JSON-RPC 2.0 API documentation and routing. It also integrates with middleware for authentication and rate limiting.
Index ¶
- Variables
- func RegisterAuthCallback(n *Namespace) error
- func RegisterCreateKeyHandler(n *Namespace) error
- func RegisterDeleteKeyHandler(n *Namespace) error
- func RegisterGetCurrentKeyHandler(n *Namespace) error
- func RegisterGetKeyHandler(n *Namespace) error
- func RegisterListKeysHandler(n *Namespace) error
- func RegisterService(ctx *cli.Context, baseService service.Service) (service.Service, error)
- func RegisterUpdateKeyHandler(n *Namespace) error
- type AuthCallback
- type InputCreateKey
- type InputDeleteKey
- type InputGetKey
- type InputListKeys
- type InputUpdateKey
- type Key
- type Namespace
- type RpcService
- func (s RpcService) Callback(ctx context.Context, payload User) (*AuthCallback, *zenrpc.Error)
- func (s RpcService) CreateKey(ctx context.Context, profileId string, label string, roles []string, ...) (*Key, *zenrpc.Error)
- func (s RpcService) DeleteKey(ctx context.Context, id *uuid.UUID) (*Key, *zenrpc.Error)
- func (s RpcService) GetCurrentKey(ctx context.Context) (*Key, *zenrpc.Error)
- func (s RpcService) GetKey(ctx context.Context, id uuid.UUID) (*Key, *zenrpc.Error)
- func (s RpcService) Invoke(ctx context.Context, w http.ResponseWriter, method string, ...) zenrpc.Response
- func (s RpcService) ListKeys(ctx context.Context, limit int) ([]*Key, *zenrpc.Error)
- func (RpcService) SMD() smd.ServiceInfo
- func (s RpcService) UpdateKey(ctx context.Context, id *uuid.UUID, label string, roles []string, ...) (*Key, *zenrpc.Error)
- type Service
- type User
Constants ¶
This section is empty.
Variables ¶
var AclServiceName rest.ServiceName = "acl"
AclServiceName defines the service name for the Acl service.
var RPC = struct { RpcService struct{ ListKeys, GetCurrentKey, GetKey, CreateKey, UpdateKey, DeleteKey, Callback string } }{ RpcService: struct{ ListKeys, GetCurrentKey, GetKey, CreateKey, UpdateKey, DeleteKey, Callback string }{ ListKeys: "listkeys", GetCurrentKey: "getcurrentkey", GetKey: "getkey", CreateKey: "createkey", UpdateKey: "updatekey", DeleteKey: "deletekey", Callback: "callback", }, }
Functions ¶
func RegisterAuthCallback ¶ added in v0.9.7
RegisterAuthCallback registers the endpoint for the authentication callback. This endpoint handles the authentication callback to register or retrieve API keys.
func RegisterCreateKeyHandler ¶ added in v0.9.7
RegisterCreateKeyHandler registers the endpoint to create a new API key
func RegisterDeleteKeyHandler ¶ added in v0.9.7
RegisterDeleteKeyHandler registers the endpoint to delete an API key by ID
func RegisterGetCurrentKeyHandler ¶ added in v0.9.7
RegisterGetCurrentKeyHandler registers the endpoint to get the current API key
func RegisterGetKeyHandler ¶ added in v0.9.7
RegisterGetKeyHandler registers the endpoint to get an API key by ID
func RegisterListKeysHandler ¶ added in v0.9.7
RegisterListKeysHandler registers the endpoint to list API keys
func RegisterService ¶
RegisterService registers the ACL service with the provided CLI context and base service.
It initializes a new ACL service instance and returns it as a service.Service interface.
func RegisterUpdateKeyHandler ¶ added in v0.9.7
RegisterUpdateKeyHandler registers the endpoint to update an existing API key
Types ¶
type AuthCallback ¶
type AuthCallback struct { // Registered indicates whether the user is registered. Registered bool `json:"registered" doc:"Indicates whether the user is registered"` // User represents the user associated with the authentication callback. User *User `json:"user" doc:"User associated with the authentication callback"` // Key represents the API key associated with the user. Key *Key `json:"key" doc:"API key associated with the user"` }
AuthCallback represents the callback response after authentication.
type InputCreateKey ¶ added in v0.9.7
type InputCreateKey struct { ProfileID string `json:"profileId" query:"profileId" doc:"Profile ID"` Label string `json:"label" query:"label" doc:"Label"` Roles []string `json:"roles" query:"roles" doc:"Roles"` RateLimit int32 `json:"rateLimit" query:"rateLimit" doc:"Rate limit"` RateLimitDuration string `json:"rateLimitDuration" query:"rateLimitDuration" doc:"Rate limit duration"` Enabled bool `json:"enabled" query:"enabled" doc:"Enabled"` }
InputCreateKey represents the input parameters required for the CreateKey handler.
type InputDeleteKey ¶ added in v0.9.7
InputDeleteKey represents the input parameters required for the DeleteKey handler.
type InputGetKey ¶ added in v0.9.7
InputGetKey represents the input parameters required for the GetKey handler.
type InputListKeys ¶ added in v0.9.7
type InputListKeys struct {
Limit int `query:"limit" doc:"Limit for the number of keys to return"`
}
InputListKeys represents the input parameters required for the ListKeys handler.
type InputUpdateKey ¶ added in v0.9.7
type InputUpdateKey struct { ID uuid.UUID `json:"id" path:"id" doc:"API key ID"` Label string `json:"label" query:"label" doc:"Label"` Roles []string `json:"roles" query:"roles" doc:"Roles"` RateLimit int32 `json:"rateLimit" query:"rateLimit" doc:"Rate limit"` RateLimitDuration string `json:"rateLimitDuration" query:"rateLimitDuration" doc:"Rate limit duration"` Enabled bool `json:"enabled" query:"enabled" doc:"Enabled"` Suspended bool `json:"suspended" query:"suspended" doc:"Suspended"` }
InputUpdateKey represents the input parameters required for the UpdateKey handler.
type Key ¶
type Key struct { // Id represents the unique identifier of the API key. Id uuid.UUID `json:"id" doc:"Unique identifier of the API key"` // ProfileId represents reference identifier to the user id. ProfileId string `json:"profileId" doc:"Reference identifier to the user id"` // Label represents the label or name assigned to the API key. Label string `json:"label" doc:"Label or name assigned to the API key"` // Key represents the actual API key string. Key string `json:"key" doc:"The actual API key string"` // Roles represents the roles associated with the API key. Roles []string `json:"roles" doc:"Roles associated with the API key"` // RateLimit represents the rate limit applied to the API key. RateLimit int32 `json:"rateLimit" doc:"Rate limit applied to the API key"` // RateLimitDuration represents the duration of the rate limit (e.g., second, minute, hour). RateLimitDuration string `json:"rateLimitDuration" doc:"Duration of the rate limit (e.g., second, minute, hour)"` // Enabled indicates whether the API key is enabled. Enabled bool `json:"enabled" doc:"Indicates whether the API key is enabled"` // Suspended indicates whether the API key is suspended. Suspended bool `json:"suspended" doc:"Indicates whether the API key is suspended"` // CreatedAt represents the creation timestamp of the API key. CreatedAt time.Time `json:"createdAt" doc:"Creation timestamp of the API key"` // UpdatedAt represents the last update timestamp of the API key. UpdatedAt time.Time `json:"updatedAt" doc:"Last update timestamp of the API key"` }
Key struct represents an API key with associated metadata.
type Namespace ¶ added in v0.9.7
Namespace represents a service namespace containing configuration and dependencies for the Accounts service.
func NewNamespace ¶ added in v0.9.7
func NewNamespace(server *rest.Server, db db.Adapter, pool *clients.ClientPool, nats *nats.Conn, cache *cache.Redis) *Namespace
NewNamespace creates a new instance of Namespace with the provided server, database adapter, client pool, NATS connection, and Redis cache.
func (*Namespace) GetName ¶ added in v0.9.7
func (s *Namespace) GetName() rest.ServiceName
GetName returns the service name for the Accounts namespace.
func (*Namespace) RegisterHandlers ¶ added in v0.9.7
RegisterHandlers registers all the necessary handlers for the Accounts namespace.
type RpcService ¶
type RpcService struct { zenrpc.Service // Embeds the zenrpc.Service for JSON-RPC functionality. // contains filtered or unexported fields }
RpcService struct represents the RPC service for ACL operations.
func (RpcService) Callback ¶
func (s RpcService) Callback(ctx context.Context, payload User) (*AuthCallback, *zenrpc.Error)
func (RpcService) CreateKey ¶
func (s RpcService) CreateKey(ctx context.Context, profileId string, label string, roles []string, rateLimit int32, rateLimitDuration string, enabled *bool) (*Key, *zenrpc.Error)
CreateKey creates a new API key.
In case the ACL service is not started, the API key won't be available. Make sure to start the module if ACL support is required.
func (RpcService) DeleteKey ¶
DeleteKey deletes an API key by ID.
In case the ACL service is not started, API key won't be available. Make sure to start the module if ACL support is required.
func (RpcService) GetCurrentKey ¶
func (s RpcService) GetCurrentKey(ctx context.Context) (*Key, *zenrpc.Error)
GetCurrentKey returns the current API key.
In case the ACL service is not started, API key won't be available. Make sure to start the module if ACL support is required.
func (RpcService) GetKey ¶
GetKey returns an API key by ID.
In case the ACL service is not started, an API key won't be available. Make sure to start the module if ACL support is required.
func (RpcService) Invoke ¶
func (s RpcService) Invoke(ctx context.Context, w http.ResponseWriter, method string, params json.RawMessage) zenrpc.Response
Invoke is as generated code from zenrpc cmd
func (RpcService) ListKeys ¶
func (s RpcService) ListKeys(ctx context.Context, limit int) ([]*Key, *zenrpc.Error)
ListKeys returns a list of API keys with optional limit.
In case the ACL service is not started, API keys won't be available. Make sure to start the module if ACL support is required.
func (RpcService) SMD ¶
func (RpcService) SMD() smd.ServiceInfo
func (RpcService) UpdateKey ¶
func (s RpcService) UpdateKey(ctx context.Context, id *uuid.UUID, label string, roles []string, rateLimit int32, rateLimitDuration string, enabled *bool, suspended *bool) (*Key, *zenrpc.Error)
UpdateKey updates an existing API key.
In case the ACL service is not started, the API key won't be available. Make sure to start the module if ACL support is required.
type Service ¶
type Service struct { *service.BaseService // contains filtered or unexported fields }
Service represents the ACL service for managing access control lists.
func NewService ¶
func NewService(ctx *cli.Context, baseService *service.BaseService) (*Service, error)
NewService creates a new instance of the ACL service.
It initializes the service with the provided CLI context and base service. The ACL service registers GRPC server ACL middleware and namespaces for RPC.
func (*Service) Dependencies ¶
func (s *Service) Dependencies() map[service.DependencyName]service.Option
Dependencies returns the dependencies required by the ACL service.
func (*Service) RegisterRestNamespaces ¶ added in v0.9.7
RegisterRestNamespaces registers REST namespaces for the ACL service.
func (*Service) RegisterRpcNamespaces ¶ added in v0.9.7
RegisterRpcNamespaces registers RPC namespaces for the ACL service.
It registers the "acl" namespace with the RpcService instance.
type User ¶
type User struct { Nickname string `json:"nickname" query:"nickname" doc:"Nickname of the user"` Name string `json:"name" query:"name" doc:"Name of the user"` Picture string `json:"picture" query:"picture" doc:"Profile picture URL"` UpdatedAt string `json:"updated_at" query:"updated_at" doc:"Last updated timestamp"` Email string `json:"email" query:"email" doc:"Email address"` EmailVerified bool `json:"email_verified" query:"email_verified" doc:"Email verification status"` Sub string `json:"sub" query:"sub" doc:"Profile ID"` }