authservice

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken added in v1.0.5

type AccessToken struct {
	Token     string `json:"access_token"`
	TokenType string `json:"token_type"`
}

AccessToken represents an access token granted by a remote auth service

type AuthDataLoader added in v1.0.5

type AuthDataLoader interface {
	// GetAccessToken gets an access token
	GetAccessToken() error
	// GetDeletedAccounts loads deleted account IDs
	GetDeletedAccounts() ([]string, error)
	ServiceRegLoader
}

AuthDataLoader declares an interface to load data from an auth service

type AuthService

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

AuthService contains the configurations to interface with the auth service

func NewAuthService

func NewAuthService(serviceID string, serviceHost string, dataLoader AuthDataLoader) (*AuthService, error)

NewAuthService creates and configures a new AuthService instance

func NewTestAuthService

func NewTestAuthService(serviceID string, serviceHost string, dataLoader AuthDataLoader) (*AuthService, error)

NewTestAuthService creates and configures a new AuthService instance for testing purposes

func (*AuthService) CheckForRefresh

func (a *AuthService) CheckForRefresh() (bool, error)

func (*AuthService) GetServiceID

func (a *AuthService) GetServiceID() string

GetServiceID returns the ID of the implementing service

func (*AuthService) GetServiceReg

func (a *AuthService) GetServiceReg(id string) (*ServiceReg, error)

GetServiceReg returns the service registration record for the given ID if found

func (*AuthService) GetServiceRegWithPubKey

func (a *AuthService) GetServiceRegWithPubKey(id string) (*ServiceReg, error)

GetServiceRegWithPubKey returns the service registration record for the given ID if found and validates the PubKey

func (*AuthService) LoadServices

func (a *AuthService) LoadServices() error

LoadServices loads the subscribed service registration records and caches them

This function will be called periodically after refreshCacheFreq, but can be called directly to force a cache refresh

func (*AuthService) SetMaxRefreshCacheFreq

func (a *AuthService) SetMaxRefreshCacheFreq(freq int)

SetMaxRefreshCacheFreq sets the minimum frequency at which cached service registration records are refreshed in minutes

The default value is 60

func (*AuthService) SetMinRefreshCacheFreq

func (a *AuthService) SetMinRefreshCacheFreq(freq int)

SetMinRefreshCacheFreq sets the minimum frequency at which cached service registration records are refreshed in minutes

The default value is 1

func (*AuthService) SubscribeServices

func (a *AuthService) SubscribeServices(serviceIDs []string, reload bool) error

SubscribeServices subscribes to the provided services

If reload is true and one of the services is not already subscribed, the service registrations will be reloaded immediately

func (*AuthService) UnsubscribeServices

func (a *AuthService) UnsubscribeServices(serviceIDs []string)

UnsubscribeServices unsubscribes from the provided service

func (*AuthService) ValidateServiceRegistration

func (a *AuthService) ValidateServiceRegistration(serviceHost string) error

ValidateServiceRegistration validates that the implementing service has a valid registration for the provided service ID and hostname

func (*AuthService) ValidateServiceRegistrationKey

func (a *AuthService) ValidateServiceRegistrationKey(privKey *rsa.PrivateKey) error

ValidateServiceRegistrationKey validates that the implementing service has a valid registration for the provided keypair

type PubKey

type PubKey struct {
	Key    *rsa.PublicKey `json:"-" bson:"-"`
	KeyPem string         `json:"key_pem" bson:"key_pem" validate:"required"`
	Alg    string         `json:"alg" bson:"alg" validate:"required"`
	Kid    string         `json:"-" bson:"-"`
}

PubKey represents a public key object including the key and related metadata

func (*PubKey) LoadKeyFromPem

func (p *PubKey) LoadKeyFromPem() error

LoadKeyFromPem parses "KeyPem" and sets the "Key" and "Kid"

type RemoteAuthDataLoaderConfig added in v1.0.5

type RemoteAuthDataLoaderConfig struct {
	AuthServicesHost string // URL of auth services host
	ServiceToken     string // Static token issued by the auth service, used to get access tokens from the auth service

	AccessTokenPath     string // Path to auth service access token endpoint
	DeletedAccountsPath string // Path to auth service deleted accounts endpoint
	ServiceRegPath      string // Path to auth service service registration endpoint

	AccessTokenRequest       *http.Request
	DeletedAccountsCallback  func([]string) error // Function to call once the deleted accounts list is received from the auth service
	GetDeletedAccountsPeriod int64                // How often to request deleted account list from the auth service (in hours)
}

RemoteAuthDataLoaderConfig represents a configuration for a remote data loader

type RemoteAuthDataLoaderImpl added in v1.0.5

type RemoteAuthDataLoaderImpl struct {
	*RemoteServiceRegLoaderImpl
	// contains filtered or unexported fields
}

RemoteAuthDataLoaderImpl provides a AuthDataLoader implementation for a remote auth service

func NewRemoteAuthDataLoader added in v1.0.5

func NewRemoteAuthDataLoader(config RemoteAuthDataLoaderConfig, subscribedServices []string, logger *logs.Logger) (*RemoteAuthDataLoaderImpl, error)

NewRemoteAuthDataLoader creates and configures a new NewRemoteAuthDataLoaderImpl instance for the provided auth services url

func (*RemoteAuthDataLoaderImpl) GetAccessToken added in v1.0.5

func (r *RemoteAuthDataLoaderImpl) GetAccessToken() error

GetAccessToken implements AuthDataLoader interface

func (*RemoteAuthDataLoaderImpl) GetDeletedAccounts added in v1.0.5

func (r *RemoteAuthDataLoaderImpl) GetDeletedAccounts() ([]string, error)

GetDeletedAccounts implements AuthDataLoader interface

type RemoteServiceRegLoaderImpl

type RemoteServiceRegLoaderImpl struct {
	*ServiceRegSubscriptions
	// contains filtered or unexported fields
}

RemoteServiceRegLoaderImpl provides a ServiceRegLoader implementation for a remote auth service

func NewRemoteServiceRegLoader

func NewRemoteServiceRegLoader(subscribedServices []string) *RemoteServiceRegLoaderImpl

NewRemoteServiceRegLoader creates and configures a new RemoteServiceRegLoaderImpl instance for the provided auth services url

func (*RemoteServiceRegLoaderImpl) LoadServices

func (r *RemoteServiceRegLoaderImpl) LoadServices() ([]ServiceReg, error)

LoadServices implements ServiceRegLoader interface

type ServiceReg

type ServiceReg struct {
	ServiceID        string  `json:"service_id" bson:"service_id" validate:"required"`
	ServiceAccountID string  `json:"service_account_id" bson:"service_account_id"`
	Host             string  `json:"host" bson:"host" validate:"required"`
	PubKey           *PubKey `json:"pub_key" bson:"pub_key"`
}

ServiceReg represents a service registration record

type ServiceRegLoader

type ServiceRegLoader interface {
	// LoadServices loads the service registration records for all subscribed services
	LoadServices() ([]ServiceReg, error)
	//GetSubscribedServices returns the list of currently subscribed services
	GetSubscribedServices() []string
	// SubscribeService subscribes the loader to the given service
	// 	Returns true if the specified service was added or false if it was already found
	SubscribeService(serviceID string) bool
	// UnsubscribeService unsubscribes the loader from the given service
	// 	Returns true if the specified service was removed or false if it was not found
	UnsubscribeService(serviceID string) bool
}

ServiceRegLoader declares an interface to load the service registrations for specified services

type ServiceRegSubscriptions

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

ServiceRegSubscriptions defined a struct to hold service registration subscriptions

This struct implements the subcription part of the ServiceRegLoader interface
If you subscribe to the reserved "all" service ID, all registered services
will be loaded

func NewServiceRegSubscriptions

func NewServiceRegSubscriptions(subscribedServices []string) *ServiceRegSubscriptions

NewServiceRegSubscriptions creates and configures a new ServiceRegSubscriptions instance

func (*ServiceRegSubscriptions) GetSubscribedServices

func (r *ServiceRegSubscriptions) GetSubscribedServices() []string

GetSubscribedServices returns the list of subscribed services

func (*ServiceRegSubscriptions) SubscribeService

func (r *ServiceRegSubscriptions) SubscribeService(serviceID string) bool

SubscribeService adds the given service ID to the list of subscribed services if not already present

Returns true if the specified service was added or false if it was already found

func (*ServiceRegSubscriptions) UnsubscribeService

func (r *ServiceRegSubscriptions) UnsubscribeService(serviceID string) bool

UnsubscribeService removed the given service ID from the list of subscribed services if presents

Returns true if the specified service was removed or false if it was not found

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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