acl

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 24 Imported by: 0

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

Constants

This section is empty.

Variables

View Source
var AclServiceName rest.ServiceName = "acl"

AclServiceName defines the service name for the Acl service.

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

func RegisterAuthCallback(n *Namespace) error

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

func RegisterCreateKeyHandler(n *Namespace) error

RegisterCreateKeyHandler registers the endpoint to create a new API key

func RegisterDeleteKeyHandler added in v0.9.7

func RegisterDeleteKeyHandler(n *Namespace) error

RegisterDeleteKeyHandler registers the endpoint to delete an API key by ID

func RegisterGetCurrentKeyHandler added in v0.9.7

func RegisterGetCurrentKeyHandler(n *Namespace) error

RegisterGetCurrentKeyHandler registers the endpoint to get the current API key

func RegisterGetKeyHandler added in v0.9.7

func RegisterGetKeyHandler(n *Namespace) error

RegisterGetKeyHandler registers the endpoint to get an API key by ID

func RegisterListKeysHandler added in v0.9.7

func RegisterListKeysHandler(n *Namespace) error

RegisterListKeysHandler registers the endpoint to list API keys

func RegisterService

func RegisterService(ctx *cli.Context, baseService service.Service) (service.Service, error)

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

func RegisterUpdateKeyHandler(n *Namespace) error

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

type InputDeleteKey struct {
	ID uuid.UUID `json:"id" path:"id" doc:"API key ID"`
}

InputDeleteKey represents the input parameters required for the DeleteKey handler.

type InputGetKey added in v0.9.7

type InputGetKey struct {
	ID uuid.UUID `json:"id" path:"id" doc:"API key ID"`
}

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.

func CreateKey added in v0.9.7

func CreateKey(ctx context.Context, n *Namespace, input *InputCreateKey) (*Key, error)

CreateKey creates a new API key based on the provided input. It validates the input parameters and generates a new API key if valid.

type Namespace added in v0.9.7

type Namespace struct {
	*rest.Server
	// contains filtered or unexported fields
}

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

func (s *Namespace) RegisterHandlers() error

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

func (s RpcService) DeleteKey(ctx context.Context, id *uuid.UUID) (*Key, *zenrpc.Error)

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

func (s RpcService) GetKey(ctx context.Context, id uuid.UUID) (*Key, *zenrpc.Error)

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

func (s *Service) RegisterRestNamespaces() error

RegisterRestNamespaces registers REST namespaces for the ACL service.

func (*Service) RegisterRpcNamespaces added in v0.9.7

func (s *Service) RegisterRpcNamespaces() error

RegisterRpcNamespaces registers RPC namespaces for the ACL service.

It registers the "acl" namespace with the RpcService instance.

func (*Service) Start

func (s *Service) Start(network utils.Network, networkId utils.NetworkID) error

Start starts the ACL service.

This method does nothing at the moment and may not perform any actions in the future.

func (*Service) Stop

func (s *Service) Stop() error

Stop stops the ACL service.

This method does nothing at the moment and may not perform any actions in the future.

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"`
}

Jump to

Keyboard shortcuts

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