authentication_handler

package
v0.0.0-...-eac6ddc Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EMPTY = ""
)

Variables

View Source
var (
	ErrRequestTimeout                           = errors.New("request timeout")
	ErrRetriesExceeded                          = errors.New("retries exceeded")
	ErrInvalidRequest                           = errors.New("invalid grpc request")
	ErrFailedToConnectToDatabase                = errors.New("failed to connect to database")
	ErrFailedToPerformDatabaseMigrations        = errors.New("failed to perform database migrations")
	ErrInvalidInputArguments                    = errors.New("invalid input arguments")
	ErrInvalidEnvironmentVariableConfigurations = errors.New("invalid environment variable configurations")
	ErrFailedToStartGRPCServer                  = errors.New("failed to start grpc server")
	ErrHttpServerFailedGracefuleShutdown        = errors.New("http server failed to perform graceful shutdown")
	ErrHttpsServerFailedGracefuleShutdown       = errors.New("https server failed to perform graceful shutdown")
	ErrHttpServerCrashed                        = errors.New("http Server crashed")
	ErrHttpsServerCrashed                       = errors.New("https Server crashed")
	ErrSwaggerGenError                          = errors.New("swagger generation error")
	ErrFailedToWatchConfigDirectory             = errors.New("failed to watch config directory")
	ErrExceededMaxRetryAttempts                 = errors.New("exceeded max retry attemps")
	ErrInvalidAccount                           = errors.New("invalid account. account contains invalid fields")
	ErrFailedToReactivateAccount                = errors.New("failed to reactivate existing account")
	ErrDistributedTransactionError              = errors.New(
		"distributed transaction error. failed to successfully perform a distributed operations")
	ErrFailedToUpdateAccountActiveStatus = errors.New("failed to updated account active status")
	ErrAccountDoesNotExist               = errors.New("account does not exist")
	ErrCannotLogoutAccount               = errors.New("cannot logout account")
	ErrAccountAlreadyUnlocked            = errors.New("account already unlocked")
	ErrAccountAlreadyLocked              = errors.New("account already locked")
	ErrAccountAlreadyExist               = errors.New("account already exists")
	ErrFailedToConvertFromOrmType        = errors.New("failed to perform conversion from Orm type")
	ErrFailedToConvertToOrmType          = errors.New("failed to perform conversion to Orm type")
	ErrFailedToConfigureSaga             = errors.New("failed to configure saga")
	ErrSagaFailedToExecuteSuccessfully   = errors.New("saga failed to execute successfully")
	ErrFailedToHashPassword              = errors.New("failed to hash password")
	ErrFailedToCreateAccount             = errors.New("failed to create account")
	ErrFailedToUpdateAccountEmail        = errors.New("failed to updated account email through distributed transaction")
	ErrFailedToSaveUpdatedAccountRecord  = errors.New("failed to save updated account record")
	ErrCannotUpdatePassword              = errors.New("cannot update password field")
	ErrCannotConfigureAccount            = errors.New("cannot configure account")
	ErrUnableToObtainBusinessAccounts    = errors.New("unable to obtain account")
	ErrFailedToCastAccount               = errors.New("failed to cast account")
	ErrUnauthorizedRequest               = errors.New("unauthorized request")
	ErrJWTCastingError                   = errors.New("issue casting to jwt token")
	ErrTypeConversionError               = errors.New("failed to convert result to uint32 id value")
)

Functions

func ConnectToAuthService

func ConnectToAuthService(logger *zap.Logger, client *core_auth_sdk.Client, response chan interface{}) error

ConnectToAuthService attempts to connect to a downstream service

func NewCastingOperationFailureCounter

func NewCastingOperationFailureCounter(serviceName string) *prometheus.CounterVec

NewCastingOperationFailureCounter returns an instance of the casting operation failure counter

func NewDecodeRequestStatusCounter

func NewDecodeRequestStatusCounter(serviceName string) *prometheus.CounterVec

NewDecodeRequestStatusCounter returns an instance of the request status counter

func NewExtractIdOperationCounter

func NewExtractIdOperationCounter(serviceName string) *prometheus.CounterVec

NewExtractIdOperationCounter returns an instance of the status of the extract id operation counter

func NewInvalidRequestParametersCounter

func NewInvalidRequestParametersCounter(serviceName string) *prometheus.CounterVec

NewInvalidRequestParametersCounter returns an instance of the invalid request parameters counter

func NewRemoteOperationLatencyCounter

func NewRemoteOperationLatencyCounter(serviceName string) *prometheus.HistogramVec

NewRemoteOperationLatencyCounter returns an instance of the rpc operation latency counter

func NewRemoteOperationStatusCounter

func NewRemoteOperationStatusCounter(serviceName string) *prometheus.CounterVec

NewRemoteOperationStatusCounter returns an instance of a counter capturing the status of an rpc operation

func NewRequestCounter

func NewRequestCounter(serviceName string) *prometheus.CounterVec

NewRequestCounter returns a counter instance capturing the number of requests

func NewRequestLatencyCounter

func NewRequestLatencyCounter(serviceName string) *prometheus.HistogramVec

NewRequestLatencyCounter returns a counter instance capturing the request latency of a grpc operation

Types

type AuthenticateAccountRequest

type AuthenticateAccountRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type AuthenticateAccountResponse

type AuthenticateAccountResponse struct {
	Token        string `json:"token"`
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

type AuthenticationComponent

type AuthenticationComponent struct {
	// Client is a connection handler to the authn service
	Client *core_auth_sdk.Client
	// Logger is the logger object used by this component
	Logger *zap.Logger
	// Metric specific to this module
	Metric *ServiceMetrics
	// Duration of any expected http call
	HttpTimeout time.Duration
}

AuthenticationComponent provides a wrapper around the authn client for more robust configurability per our use cases

func InitializeMockAuthenticationComponent

func InitializeMockAuthenticationComponent() *AuthenticationComponent

InitializeMockAuthenticationComponent initializes a mock authentication component assuming certain pre-conditions are met

func NewAuthenticationComponent

func NewAuthenticationComponent(params *AuthenticationParams, serviceName string, httpRequestTimeout time.Duration) *AuthenticationComponent

NewAuthenticationComponent returns an authentication component to the caller

func (*AuthenticationComponent) AuthenticateAccount

func (c *AuthenticationComponent) AuthenticateAccount(ctx context.Context, email, password string) (string, error)

AuthenticateAccount attempts to authenticate a user based on provided credentials

func (*AuthenticationComponent) AuthenticateAccountHandler

func (c *AuthenticationComponent) AuthenticateAccountHandler(w http.ResponseWriter, r *http.Request)

AuthenticateAccountHandler godoc @Summary Account Authentication @Description authenticates a user account based on provided credentials against the authentication service @Tags HTTP API @Produce html @Router / [post] @Success 200 {string} string "OK"

func (*AuthenticationComponent) CreateAccount

func (c *AuthenticationComponent) CreateAccount(ctx context.Context, email, password string, accountLocked bool) (uint32, error)

CreateAccount attempts to create a user account against the authentication service

func (*AuthenticationComponent) CreateAccountHandler

func (c *AuthenticationComponent) CreateAccountHandler(w http.ResponseWriter, r *http.Request)

CreateAccountHandler godoc @Summary Create Account @Description creates a new user account in the authentication service @Tags HTTP API @Produce html @Router / [post] @Success 200 {string} string "OK"

func (*AuthenticationComponent) DeleteAccount

func (c *AuthenticationComponent) DeleteAccount(ctx context.Context, Id uint32) error

DeleteAccount attempts to archive an account from the context of the authentication service (authn)

func (*AuthenticationComponent) DeleteAccountHandler

func (c *AuthenticationComponent) DeleteAccountHandler(w http.ResponseWriter, r *http.Request)

DeleteAccountHandler godoc @Summary Delete Account @Description deletes user account in the authentication service @Tags HTTP API @Produce html @Router / [delete] @Success 200 {string} string "OK"

func (*AuthenticationComponent) GetAccount

GetAccount obtains a user account from the context of the authentications service (authn) based on a provided user id

func (*AuthenticationComponent) GetAccountHandler

func (c *AuthenticationComponent) GetAccountHandler(w http.ResponseWriter, r *http.Request)

GetAccountHandler godoc @Summary Get Account @Description gets a user account from the context of the authentication service @Tags HTTP API @Produce html @Router / [get] @Success 200 {string} string "OK"

func (*AuthenticationComponent) IsPasswordOrEmailInValid

func (c *AuthenticationComponent) IsPasswordOrEmailInValid(email string, password string) (bool, error)

IsPasswordOrEmailInValid checks request parameters for validity

func (*AuthenticationComponent) LockAccount

func (c *AuthenticationComponent) LockAccount(ctx context.Context, Id uint32) error

LockAccount locks a user account

func (*AuthenticationComponent) LockAccountHandler

func (c *AuthenticationComponent) LockAccountHandler(w http.ResponseWriter, r *http.Request)

LockAccountHandler godoc @Summary Lock Account @Description locks a user account from the context of the authentication service @Tags HTTP API @Produce html @Router / [post] @Success 200 {string} string "OK"

func (*AuthenticationComponent) LogoutAccount

func (c *AuthenticationComponent) LogoutAccount(ctx context.Context, Id uint32) error

func (*AuthenticationComponent) LogoutAccountHandler

func (c *AuthenticationComponent) LogoutAccountHandler(w http.ResponseWriter, r *http.Request)

LogoutAccountHandler godoc @Summary Log out of Account @Description logs user account out of the system from the context of the authentication service @Tags HTTP API @Produce html @Router / [post] @Success 200 {string} string "OK"

func (*AuthenticationComponent) UnLockAccount

func (c *AuthenticationComponent) UnLockAccount(ctx context.Context, Id uint32) error

UnLockAccount unlocks a user account

func (*AuthenticationComponent) UnLockAccountHandler

func (c *AuthenticationComponent) UnLockAccountHandler(w http.ResponseWriter, r *http.Request)

UnLockAccountHandler godoc @Summary UnLock Account @Description unlocks a user account from the context of the authentication service @Tags HTTP API @Produce html @Router / [post] @Success 200 {string} string "OK"

func (*AuthenticationComponent) UpdateAccount

func (c *AuthenticationComponent) UpdateAccount(ctx context.Context, Id uint32, email string) error

UpdateAccount updates a user account's credentials

func (*AuthenticationComponent) UpdateEmailHandler

func (c *AuthenticationComponent) UpdateEmailHandler(w http.ResponseWriter, r *http.Request)

UpdateEmailHandler godoc @Summary Update Account Email @Description updates the email account from the context of the authentication service @Tags HTTP API @Produce html @Router / [post] @Success 200 {string} string "OK"

type AuthenticationParams

type AuthenticationParams struct {
	// AuthConfig is comprised with security parameters necessary for connecting to the authn service
	AuthConfig *core_auth_sdk.Config
	// AuthnConnectionConfig defines the various retry configurations that will dictate the retry logic to engage in in the face of an http failure
	AuthConnectionConfig *core_auth_sdk.RetryConfig
	// Logger is the logger object
	Logger *zap.Logger
	// Origin is the origin server from which requests originate from
	Origin string
}

AuthenticationParams encompases the required entries necessary to configure a client connection to the authn service

type AuthenticationServiceInterface

type AuthenticationServiceInterface interface {
	AuthenticateAccount(ctx context.Context, email, password string) (string, error)
	AuthenticateAccountHandler(w http.ResponseWriter, r *http.Request)
	CreateAccount(ctx context.Context, email, password string, accountLocked bool) (uint32, error)
	CreateAccountHandler(w http.ResponseWriter, r *http.Request)
	DeleteAccount(ctx context.Context, Id uint32) error
	DeleteAccountHandler(w http.ResponseWriter, r *http.Request)
	GetAccount(ctx context.Context, Id uint32) (*core_auth_sdk.Account, error)
	GetAccountHandler(w http.ResponseWriter, r *http.Request)
	LockAccount(ctx context.Context, Id uint32) error
	LockAccountHandler(w http.ResponseWriter, r *http.Request)
	UnLockAccount(ctx context.Context, Id uint32) error
	UnLockAccountHandler(w http.ResponseWriter, r *http.Request)
	UpdateAccount(ctx context.Context, Id uint32, email string) error
	UpdateEmailHandler(w http.ResponseWriter, r *http.Request)
	LogoutAccount(ctx context.Context, Id uint32) error
	LogoutAccountHandler(w http.ResponseWriter, r *http.Request)
}

AuthenticationServiceInterface provides an interface definition specific to authentication

type CreateAccountRequest

type CreateAccountRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type CreateAccountResponse

type CreateAccountResponse struct {
	Id           uint32 `json:"id"`
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

type DeleteAccountResponse

type DeleteAccountResponse struct {
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

type GetAccountResponse

type GetAccountResponse struct {
	Account      *core_auth_sdk.Account `json:"account"`
	Code         int                    `json:"code"`
	ErrorMessage string                 `json:"message"`
}

type LockAccountResponse

type LockAccountResponse struct {
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

type LogoutAccountResponse

type LogoutAccountResponse struct {
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

type ServiceMetrics

type ServiceMetrics struct {
	ServiceName string
	// tracks the number of grpc requests partitioned by name and status code
	// used for monitoring and alerting (RED method)
	RequestCounter *prometheus.CounterVec
	// tracks the latencies associated with a GRPC requests by operation name
	// used for horizontal pod auto-scaling (Kubernetes HPA v2)
	RequestLatency *prometheus.HistogramVec
	// tracks the number of times there was a failure or success when trying to extract id from the request url
	ExtractIdOperationCounter *prometheus.CounterVec
	// tracks the status of rpc operations
	RemoteOperationStatusCounter *prometheus.CounterVec
	// tracks the latency of various remote operations
	RemoteOperationLatencyCounter *prometheus.HistogramVec
	// tracks the number of invalid requests processed by the service
	InvalidRequestParameterCounter *prometheus.CounterVec
	// tracks the number of failed casting operations captured by the service
	CastingOperationFailureCounter *prometheus.CounterVec
	// tracks the number of failed request decoding operations for the service
	DecodeRequestStatusCounter *prometheus.CounterVec
}

func NewServiceMetrics

func NewServiceMetrics(serviceName string) *ServiceMetrics

NewServiceMetrics returns a pointer reference to a metrics objects encapsulating all registered counters for this service

type UnLockAccountResponse

type UnLockAccountResponse struct {
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

type UpdateEmailRequest

type UpdateEmailRequest struct {
	Email string `json:"email"`
}

type UpdateEmailResponse

type UpdateEmailResponse struct {
	Code         int    `json:"code"`
	ErrorMessage string `json:"message"`
}

Jump to

Keyboard shortcuts

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