Documentation
¶
Index ¶
- Constants
- Variables
- func ValidatePINDigits(pin string) error
- func ValidatePINLength(pin string) error
- type BaseExtension
- type BaseExtensionImpl
- func (b *BaseExtensionImpl) EnsureSubscriptionsExist(ctx context.Context, pubsubClient *pubsub.Client, ...) error
- func (b *BaseExtensionImpl) EnsureTopicsExist(ctx context.Context, pubsubClient *pubsub.Client, topicIDs []string) error
- func (b *BaseExtensionImpl) ErrorMap(err error) map[string]string
- func (b *BaseExtensionImpl) GetEnvVar(envName string) (string, error)
- func (b *BaseExtensionImpl) GetLoggedInUser(ctx context.Context) (*dto.UserInfo, error)
- func (b *BaseExtensionImpl) GetLoggedInUserUID(ctx context.Context) (string, error)
- func (b *BaseExtensionImpl) GetPubSubTopic(m *pubsubtools.PubSubPayload) (string, error)
- func (b *BaseExtensionImpl) GetRunningEnvironment() string
- func (b *BaseExtensionImpl) GoogleCloudProjectIDEnvVarName() (string, error)
- func (b *BaseExtensionImpl) LoadDepsFromYAML() (*interserviceclient.DepsConfig, error)
- func (b *BaseExtensionImpl) NamespacePubsubIdentifier(serviceName string, topicID string, environment string, version string) string
- func (b *BaseExtensionImpl) NormalizeMSISDN(msisdn string) (*string, error)
- func (b *BaseExtensionImpl) PubSubHandlerPath() string
- func (b *BaseExtensionImpl) PublishToPubsub(ctx context.Context, pubsubClient *pubsub.Client, topicID string, ...) error
- func (b *BaseExtensionImpl) SetupISCclient(config interserviceclient.DepsConfig, serviceName string) (*interserviceclient.InterServiceClient, error)
- func (b *BaseExtensionImpl) SubscriptionIDs(topicIDs []string) map[string]string
- func (b *BaseExtensionImpl) VerifyPubSubJWTAndDecodePayload(w http.ResponseWriter, r *http.Request) (*pubsubtools.PubSubPayload, error)
- func (b *BaseExtensionImpl) WriteJSONResponse(w http.ResponseWriter, source interface{}, status int)
- type ISCClientExtension
- type ISCExtensionImpl
- type Options
- type PINExtension
- type PINExtensionImpl
Constants ¶
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 ¶
var DefaultHashFunction = sha512.New
DefaultHashFunction ...
Functions ¶
func ValidatePINDigits ¶
ValidatePINDigits validates user pin to ensure a PIN only contains digits
func ValidatePINLength ¶
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 ¶
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 ¶
func (b *BaseExtensionImpl) SetupISCclient(config interserviceclient.DepsConfig, serviceName string) (*interserviceclient.InterServiceClient, error)
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 ¶
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 ...
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