Documentation
¶
Overview ¶
Package diygoapi comprises application or business domain data types and functions.
Index ¶
- Constants
- func HandlerPatternFromRequest(r *http.Request) (string, error)
- func NewContextWithApp(ctx context.Context, a *App) context.Context
- func NewContextWithAuthParams(ctx context.Context, ap *AuthenticationParams) context.Context
- func NewContextWithRequestHandlerPattern(ctx context.Context, pattern string) context.Context
- func NewContextWithUser(ctx context.Context, u *User) context.Context
- func NewNullInt32(i int32) sql.NullInt32
- func NewNullInt64(i int64) sql.NullInt64
- func NewNullString(s string) sql.NullString
- func NewNullTime(t time.Time) sql.NullTime
- func NewNullUUID(i uuid.UUID) uuid.NullUUID
- func RequestHandlerPatternFromContext(ctx context.Context) (string, error)
- type APIKey
- type APIKeyGenerator
- type APIKeyResponse
- type App
- type AppResponse
- type AppServicer
- type Audit
- type Auth
- type AuthenticationParams
- type AuthenticationServicer
- type AuthorizationServicer
- type CreateAppRequest
- type CreateMovieRequest
- type CreateOrgRequest
- type CreatePermissionRequest
- type CreateRoleRequest
- type DBTX
- type Datastorer
- type DeleteResponse
- type FindPermissionRequest
- type GenesisRequest
- type GenesisResponse
- type GenesisServicer
- type LoggerRequest
- type LoggerResponse
- type LoggerServicer
- type Movie
- type MovieResponse
- type MovieServicer
- type Org
- type OrgKind
- type OrgResponse
- type OrgServicer
- type Permission
- type PermissionResponse
- type PermissionServicer
- type Person
- type PingResponse
- type PingServicer
- type Provider
- type ProviderInfo
- type ProviderTokenInfo
- type ProviderUserInfo
- type RegisterUserServicer
- type Role
- type RoleResponse
- type RoleServicer
- type SimpleAudit
- type TokenExchanger
- type UpdateAppRequest
- type UpdateMovieRequest
- type UpdateOrgRequest
- type User
- type UserResponse
Constants ¶
const ( // AppIDHeaderKey is the App ID header key AppIDHeaderKey string = "X-APP-ID" // ApiKeyHeaderKey is the API key header key ApiKeyHeaderKey string = "X-API-KEY" // AuthProviderHeaderKey is the Authorization provider header key AuthProviderHeaderKey string = "X-AUTH-PROVIDER" )
const BearerTokenType string = "Bearer"
BearerTokenType is used in authorization to access a resource
Variables ¶
This section is empty.
Functions ¶
func HandlerPatternFromRequest ¶ added in v0.53.0
HandlerPatternFromRequest is a helper function which returns the handler pattern from the request context.
func NewContextWithApp ¶
NewContextWithApp returns a new context with the given App
func NewContextWithAuthParams ¶
func NewContextWithAuthParams(ctx context.Context, ap *AuthenticationParams) context.Context
NewContextWithAuthParams returns a new context with the given AuthenticationParams
func NewContextWithRequestHandlerPattern ¶ added in v0.53.0
NewContextWithRequestHandlerPattern returns a new context with the given Handler pattern
func NewContextWithUser ¶
NewContextWithUser returns a new context with the given User
func NewNullInt32 ¶
NewNullInt32 returns a null if i == 0, otherwise it returns the int32 which was input.
func NewNullInt64 ¶
NewNullInt64 returns a null if i == 0, otherwise it returns the int64 which was input.
func NewNullString ¶
func NewNullString(s string) sql.NullString
NewNullString returns a null if s is empty, otherwise it returns the string which was input
func NewNullTime ¶
NewNullTime returns a null if t is the zero value for time.Time, otherwise it returns the time which was input
func NewNullUUID ¶
NewNullUUID returns a null if i == uuid.Nil, otherwise it returns the int32 which was input.
Types ¶
type APIKey ¶
type APIKey struct {
// contains filtered or unexported fields
}
APIKey is an API key for interacting with the system. The API key string is delivered to the client along with an App ID. The API Key acts as a password for the application.
func NewAPIKey ¶
NewAPIKey initializes an APIKey. It generates a random 128-bit (16 byte) base64 encoded string as an API key. The generated key is then encrypted using 256-bit AES-GCM and the encrypted bytes are added to the struct as well.
func NewAPIKeyFromCipher ¶
NewAPIKeyFromCipher initializes an APIKey given a ciphertext string.
func (*APIKey) Ciphertext ¶
Ciphertext returns the hex encoded text of the encrypted cipher bytes for the API key
func (*APIKey) DeactivationDate ¶
DeactivationDate returns the Deactivation Date for the API key
func (*APIKey) SetDeactivationDate ¶
SetDeactivationDate sets the deactivation date value to AppAPIkey TODO - try SetDeactivationDate as a candidate for generics with 1.18
func (*APIKey) SetStringAsDeactivationDate ¶
SetStringAsDeactivationDate sets the deactivation date value to AppAPIkey given a string in RFC3339 format
type APIKeyGenerator ¶
APIKeyGenerator creates a random, 128 API key string
type APIKeyResponse ¶
type APIKeyResponse struct { Key string `json:"key"` DeactivationDate string `json:"deactivation_date"` }
APIKeyResponse is the response fields for an API key
type App ¶
type App struct { ID uuid.UUID ExternalID secure.Identifier Org *Org Name string Description string Provider Provider ProviderClientID string APIKeys []APIKey }
App is an application that interacts with the system
func AppFromContext ¶
AppFromContext returns the App from the given context
func AppFromRequest ¶
AppFromRequest is a helper function which returns the App from the request context.
func (*App) ValidateKey ¶
ValidateKey determines if the app has a matching key for the input and if that key is valid
type AppResponse ¶
type AppResponse struct { ExternalID string `json:"external_id"` Name string `json:"name"` Description string `json:"description"` CreateAppExtlID string `json:"create_app_extl_id"` CreateUserFirstName string `json:"create_user_first_name"` CreateUserLastName string `json:"create_user_last_name"` CreateDateTime string `json:"create_date_time"` UpdateAppExtlID string `json:"update_app_extl_id"` UpdateUserFirstName string `json:"update_user_first_name"` UpdateUserLastName string `json:"update_user_last_name"` UpdateDateTime string `json:"update_date_time"` APIKeys []APIKeyResponse `json:"api_keys"` }
AppResponse is the response struct for an App
type AppServicer ¶
type AppServicer interface { Create(ctx context.Context, r *CreateAppRequest, adt Audit) (*AppResponse, error) Update(ctx context.Context, r *UpdateAppRequest, adt Audit) (*AppResponse, error) }
AppServicer manages the retrieval and manipulation of an App
type Auth ¶
type Auth struct { // ID is the unique identifier for authorization record in database ID uuid.UUID // User is the unique user associated to the authorization record. // // A Person can have one or more methods of authentication, however, // only one per authorization provider is allowed per User. User *User // Provider is the authentication provider Provider Provider // ProviderClientID is the external ID representing the Oauth2 client which // authenticated the user. ProviderClientID string // ProviderPersonID is the authentication provider's unique person/user ID. ProviderPersonID string // Provider Access Token ProviderAccessToken string // Provider Access Token Expiration Date/Time ProviderAccessTokenExpiry time.Time // Provider Refresh Token ProviderRefreshToken string }
Auth represents a user's authorization in the database. It captures the provider Oauth2 credentials. Users are linked to a Person. A single Person could authenticate through multiple providers.
type AuthenticationParams ¶
type AuthenticationParams struct { // Realm is a description of a protected area, used in the WWW-Authenticate header. Realm string // Provider is the authentication provider. Provider Provider // Token is the authentication token sent as part of Oauth2. Token *oauth2.Token }
AuthenticationParams is the parameters needed for authenticating a User.
func AuthParamsFromContext ¶
func AuthParamsFromContext(ctx context.Context) (*AuthenticationParams, error)
AuthParamsFromContext returns the AuthenticationParams from the given context
type AuthenticationServicer ¶
type AuthenticationServicer interface { // SelfRegister is used for first-time registration of a Person/User // in the system (associated with an Organization). This is "self // registration" as opposed to one person registering another person. SelfRegister(ctx context.Context, params *AuthenticationParams) (ur *UserResponse, err error) // FindExistingAuth looks up a User given a Provider and Access Token. // If a User is not found, an error is returned. FindExistingAuth(r *http.Request, realm string) (Auth, error) // FindAppByProviderClientID Finds an App given a Provider Client ID as part // of an Auth object. FindAppByProviderClientID(ctx context.Context, realm string, auth Auth) (a *App, err error) // DetermineAppContext checks to see if the request already has an app as part of // if it does, use that app as the app for session, if it does not, determine the // app based on the user's provider client ID. In either case, return a new context // with an app. If there is no app to be found for either, return an error. DetermineAppContext(ctx context.Context, auth Auth, realm string) (context.Context, error) // FindAppByAPIKey finds an app given its External ID and determines // if the given API key is a valid key for it. It is used as part of // app authentication. FindAppByAPIKey(r *http.Request, realm string) (*App, error) // AuthenticationParamExchange returns a ProviderInfo struct // after calling remote Oauth2 provider. AuthenticationParamExchange(ctx context.Context, params *AuthenticationParams) (*ProviderInfo, error) // NewAuthenticationParams parses the provider and authorization // headers and returns AuthenticationParams based on the results NewAuthenticationParams(r *http.Request, realm string) (*AuthenticationParams, error) }
AuthenticationServicer represents a service for managing authentication.
For this project, Oauth2 is used for user authentication. It is assumed that the actual user interaction is being orchestrated externally and the server endpoints are being called after an access token has already been retrieved from an authentication provider.
In addition, this project provides for a custom application authentication. If an endpoint request is sent using application credentials, then those will be used. If none are sent, then the client id from the access token must be registered in the system and that is used as the calling application. The latter is likely the more common use case.
type AuthorizationServicer ¶
type AuthorizationServicer interface {
Authorize(r *http.Request, lgr zerolog.Logger, adt Audit) error
}
AuthorizationServicer represents a service for managing authorization.
type CreateAppRequest ¶
type CreateAppRequest struct { Name string `json:"name"` Description string `json:"description"` Oauth2Provider string `json:"oauth2_provider"` Oauth2ProviderClientID string `json:"oauth2_provider_client_id"` }
CreateAppRequest is the request struct for Creating an App
func (CreateAppRequest) Validate ¶
func (r CreateAppRequest) Validate() error
Validate determines whether the CreateAppRequest has proper data to be considered valid
type CreateMovieRequest ¶
type CreateMovieRequest struct { Title string `json:"title"` Rated string `json:"rated"` Released string `json:"release_date"` RunTime int `json:"run_time"` Director string `json:"director"` Writer string `json:"writer"` }
CreateMovieRequest is the request struct for Creating a Movie
type CreateOrgRequest ¶
type CreateOrgRequest struct { Name string `json:"name"` Description string `json:"description"` Kind string `json:"kind"` CreateAppRequest *CreateAppRequest `json:"app"` }
CreateOrgRequest is the request struct for Creating an Org
func (CreateOrgRequest) Validate ¶
func (r CreateOrgRequest) Validate() error
Validate determines whether the CreateOrgRequest has proper data to be considered valid
type CreatePermissionRequest ¶
type CreatePermissionRequest struct { // A human-readable string which represents a resource (e.g. an HTTP route or document, etc.). Resource string `json:"resource"` // A string representing the action taken on the resource (e.g. POST, GET, edit, etc.) Operation string `json:"operation"` // A description of what the permission is granting, e.g. "grants ability to edit a billing document". Description string `json:"description"` // A boolean denoting whether the permission is active (true) or not (false). Active bool `json:"active"` }
CreatePermissionRequest is the request struct for creating a permission
type CreateRoleRequest ¶
type CreateRoleRequest struct { // A human-readable code which represents the role. Code string `json:"role_cd"` // A longer description of the role. Description string `json:"role_description"` // A boolean denoting whether the role is active (true) or not (false). Active bool `json:"active"` // The list of permissions to be given to the role Permissions []*FindPermissionRequest }
CreateRoleRequest is the request struct for creating a role
type DBTX ¶
type DBTX interface { Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) Query(context.Context, string, ...interface{}) (pgx.Rows, error) QueryRow(context.Context, string, ...interface{}) pgx.Row }
DBTX interface mirrors the interface generated by https://github.com/kyleconroy/sqlc to allow passing a Pool or a Tx
type Datastorer ¶
type Datastorer interface { // Ping pings the DB pool. Ping(ctx context.Context) error // BeginTx starts a pgx.Tx using the input context BeginTx(ctx context.Context) (pgx.Tx, error) // RollbackTx rolls back the input pgx.Tx RollbackTx(ctx context.Context, tx pgx.Tx, err error) error // CommitTx commits the Tx CommitTx(ctx context.Context, tx pgx.Tx) error }
Datastorer is an interface for working with the Database
type DeleteResponse ¶
DeleteResponse is the general response struct for things which have been deleted
type FindPermissionRequest ¶
type FindPermissionRequest struct { // Unique External ID to be given to outside callers. ExternalID string `json:"external_id"` // A human-readable string which represents a resource (e.g. an HTTP route or document, etc.). Resource string `json:"resource"` // A string representing the action taken on the resource (e.g. POST, GET, edit, etc.) Operation string `json:"operation"` }
FindPermissionRequest is the response struct for finding a permission
type GenesisRequest ¶
type GenesisRequest struct { User struct { // Provider: The Oauth2 provider. Provider string `json:"provider"` // Token: The Oauth2 token to be used to create the user. Token string `json:"token"` } `json:"user"` UserInitiatedOrg CreateOrgRequest `json:"org"` // PermissionRequests: The list of permissions to be created as part of Genesis CreatePermissionRequests []CreatePermissionRequest `json:"permissions"` // CreateRoleRequests: The list of Roles to be created as part of Genesis CreateRoleRequests []CreateRoleRequest `json:"roles"` }
GenesisRequest is the request struct for the genesis service
type GenesisResponse ¶
type GenesisResponse struct { Principal *OrgResponse `json:"principal"` Test *OrgResponse `json:"test"` UserInitiated *OrgResponse `json:"userInitiated,omitempty"` }
GenesisResponse contains both the Genesis response and the Test response
type GenesisServicer ¶
type GenesisServicer interface { // Arche creates the initial seed data in the database. Arche(ctx context.Context, r *GenesisRequest) (GenesisResponse, error) // ReadConfig reads the local config file generated as part of Seed (when run locally). // Is only a utility to help with local testing. ReadConfig() (GenesisResponse, error) }
GenesisServicer initializes the database with dependent data
type LoggerRequest ¶
type LoggerRequest struct { GlobalLogLevel string `json:"global_log_level"` LogErrorStack string `json:"log_error_stack"` }
LoggerRequest is the request struct for the app logger
type LoggerResponse ¶
type LoggerResponse struct { LoggerMinimumLevel string `json:"logger_minimum_level"` GlobalLogLevel string `json:"global_log_level"` LogErrorStack bool `json:"log_error_stack"` }
LoggerResponse is the response struct for the current state of the app logger
type LoggerServicer ¶
type LoggerServicer interface { Read() *LoggerResponse Update(r *LoggerRequest) (*LoggerResponse, error) }
LoggerServicer reads and updates the logger state
type Movie ¶
type Movie struct { ID uuid.UUID ExternalID secure.Identifier Title string Rated string Released time.Time RunTime int Director string Writer string }
Movie holds details of a movie
type MovieResponse ¶
type MovieResponse struct { ExternalID string `json:"external_id"` Title string `json:"title"` Rated string `json:"rated"` Released string `json:"release_date"` RunTime int `json:"run_time"` Director string `json:"director"` Writer string `json:"writer"` CreateAppExtlID string `json:"create_app_extl_id"` CreateUserFirstName string `json:"create_user_first_name"` CreateUserLastName string `json:"create_user_last_name"` CreateDateTime string `json:"create_date_time"` UpdateAppExtlID string `json:"update_app_extl_id"` UpdateUserFirstName string `json:"update_user_first_name"` UpdateUserLastName string `json:"update_user_last_name"` UpdateDateTime string `json:"update_date_time"` }
MovieResponse is the response struct for a Movie
type MovieServicer ¶
type MovieServicer interface { Create(ctx context.Context, r *CreateMovieRequest, adt Audit) (*MovieResponse, error) Update(ctx context.Context, r *UpdateMovieRequest, adt Audit) (*MovieResponse, error) Delete(ctx context.Context, extlID string) (DeleteResponse, error) FindMovieByExternalID(ctx context.Context, extlID string) (*MovieResponse, error) FindAllMovies(ctx context.Context) ([]*MovieResponse, error) }
MovieServicer is used to create, read, update and delete movies.
type Org ¶
type Org struct { // ID: The unique identifier ID uuid.UUID // External ID: The unique external identifier ExternalID secure.Identifier // Name: The organization name Name string // Description: A longer description of the organization Description string // Kind: a way of classifying organizations Kind *OrgKind }
Org represents an Organization (company, institution or any other organized body of people with a particular purpose)
type OrgKind ¶
type OrgKind struct { // ID: The unique identifier ID uuid.UUID // External ID: The unique external identifier ExternalID string // Description: A longer description of the organization kind Description string }
OrgKind is a way of classifying an organization. Examples are Genesis, Test, Standard
type OrgResponse ¶
type OrgResponse struct { ExternalID string `json:"external_id"` Name string `json:"name"` KindExternalID string `json:"kind_description"` Description string `json:"description"` CreateAppExtlID string `json:"create_app_extl_id"` CreateUserFirstName string `json:"create_user_first_name"` CreateUserLastName string `json:"create_user_last_name"` CreateDateTime string `json:"create_date_time"` UpdateAppExtlID string `json:"update_app_extl_id"` UpdateUserFirstName string `json:"update_user_first_name"` UpdateUserLastName string `json:"update_user_last_name"` UpdateDateTime string `json:"update_date_time"` App *AppResponse `json:"app,omitempty"` }
OrgResponse is the response struct for an Org. It contains only one app (even though an org can have many apps). This app is only present in the response when creating an org and accompanying app. I may change this later to be different response structs for different purposes, but for now, this works.
type OrgServicer ¶
type OrgServicer interface { // Create manages the creation of an Org (and optional app) Create(ctx context.Context, r *CreateOrgRequest, adt Audit) (*OrgResponse, error) Update(ctx context.Context, r *UpdateOrgRequest, adt Audit) (*OrgResponse, error) Delete(ctx context.Context, extlID string) (DeleteResponse, error) FindAll(ctx context.Context) ([]*OrgResponse, error) FindByExternalID(ctx context.Context, extlID string) (*OrgResponse, error) }
OrgServicer manages the retrieval and manipulation of an Org
type Permission ¶
type Permission struct { // ID is the unique ID for the Permission. ID uuid.UUID // ExternalID is the unique External ID to be given to outside callers. ExternalID secure.Identifier // Resource is a human-readable string which represents a resource (e.g. an HTTP route or document, etc.). Resource string // Operation represents the action taken on the resource (e.g. POST, GET, edit, etc.) Operation string // Description is what the permission is granting, e.g. "grants ability to edit a billing document". Description string // Active is a boolean denoting whether the permission is active (true) or not (false). Active bool }
Permission stores an approval of a mode of access to a resource.
func (Permission) Validate ¶
func (p Permission) Validate() error
Validate determines if the Permission is valid
type PermissionResponse ¶
type PermissionResponse struct { // Unique External ID to be given to outside callers. ExternalID string `json:"external_id"` // A human-readable string which represents a resource (e.g. an HTTP route or document, etc.). Resource string `json:"resource"` // A string representing the action taken on the resource (e.g. POST, GET, edit, etc.) Operation string `json:"operation"` // A description of what the permission is granting, e.g. "grants ability to edit a billing document". Description string `json:"description"` // A boolean denoting whether the permission is active (true) or not (false). Active bool `json:"active"` }
PermissionResponse is the response struct for a permission
type PermissionServicer ¶
type PermissionServicer interface { Create(ctx context.Context, r *CreatePermissionRequest, adt Audit) (*PermissionResponse, error) FindAll(ctx context.Context) ([]*PermissionResponse, error) Delete(ctx context.Context, extlID string) (DeleteResponse, error) }
PermissionServicer allows for creating, updating, reading and deleting a Permission
type Person ¶
type Person struct { // ID: The unique identifier of the Person. ID uuid.UUID // ExternalID: unique external identifier of the Person ExternalID secure.Identifier // Users: All the users that are linked to the Person // (e.g. a GitHub user, a Google user, etc.). Users []*User }
Person - from Wikipedia: "A person (plural people or persons) is a being that has certain capacities or attributes such as reason, morality, consciousness or self-consciousness, and being a part of a culturally established form of social relations such as kinship, ownership of property, or legal responsibility.
The defining features of personhood and, consequently, what makes a person count as a person, differ widely among cultures and contexts."
A Person can have multiple Users.
type PingResponse ¶
type PingResponse struct {
DBUp bool `json:"db_up"`
}
PingResponse is the response struct for the PingService
type PingServicer ¶
type PingServicer interface {
Ping(ctx context.Context, lgr zerolog.Logger) PingResponse
}
PingServicer pings the database and responds whether it is up or down
type Provider ¶
type Provider uint8
Provider defines the provider of authorization (Google, GitHub, Apple, auth0, etc.).
Only Google is used currently.
Provider of authorization
The app uses Oauth2 to authorize users with one of the following Providers
func ParseProvider ¶
ParseProvider initializes a Provider given a case-insensitive string
type ProviderInfo ¶
type ProviderInfo struct { Provider Provider TokenInfo *ProviderTokenInfo UserInfo *ProviderUserInfo }
ProviderInfo contains information returned from an authorization provider
type ProviderTokenInfo ¶
type ProviderTokenInfo struct { // Token is the Oauth2 token. For inbound requests, only the // Access Token is given in the Authorization header, so the // other details (Refresh Token, Token Type, Expiry) must be // retrieved from a 3rd party service. The token's Expiry is // a calculated time of expiration (estimated). This is a moving // target as some providers send the actual time of expiration, // others just send seconds until expiration, which means it's // a calculation and won't have perfect precision. Token *oauth2.Token // Client ID: External ID representing the Oauth2 client which // authenticated the user. ClientID string // Scope: The space separated list of scopes granted to this token. Scope string // Audience: Who is the intended audience for this token. In general the // same as issued_to. Audience string `json:"audience,omitempty"` // IssuedTo: To whom was the token issued to. In general the same as // audience. IssuedTo string `json:"issued_to,omitempty"` }
ProviderTokenInfo contains non-user information gleaned from the Oauth2 provider's access token and subsequent calls to get information about a person using it. See ProviderUserInfo for user information.
type ProviderUserInfo ¶
type ProviderUserInfo struct { // ID: The obfuscated ID of the user assigned by the authentication provider. ExternalID string // Email: The user's email address. Email string // VerifiedEmail: Boolean flag which is true if the email address is // verified. Present only if the email scope is present in the request. VerifiedEmail bool // NamePrefix: The name prefix for the Profile (e.g. Mx., Ms., Mr., etc.) NamePrefix string // MiddleName: The person's middle name. MiddleName string // FirstName: The user's first name. FirstName string // FamilyName: The user's last name. LastName string // FullName: The user's full name. FullName string // NameSuffix: The name suffix for the person's name (e.g. "PhD", "CCNA", "OBE"). // Other examples include generational designations like "Sr." and "Jr." and "I", "II", "III", etc. NameSuffix string // Nickname: The person's nickname Nickname string // Gender: The user's gender. TODO - setup Gender properly. not binary. Gender string // BirthDate: The full birthdate of a person (e.g. Dec 18, 1953) BirthDate time.Time // Hd: The hosted domain e.g. example.com if the user is Google apps // user. HostedDomain string // Link: URL of the profile page. ProfileLink string // Locale: The user's preferred locale. Locale string // Picture: URL of the user's picture image. Picture string }
ProviderUserInfo contains common fields from the various Oauth2 providers. Currently only using Google, so looks a lot like Google's.
type RegisterUserServicer ¶
RegisterUserServicer registers a new user
type Role ¶
type Role struct { // The unique ID for the Role. ID uuid.UUID // Unique External ID to be given to outside callers. ExternalID secure.Identifier // A human-readable code which represents the role. Code string // A longer description of the role. Description string // A boolean denoting whether the role is active (true) or not (false). Active bool // Permissions is the list of permissions allowed for the role. Permissions []*Permission }
Role is a job function or title which defines an authority level.
type RoleResponse ¶
type RoleResponse struct { // Unique External ID to be given to outside callers. ExternalID string `json:"external_id"` // A human-readable code which represents the role. Code string `json:"role_cd"` // A longer description of the role. Description string `json:"role_description"` // A boolean denoting whether the role is active (true) or not (false). Active bool `json:"active"` // Permissions is the list of permissions allowed for the role. Permissions []*Permission }
RoleResponse is the response struct for a Role.
type RoleServicer ¶
type RoleServicer interface {
Create(ctx context.Context, r *CreateRoleRequest, adt Audit) (*RoleResponse, error)
}
RoleServicer allows for creating, updating, reading and deleting a Role as well as assigning permissions and users to it.
type SimpleAudit ¶
SimpleAudit captures the first time a record was written as well as the last time the record was updated. The first time a record is written Create and Update will be identical.
type TokenExchanger ¶
type TokenExchanger interface {
Exchange(ctx context.Context, realm string, provider Provider, token *oauth2.Token) (*ProviderInfo, error)
}
TokenExchanger exchanges an oauth2.Token for a ProviderUserInfo struct populated with information retrieved from an authentication provider.
type UpdateAppRequest ¶
type UpdateAppRequest struct { ExternalID string Name string `json:"name"` Description string `json:"description"` }
UpdateAppRequest is the request struct for Updating an App
type UpdateMovieRequest ¶
type UpdateMovieRequest struct { ExternalID string Title string `json:"title"` Rated string `json:"rated"` Released string `json:"release_date"` RunTime int `json:"run_time"` Director string `json:"director"` Writer string `json:"writer"` }
UpdateMovieRequest is the request struct for updating a Movie
type UpdateOrgRequest ¶
type UpdateOrgRequest struct { ExternalID string Name string `json:"name"` Description string `json:"description"` }
UpdateOrgRequest is the request struct for Updating an Org
type User ¶
type User struct { // ID: The unique identifier for the Person's profile ID uuid.UUID // ExternalID: unique external identifier of the User ExternalID secure.Identifier // NamePrefix: The name prefix for the Profile (e.g. Mx., Ms., Mr., etc.) NamePrefix string // FirstName: The person's first name. FirstName string // MiddleName: The person's middle name. MiddleName string // LastName: The person's last name. LastName string // FullName: The person's full name. FullName string // NameSuffix: The name suffix for the person's name (e.g. "PhD", "CCNA", "OBE"). // Other examples include generational designations like "Sr." and "Jr." and "I", "II", "III", etc. NameSuffix string // Nickname: The person's nickname Nickname string // Gender: The user's gender. TODO - setup Gender properly. not binary. Gender string // Email: The primary email for the User Email string // CompanyName: The Company Name that the person works at CompanyName string // CompanyDepartment: is the department at the company that the person works at CompanyDepartment string // JobTitle: The person's Job Title JobTitle string // BirthDate: The full birthdate of a person (e.g. Dec 18, 1953) BirthDate time.Time // LanguagePreferences is the user's language tag preferences. LanguagePreferences []language.Tag // HostedDomain: The hosted domain e.g. example.com. HostedDomain string // PictureURL: URL of the person's picture image for the profile. PictureURL string // ProfileLink: URL of the profile page. ProfileLink string // Source: The origin of the User (e.g. Google Oauth2, Apple Oauth2, etc.) Source string }
User - from Wikipedia: "A user is a person who utilizes a computer or network service." In the context of this project, given that we allow Persons to authenticate with multiple providers, a User is akin to a persona (Wikipedia - "The word persona derives from Latin, where it originally referred to a theatrical mask. On the social web, users develop virtual personas as online identities.") and as such, a Person can have one or many Users (for instance, I can have a GitHub user and a Google user, but I am just one Person).
As a general, practical matter, most operations are considered at the User level. For instance, roles are assigned at the user level instead of the Person level, which allows for more fine-grained access control.
func NewUserFromProviderInfo ¶ added in v0.52.0
func NewUserFromProviderInfo(pi *ProviderInfo, lm language.Matcher) *User
NewUserFromProviderInfo creates a new User struct to be used in db user creation
func UserFromContext ¶ added in v0.52.0
UserFromContext returns the User from the given Context
func UserFromRequest ¶
UserFromRequest returns the User from the request context
type UserResponse ¶ added in v0.52.0
type UserResponse struct { // ID: The unique identifier for the Person's profile ID uuid.UUID // ExternalID: unique external identifier of the User ExternalID secure.Identifier `json:"external_id"` // NamePrefix: The name prefix for the Profile (e.g. Mx., Ms., Mr., etc.) NamePrefix string `json:"name_prefix"` // FirstName: The person's first name. FirstName string `json:"first_name"` // MiddleName: The person's middle name. MiddleName string `json:"middle_name"` // LastName: The person's last name. LastName string `json:"last_name"` // FullName: The person's full name. FullName string `json:"full_name"` // NameSuffix: The name suffix for the person's name (e.g. "PhD", "CCNA", "OBE"). // Other examples include generational designations like "Sr." and "Jr." and "I", "II", "III", etc. NameSuffix string `json:"name_suffix"` // Nickname: The person's nickname Nickname string `json:"nickname"` // Email: The primary email for the User Email string `json:"email"` // CompanyName: The Company Name that the person works at CompanyName string `json:"company_name"` // CompanyDepartment: is the department at the company that the person works at CompanyDepartment string `json:"company_department"` // JobTitle: The person's Job Title JobTitle string `json:"job_title"` // BirthDate: The full birthdate of a person (e.g. Dec 18, 1953) BirthDate time.Time `json:"birth_date"` // LanguagePreferences is the user's language tag preferences. LanguagePreferences []language.Tag `json:"language_preferences"` // HostedDomain: The hosted domain e.g. example.com. HostedDomain string `json:"hosted_domain"` // PictureURL: URL of the person's picture image for the profile. PictureURL string `json:"picture_url"` // ProfileLink: URL of the profile page. ProfileLink string `json:"profile_link"` // Source: The origin of the User (e.g. Google Oauth2, Apple Oauth2, etc.) Source string `json:"source"` }
UserResponse - from Wikipedia: "A user is a person who utilizes a computer or network service." In the context of this project, given that we allow Persons to authenticate with multiple providers, a User is akin to a persona (Wikipedia - "The word persona derives from Latin, where it originally referred to a theatrical mask. On the social web, users develop virtual personas as online identities.") and as such, a Person can have one or many Users (for instance, I can have a GitHub user and a Google user, but I am just one Person).
As a general, practical matter, most operations are considered at the User level. For instance, roles are assigned at the user level instead of the Person level, which allows for more fine-grained access control.
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
Package errs is a modified copy of the upspin.io/errors package.
|
Package errs is a modified copy of the upspin.io/errors package. |
Package gateway and packages within provide abstractions for interacting with external systems or resources
|
Package gateway and packages within provide abstractions for interacting with external systems or resources |
Package logger has helpers to setup a zerolog.Logger
|
Package logger has helpers to setup a zerolog.Logger |
Package server provides a preconfigured HTTP server.
|
Package server provides a preconfigured HTTP server. |
driver
Package driver defines an interface for custom HTTP listeners.
|
Package driver defines an interface for custom HTTP listeners. |
Package service orchestrates components between handlers and other packages (datastore, gateway, domain, etc.)
|
Package service orchestrates components between handlers and other packages (datastore, gateway, domain, etc.) |
Package sqldb is used to interact with a datastore.
|
Package sqldb is used to interact with a datastore. |