extension

package
Version: v0.0.19 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSaltLen is the length of generated salt for the user is 256
	DefaultSaltLen = 256

	// DefaultKeyLen is the length of encoded key in PBKDF2 function is 512
	DefaultKeyLen = 512
)

Variables

View Source
var DefaultHashFunction = sha512.New

DefaultHashFunction ...

Functions

func ValidatePINDigits

func ValidatePINDigits(pin string) error

ValidatePINDigits validates user pin to ensure a PIN only contains digits

func ValidatePINLength

func ValidatePINLength(pin string) error

ValidatePINLength validates user pin to ensure it is 4,5, or six digits

Types

type BaseExtension

type BaseExtension interface {
	GetLoggedInUser(ctx context.Context) (*dto.UserInfo, error)
	GetLoggedInUserUID(ctx context.Context) (string, error)
	NormalizeMSISDN(msisdn string) (*string, error)
	LoadDepsFromYAML() (*interserviceclient.DepsConfig, error)
	SetupISCclient(config interserviceclient.DepsConfig, serviceName string) (*interserviceclient.InterServiceClient, error)
	GetEnvVar(envName string) (string, error)

	// PubSub
	EnsureTopicsExist(
		ctx context.Context,
		pubsubClient *pubsub.Client,
		topicIDs []string,
	) error
	GetRunningEnvironment() string
	NamespacePubsubIdentifier(
		serviceName string,
		topicID string,
		environment string,
		version string,
	) string
	PublishToPubsub(
		ctx context.Context,
		pubsubClient *pubsub.Client,
		topicID string,
		environment string,
		serviceName string,
		version string,
		payload []byte,
	) error
	GoogleCloudProjectIDEnvVarName() (string, error)
	EnsureSubscriptionsExist(
		ctx context.Context,
		pubsubClient *pubsub.Client,
		topicSubscriptionMap map[string]string,
		callbackURL string,
	) error
	SubscriptionIDs(topicIDs []string) map[string]string
	PubSubHandlerPath() string
	VerifyPubSubJWTAndDecodePayload(
		w http.ResponseWriter,
		r *http.Request,
	) (*pubsubtools.PubSubPayload, error)
	GetPubSubTopic(m *pubsubtools.PubSubPayload) (string, error)
	ErrorMap(err error) map[string]string
	WriteJSONResponse(
		w http.ResponseWriter,
		source interface{},
		status int,
	)
}

BaseExtension is an interface that represents some methods in base The `onboarding` service has a dependency on `base` library. Our first step to making some functions are testable is to remove the base dependency. This can be achieved with the below interface.

func NewBaseExtensionImpl

func NewBaseExtensionImpl(fc firebasetools.IFirebaseClient) BaseExtension

NewBaseExtensionImpl ...

type BaseExtensionImpl

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

BaseExtensionImpl ...

func (*BaseExtensionImpl) EnsureSubscriptionsExist

func (b *BaseExtensionImpl) EnsureSubscriptionsExist(
	ctx context.Context,
	pubsubClient *pubsub.Client,
	topicSubscriptionMap map[string]string,
	callbackURL string,
) error

EnsureSubscriptionsExist ensures that the subscriptions named in the supplied topic:subscription map exist. If any does not exist, it is created.

func (*BaseExtensionImpl) EnsureTopicsExist

func (b *BaseExtensionImpl) EnsureTopicsExist(
	ctx context.Context,
	pubsubClient *pubsub.Client,
	topicIDs []string,
) error

EnsureTopicsExist creates the topic(s) in the suppplied list if they do not already exist.

func (*BaseExtensionImpl) ErrorMap

func (b *BaseExtensionImpl) ErrorMap(err error) map[string]string

ErrorMap turns the supplied error into a map with "error" as the key

func (*BaseExtensionImpl) GetEnvVar

func (b *BaseExtensionImpl) GetEnvVar(envName string) (string, error)

GetEnvVar ...

func (*BaseExtensionImpl) GetLoggedInUser

func (b *BaseExtensionImpl) GetLoggedInUser(ctx context.Context) (*dto.UserInfo, error)

GetLoggedInUser retrieves logged in user information

func (*BaseExtensionImpl) GetLoggedInUserUID

func (b *BaseExtensionImpl) GetLoggedInUserUID(ctx context.Context) (string, error)

GetLoggedInUserUID get the logged in user uid

func (*BaseExtensionImpl) GetPubSubTopic

func (b *BaseExtensionImpl) GetPubSubTopic(m *pubsubtools.PubSubPayload) (string, error)

GetPubSubTopic retrieves a pubsub topic from a pubsub payload.

func (*BaseExtensionImpl) GetRunningEnvironment

func (b *BaseExtensionImpl) GetRunningEnvironment() string

GetRunningEnvironment returns the environment wheere the service is running. Importannt so as to point to the correct deps

func (*BaseExtensionImpl) GoogleCloudProjectIDEnvVarName

func (b *BaseExtensionImpl) GoogleCloudProjectIDEnvVarName() (string, error)

GoogleCloudProjectIDEnvVarName returns `GOOGLE_CLOUD_PROJECT` env

func (*BaseExtensionImpl) LoadDepsFromYAML

func (b *BaseExtensionImpl) LoadDepsFromYAML() (*interserviceclient.DepsConfig, error)

LoadDepsFromYAML ...

func (*BaseExtensionImpl) NamespacePubsubIdentifier

func (b *BaseExtensionImpl) NamespacePubsubIdentifier(
	serviceName string,
	topicID string,
	environment string,
	version string,
) string

NamespacePubsubIdentifier uses the service name, environment and version to create a "namespaced" pubsub identifier. This could be a topicID or subscriptionID.

func (*BaseExtensionImpl) NormalizeMSISDN

func (b *BaseExtensionImpl) NormalizeMSISDN(msisdn string) (*string, error)

NormalizeMSISDN validates the input phone number.

func (*BaseExtensionImpl) PubSubHandlerPath

func (b *BaseExtensionImpl) PubSubHandlerPath() string

PubSubHandlerPath returns pubsub hander path `/pubsub`

func (*BaseExtensionImpl) PublishToPubsub

func (b *BaseExtensionImpl) PublishToPubsub(
	ctx context.Context,
	pubsubClient *pubsub.Client,
	topicID string,
	environment string,
	serviceName string,
	version string,
	payload []byte,
) error

PublishToPubsub sends the supplied payload to the indicated topic

func (*BaseExtensionImpl) SetupISCclient

SetupISCclient ...

func (*BaseExtensionImpl) SubscriptionIDs

func (b *BaseExtensionImpl) SubscriptionIDs(topicIDs []string) map[string]string

SubscriptionIDs returns a map of topic IDs to subscription IDs

func (*BaseExtensionImpl) VerifyPubSubJWTAndDecodePayload

func (b *BaseExtensionImpl) VerifyPubSubJWTAndDecodePayload(
	w http.ResponseWriter,
	r *http.Request,
) (*pubsubtools.PubSubPayload, error)

VerifyPubSubJWTAndDecodePayload confirms that there is a valid Google signed JWT and decodes the pubsub message payload into a struct.

It's use will simplify & shorten the handler funcs that process Cloud Pubsub push notifications.

func (*BaseExtensionImpl) WriteJSONResponse

func (b *BaseExtensionImpl) WriteJSONResponse(
	w http.ResponseWriter,
	source interface{},
	status int,
)

WriteJSONResponse writes the content supplied via the `source` parameter to the supplied http ResponseWriter. The response is returned with the indicated status.

type ISCClientExtension

type ISCClientExtension interface {
	MakeRequest(ctx context.Context, method string, path string, body interface{}) (*http.Response, error)
}

ISCClientExtension represents the base ISC client

func NewISCExtension

func NewISCExtension() ISCClientExtension

NewISCExtension initializes an ISC extension

type ISCExtensionImpl

type ISCExtensionImpl struct{}

ISCExtensionImpl ...

func (*ISCExtensionImpl) MakeRequest

func (i *ISCExtensionImpl) MakeRequest(ctx context.Context, method string, path string, body interface{}) (*http.Response, error)

MakeRequest performs an inter service http request and returns a response

type Options

type Options struct {
	SaltLen      int
	Iterations   int
	KeyLen       int
	HashFunction func() hash.Hash
}

Options is a struct for custom values of salt length, number of iterations, the encoded key's length, and the hash function being used. If set to `nil`, default options are used: &Options{ 256, 10000, 512, "sha512" }

type PINExtension

type PINExtension interface {
	EncryptPIN(rawPwd string, options *Options) (string, string)
	ComparePIN(rawPwd string, salt string, encodedPwd string, options *Options) bool
	GenerateTempPIN(ctx context.Context) (string, error)
}

PINExtension ...

func NewPINExtensionImpl

func NewPINExtensionImpl() PINExtension

NewPINExtensionImpl ...

type PINExtensionImpl

type PINExtensionImpl struct {
}

PINExtensionImpl ...

func (PINExtensionImpl) ComparePIN

func (p PINExtensionImpl) ComparePIN(rawPwd string, salt string, encodedPwd string, options *Options) bool

ComparePIN takes four arguments, the raw password, its generated salt, the encoded password, and a pointer to the Options struct, and returns a boolean value determining whether the password is the correct one or not. Passing `nil` as the last argument resorts to default options.

func (PINExtensionImpl) EncryptPIN

func (p PINExtensionImpl) EncryptPIN(rawPwd string, options *Options) (string, string)

EncryptPIN takes two arguments, a raw pin, and a pointer to an Options struct. In order to use default options, pass `nil` as the second argument. It returns the generated salt and encoded key for the user.

func (PINExtensionImpl) GenerateTempPIN

func (p PINExtensionImpl) GenerateTempPIN(ctx context.Context) (string, error)

GenerateTempPIN generates a temporary One Time PIN for a user The PIN will have 4 digits formatted as a string

Source Files

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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