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 RegisterService(ctx *cli.Context, baseService service.Service) (service.Service, error)
- type AuthCallback
- type Key
- 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, method string, params json.RawMessage) 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 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 ¶
Types ¶
type AuthCallback ¶
type Key ¶
type Key struct { // Id represents the unique identifier of the API key. Id uuid.UUID `json:"id"` // ProfileId represents reference identifier to the user id. ProfileId string `json:"profileId"` // Label represents the label or name assigned to the API key. Label string `json:"label"` // Key represents the actual API key string. Key string `json:"key"` // Roles represents the roles associated with the API key. Roles []string `json:"roles"` // RateLimit represents the rate limit applied to the API key. RateLimit int32 `json:"rateLimit"` // RateLimitDuration represents the duration of the rate limit (e.g., second, minute, hour). RateLimitDuration string `json:"rateLimitDuration"` // Enabled indicates whether the API key is enabled. Enabled bool `json:"enabled"` // Suspended indicates whether the API key is suspended. Suspended bool `json:"suspended"` // CreatedAt represents the creation timestamp of the API key. CreatedAt time.Time `json:"createdAt"` // UpdatedAt represents the last update timestamp of the API key. UpdatedAt time.Time `json:"updatedAt"` }
Key struct represents an API key with associated metadata.
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, 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) RegisterNamespaces ¶
RegisterNamespaces registers RPC namespaces for the ACL service.
It registers the "acl" namespace with the RpcService instance.