repository

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EnvLocalConfigPath     = "AUTH_SERVER_LOCAL_CONFIG_PATH"
	DefaultLocalConfigPath = "../../config/local_repository_config.yml"
)

Variables

This section is empty.

Functions

func HashAndSalt

func HashAndSalt(pwd string) ([]byte, error)

Types

type AerospikeRepository

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

AerospikeRepository implements the Repository interface using Aerospike Database as the storage backend.

func NewAerospike

func NewAerospike() (*AerospikeRepository, error)

NewAerospike returns a new AerospikeRepository using environment variables for configuration.

func (*AerospikeRepository) AuthenticateBasic

func (aero *AerospikeRepository) AuthenticateBasic(username string, password string) *UserDetails

AuthenticateBasic validates the basic username and password before issuing a JWT. It uses the bcrypt password-hashing function to validate the password.

func (*AerospikeRepository) AuthorizeRequest

func (aero *AerospikeRepository) AuthorizeRequest(userRole UserRole, request RequestDetails) bool

AuthorizeRequest checks if the role has permissions to access the endpoint.

type AuthDetails

type AuthDetails struct {
	Password string   `yaml:"password"`
	Role     UserRole `yaml:"role"`
}

AuthDetails contains authentication details for the user.

type Local

type Local struct {
	Users map[string]AuthDetails        `yaml:"users"`
	Roles map[UserRole][]RequestDetails `yaml:"roles"`
}

Local implements the Repository interface by loading authentication details from a local configuration file.

func NewLocal

func NewLocal() (*Local, error)

NewLocal returns a new Local repository using an environment variable to read a custom path to the configuration file.

func (*Local) AuthenticateBasic

func (local *Local) AuthenticateBasic(username string, password string) *UserDetails

AuthenticateBasic validates the basic username and password before issuing a JWT.

func (*Local) AuthorizeRequest

func (local *Local) AuthorizeRequest(userRole UserRole, requestDetails RequestDetails) bool

AuthorizeRequest checks if the role has permissions to access the endpoint.

type Repository

type Repository interface {

	// AuthenticateBasic validates the basic username and password before issuing a JWT.
	AuthenticateBasic(username string, password string) *UserDetails

	// AuthorizeRequest checks if the role has permissions to access the endpoint.
	AuthorizeRequest(userRole UserRole, request RequestDetails) bool
}

A Repository acts as a gateway to the authentication and authorization operations, facilitating secure access to resources.

type RequestDetails

type RequestDetails struct {
	Method string `yaml:"method"`
	URI    string `yaml:"uri"`
}

RequestDetails represents request details.

func (RequestDetails) String

func (r RequestDetails) String() string

String implements the fmt.Stringer interface.

type UserDetails

type UserDetails struct {
	UserName string
	UserRole UserRole
}

UserDetails represents user details.

type UserRole

type UserRole string

UserRole represents a user role.

type VaultRepository

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

VaultRepository implements the Repository interface using HashiCorp Vault as the storage backend.

func NewVault

func NewVault() (*VaultRepository, error)

NewVault returns a new VaultRepository using environment variables for configuration.

func (*VaultRepository) AuthenticateBasic

func (vr *VaultRepository) AuthenticateBasic(username string, password string) *UserDetails

AuthenticateBasic validates the basic username and password before issuing a JWT. It uses the bcrypt password-hashing function to validate the password.

func (*VaultRepository) AuthorizeRequest

func (vr *VaultRepository) AuthorizeRequest(userRole UserRole, request RequestDetails) bool

AuthorizeRequest checks if the role has permissions to access the endpoint.

Jump to

Keyboard shortcuts

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