api_keys

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

README


title: API Keys Plugin

Provides API key authentication for endpoints.

Type

  • Wrapper
  • Swaggerer

Description

Implements API key authentication by validating keys from headers or query parameters. Supports method-level permissions per key.

Configuration

api_keys:
  name: "X-API-Key"          # Header or query parameter name
  location: "header"         # Where to look for the key: "header" or "query"
  keys:                      # List of valid API keys
    - key: "secret-key-1"
      allowed_methods:       # Allowed methods for this key
        - "get_users"
        - "create_user"
    - key: "admin-key"      # Key with all methods allowed
      allowed_methods: []    
  keys_file: "/path/to/keys.yaml"  # Optional external keys file

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MaybeSetSecurity

func MaybeSetSecurity(op *huma.Operation, name string) *huma.Operation

Types

type Config

type Config struct {
	// Name specifies the header or query parameter name for the API key
	// Example: "X-API-Key" or "api_key"
	Name string `yaml:"name"`

	// Keys is a list of API keys and their permissions
	Keys []Key `yaml:"keys"`

	// KeysFile is a path to file containing API keys (optional)
	KeysFile string `yaml:"keys_file"`

	// Location specifies where to look for the API key: "header" or "query"
	Location string `yaml:"location"`
}

Config represents API key authentication plugin configuration

func (Config) Doc

func (c Config) Doc() string

func (Config) Tag

func (c Config) Tag() string

type Connector

type Connector struct {
	connectors.Connector
	// contains filtered or unexported fields
}

func (Connector) Query

func (c Connector) Query(ctx context.Context, endpoint model.Endpoint, params map[string]any) ([]map[string]any, error)

type Key

type Key struct {
	// Key is the API key value
	Key string `yaml:"key"`

	// AllowedMethods specifies which HTTP methods this key can use
	// If empty, all methods are allowed
	AllowedMethods []string `yaml:"allowed_methods"`
}

Key represents a single API key configuration with its permissions

func (*Key) Allowed

func (t *Key) Allowed(method string) bool

type Plugin

type Plugin struct {
	// contains filtered or unexported fields
}

func (Plugin) Doc

func (p Plugin) Doc() string

func (Plugin) Enrich

func (p Plugin) Enrich(swag *huma.OpenAPI) *huma.OpenAPI

func (Plugin) Wrap

func (p Plugin) Wrap(connector connectors.Connector) (connectors.Connector, error)

type PluginBundle

type PluginBundle interface {
	plugins.Wrapper
	plugins.Swaggerer
}

func New

func New(cfg Config) (PluginBundle, error)

Jump to

Keyboard shortcuts

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