authmethods

package
v0.1.8-1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AuthMethodsTypes = map[string]AuthMethodInit{
	"api-key": NewApiKeyAuthMethod,
	"headers": NewHeadersAuthMethod,
}
View Source
var ExternalServiceHandlers = map[string]ExternalServiceHandler{
	"success":                   ExternalServiceHandlerSuccess,
	"incorrect-retrieval-field": ExternalServiceHandlerIncorrectRetrievalField,
}

ExternalServiceHandlers contains mock handlers that represent various possible scenarios when executing requests to external services

View Source
var QueryAuthMethodFinders = map[string]QueryAuthMethodFinder{
	"api-key": ApiKeyAuthFinder,
	"headers": HeadersAuthFinder,
}

Functions

func ApiKeyAuthFinder

func ApiKeyAuthFinder(serviceUUID string, host string, store stores.Store) ([]stores.QAuthMethod, error)

func AuthMethodAlreadyExists

func AuthMethodAlreadyExists(serviceUUID string, host string, authMethodType string, store stores.Store) error

AuthMethodAlreadyExists checks where or not any type of auth method already exists for the given host and service type

func AuthMethodConvertToQueryModel

func AuthMethodConvertToQueryModel(fromAM AuthMethod, toType string) (stores.QAuthMethod, error)

AuthMethodConvertToQueryModel converts an auth method to a query auth method

func AuthMethodCreate

func AuthMethodCreate(am AuthMethod, store stores.Store, typeOfAuthMethod string) error

AuthMethodCreate inserts the given auth method to the datastore after performing some checks and enriching its contents

func AuthMethodDelete

func AuthMethodDelete(am AuthMethod, store stores.Store) error

AuthMethodDelete deletes the given auth method from the data store

func ExternalServiceHandlerIncorrectRetrievalField

func ExternalServiceHandlerIncorrectRetrievalField(w http.ResponseWriter, r *http.Request)

ExternalServiceHandlerIncorrectRetrievalField mocks the behavior of a successful external request that didn't contain the registered retrieval field

func ExternalServiceHandlerSuccess

func ExternalServiceHandlerSuccess(w http.ResponseWriter, r *http.Request)

MockServiceTypeEndpoint mocks the behavior of a service type endpoint and returns a response containing the requested resource

func HeadersAuthFinder

func HeadersAuthFinder(serviceUUID string, host string, store stores.Store) ([]stores.QAuthMethod, error)

func MockKeyAuthFinder

func MockKeyAuthFinder(serviceUUID string, host string, store stores.Store) ([]stores.QAuthMethod, error)

MockKeyAuthFinder returns a MockAuthMethod for testing purposes

func MockRequestDispatcher

func MockRequestDispatcher(handler ExternalServiceHandler) (*http.Response, error)

MockRequestDispatcher executes and captures the response of a mock handler

Types

type ApiKeyAuthMethod

type ApiKeyAuthMethod struct {
	BasicAuthMethod
	AccessKey string `json:"access_key" required:"true"`
}

func (*ApiKeyAuthMethod) RetrieveAuthResource

func (m *ApiKeyAuthMethod) RetrieveAuthResource(binding bindings.Binding, serviceType servicetypes.ServiceType, cfg *config.Config) (map[string]interface{}, error)

func (*ApiKeyAuthMethod) Update

func (m *ApiKeyAuthMethod) Update(r io.ReadCloser) (AuthMethod, error)

func (*ApiKeyAuthMethod) Validate

func (m *ApiKeyAuthMethod) Validate(store stores.Store) error

type AuthMethod

type AuthMethod interface {
	Validate(store stores.Store) error
	Update(r io.ReadCloser) (AuthMethod, error)
	RetrieveAuthResource(binding bindings.Binding, serviceType servicetypes.ServiceType, cfg *config.Config) (map[string]interface{}, error)
}

func AuthMethodFinder

func AuthMethodFinder(serviceUUID string, host string, authMethodType string, store stores.Store) (AuthMethod, error)

AuthMethodFinder uses the appropriate finder to search for a specific type of auth methods

func AuthMethodUpdate

func AuthMethodUpdate(am AuthMethod, r io.ReadCloser, store stores.Store) (AuthMethod, error)

AuthMethodUpdate updates the given method with a reader's data

func NewApiKeyAuthMethod

func NewApiKeyAuthMethod() AuthMethod

func NewHeadersAuthMethod

func NewHeadersAuthMethod() AuthMethod

func NewMockAuthMethod

func NewMockAuthMethod() AuthMethod

func QueryModelConvertToAuthMethod

func QueryModelConvertToAuthMethod(fromQam stores.QAuthMethod, toType string) (AuthMethod, error)

QueryModelConvertToAuthMethod converts a query auth method to an auth method

type AuthMethodFactory

type AuthMethodFactory struct{}

func NewAuthMethodFactory

func NewAuthMethodFactory() *AuthMethodFactory

func (*AuthMethodFactory) Create

func (f *AuthMethodFactory) Create(amType string) (AuthMethod, error)

type AuthMethodInit

type AuthMethodInit func() AuthMethod

type AuthMethodsList

type AuthMethodsList struct {
	AuthMethods []AuthMethod `json:"auth_methods"`
}

func AuthMethodFindAll

func AuthMethodFindAll(store stores.Store) (AuthMethodsList, error)

AuthMethodFindAll finds and returns all the registered auth methods

type BasicAuthMethod

type BasicAuthMethod struct {
	ServiceUUID string `json:"service_uuid" required:"true"`
	Port        int    `json:"port" required:"true"`
	Host        string `json:"host" required:"true"`
	Type        string `json:"type" required:"true"`
	UUID        string `json:"uuid"`
	CreatedOn   string `json:"created_on"`
}

func (*BasicAuthMethod) Validate

func (m *BasicAuthMethod) Validate(store stores.Store) error

type ExternalServiceHandler

type ExternalServiceHandler func(w http.ResponseWriter, r *http.Request)

type HeadersAuthMethod

type HeadersAuthMethod struct {
	BasicAuthMethod
	Headers map[string]string `json:"headers" required:"true"`
}

func (*HeadersAuthMethod) RetrieveAuthResource

func (m *HeadersAuthMethod) RetrieveAuthResource(binding bindings.Binding, serviceType servicetypes.ServiceType, cfg *config.Config) (map[string]interface{}, error)

func (*HeadersAuthMethod) Update

func (*HeadersAuthMethod) Validate

func (m *HeadersAuthMethod) Validate(store stores.Store) error

type MockAuthMethod

type MockAuthMethod struct {
	RetrievalField string `json:"retrieval_field"`
}

func (*MockAuthMethod) RetrieveAuthResource

func (m *MockAuthMethod) RetrieveAuthResource(binding bindings.Binding, serviceType servicetypes.ServiceType, cfg *config.Config) (map[string]interface{}, error)

func (*MockAuthMethod) SetDefaults

func (m *MockAuthMethod) SetDefaults(tp string) error

func (*MockAuthMethod) Update

func (m *MockAuthMethod) Update(r io.ReadCloser) (AuthMethod, error)

func (*MockAuthMethod) Validate

func (m *MockAuthMethod) Validate(store stores.Store) error

type QMockAuthMethod

type QMockAuthMethod struct {
	RetrievalField string `json:"retrieval_field"`
}

type QueryAuthMethodFinder

type QueryAuthMethodFinder func(serviceUUID string, host string, store stores.Store) ([]stores.QAuthMethod, error)

A function type that refers to all the query functions for all the respective tuh method types

type TempApiKeyAuthMethod

type TempApiKeyAuthMethod struct {
	TempBasicAuthMethod
	AccessKey string `json:"access_key" required:"true"`
}

TempApiKeyAuthMethod represents the fields that are allowed to be modified

type TempBasicAuthMethod

type TempBasicAuthMethod struct {
	ServiceUUID string `json:"service_uuid" required:"true"`
	Port        int    `json:"port" required:"true"`
	Host        string `json:"host" required:"true"`
}

TempBasicAuthMethod represents the fields that are allowed to be modified

type TempHeadersAuthMethod

type TempHeadersAuthMethod struct {
	TempBasicAuthMethod
	Headers map[string]string `json:"headers" required:"true"`
}

TempHeadersAuthMethod represents the fields that are allowed to be modified

Jump to

Keyboard shortcuts

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