Documentation
¶
Overview ¶
Package service orchestrates components between handlers and other packages (datastore, gateway, domain, etc.)
Index ¶
- Constants
- type APIKeyResponse
- type AppResponse
- type AppService
- func (s AppService) Create(ctx context.Context, r *CreateAppRequest, adt audit.Audit) (ar AppResponse, err error)
- func (s AppService) Delete(ctx context.Context, extlID string) (dr DeleteResponse, err error)
- func (s AppService) FindAll(ctx context.Context) (sar []AppResponse, err error)
- func (s AppService) FindByExternalID(ctx context.Context, extlID string) (ar AppResponse, err error)
- func (s AppService) Update(ctx context.Context, r *UpdateAppRequest, adt audit.Audit) (ar AppResponse, err error)
- type Authorizer
- type CreateAppRequest
- type CreateMovieRequest
- type CreateMovieService
- type CreateOrgRequest
- type CryptoRandomGenerator
- type DBAuthorizer
- type DBTX
- type Datastorer
- type DeleteMovieService
- type DeleteResponse
- type FindMovieService
- type FindUserParams
- type FullGenesisResponse
- type GenesisRequest
- type GenesisResponse
- type GenesisService
- type GoogleOauth2TokenConverter
- type LoggerRequest
- type LoggerResponse
- type LoggerService
- type MiddlewareService
- func (s MiddlewareService) Authorize(lgr zerolog.Logger, r *http.Request, sub audit.Audit) error
- func (s MiddlewareService) FindAppByAPIKey(ctx context.Context, realm, appExtlID, key string) (app.App, error)
- func (s MiddlewareService) FindUserByOauth2Token(ctx context.Context, params FindUserParams) (user.User, error)
- type MovieResponse
- type OrgResponse
- type OrgService
- func (s OrgService) Create(ctx context.Context, r *CreateOrgRequest, adt audit.Audit) (or OrgResponse, err error)
- func (s OrgService) Delete(ctx context.Context, extlID string) (dr DeleteResponse, err error)
- func (s OrgService) FindAll(ctx context.Context) ([]OrgResponse, error)
- func (s OrgService) FindByExternalID(ctx context.Context, extlID string) (OrgResponse, error)
- func (s OrgService) Update(ctx context.Context, r *UpdateOrgRequest, adt audit.Audit) (or OrgResponse, err error)
- type PermissionService
- type PingResponse
- type PingService
- type RegisterUserService
- type RoleService
- type TestResponse
- type UpdateAppRequest
- type UpdateMovieRequest
- type UpdateMovieService
- type UpdateOrgRequest
Constants ¶
const ( // PrincipalOrgName is the first organization created as part of // the Genesis event and is the central administration org. PrincipalOrgName = "Principal" // PrincipalAppName is the first app created as part of the // Genesis event and is the central administration app. PrincipalAppName = "Developer Dashboard" // PrincipalTestUsername is for the test user created as part of the // Genesis event and is needed for testing some features of the Principal org. PrincipalTestUsername = "pgabriel" // TestOrgName is the organization created as part of the Genesis // event solely for the purpose of testing TestOrgName = "Test Org" // TestAppName is the test app created as part of the Genesis // event solely for the purpose of testing TestAppName = "Test App" // TestUsername is the test user created as part of the Genesis // event solely for the purpose of testing TestUsername = "shackett" // LocalJSONGenesisRequestFile is the local JSON Genesis Request File path // (relative to project root) LocalJSONGenesisRequestFile = "./config/genesis/request.json" // LocalJSONGenesisResponseFile is the local JSON Genesis Response File path // (relative to project root) LocalJSONGenesisResponseFile = "./config/genesis/response.json" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyResponse ¶ added in v0.39.0
type APIKeyResponse struct {
Key string `json:"key"`
DeactivationDate string `json:"deactivation_date"`
}
APIKeyResponse is the response fields for an API key
type AppResponse ¶ added in v0.39.0
type AppResponse struct {
ExternalID string `json:"external_id"`
Name string `json:"name"`
Description string `json:"description"`
CreateAppExtlID string `json:"create_app_extl_id"`
CreateUsername string `json:"create_username"`
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"`
UpdateUsername string `json:"update_username"`
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 AppService ¶ added in v0.41.0
type AppService struct {
Datastorer Datastorer
RandomStringGenerator CryptoRandomGenerator
EncryptionKey *[32]byte
}
AppService is a service for creating an App
func (AppService) Create ¶ added in v0.41.0
func (s AppService) Create(ctx context.Context, r *CreateAppRequest, adt audit.Audit) (ar AppResponse, err error)
Create is used to create an App
func (AppService) Delete ¶ added in v0.41.0
func (s AppService) Delete(ctx context.Context, extlID string) (dr DeleteResponse, err error)
Delete is used to delete an App
func (AppService) FindAll ¶ added in v0.42.0
func (s AppService) FindAll(ctx context.Context) (sar []AppResponse, err error)
FindAll is used to list all apps in the datastore
func (AppService) FindByExternalID ¶ added in v0.42.0
func (s AppService) FindByExternalID(ctx context.Context, extlID string) (ar AppResponse, err error)
FindByExternalID is used to find an App by its External ID
func (AppService) Update ¶ added in v0.41.0
func (s AppService) Update(ctx context.Context, r *UpdateAppRequest, adt audit.Audit) (ar AppResponse, err error)
Update is used to update an App. API Keys for an App cannot be updated.
type Authorizer ¶ added in v0.39.0
Authorizer determines if an app/user (as part of an Audit) is authorized for the route in the request
type CreateAppRequest ¶ added in v0.39.0
CreateAppRequest is the request struct for Creating an App
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 CreateMovieService ¶
type CreateMovieService struct {
Datastorer Datastorer
}
CreateMovieService is a service for creating a Movie
func (CreateMovieService) Create ¶
func (s CreateMovieService) Create(ctx context.Context, r *CreateMovieRequest, adt audit.Audit) (mr MovieResponse, err error)
Create is used to create a Movie
type CreateOrgRequest ¶ added in v0.39.0
type CreateOrgRequest struct {
Name string `json:"name"`
Description string `json:"description"`
Kind string `json:"kind"`
}
CreateOrgRequest is the request struct for Creating an Org
type CryptoRandomGenerator ¶ added in v0.39.0
type CryptoRandomGenerator interface {
RandomBytes(n int) ([]byte, error)
RandomString(n int) (string, error)
}
CryptoRandomGenerator is the interface that generates random data
type DBAuthorizer ¶ added in v0.43.0
type DBAuthorizer struct {
Datastorer Datastorer
}
DBAuthorizer determines authorization for a user by running sql against tables in the database
func (DBAuthorizer) Authorize ¶ added in v0.43.0
Authorize ensures that a subject (user.User) can perform a particular action on a resource, e.g. subject otto.maddox711@gmail.com can read (GET) the resource /api/v1/movies (path).
The http.Request context is used to determine the route/path information and must be issued through the gorilla/mux library.
type DBTX ¶ added in v0.39.0
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 ¶ added in v0.39.0
type Datastorer interface {
// Pool returns *pgxpool.Pool
Pool() *pgxpool.Pool
// 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 DeleteMovieService ¶
type DeleteMovieService struct {
Datastorer Datastorer
}
DeleteMovieService is a service for deleting a Movie
func (DeleteMovieService) Delete ¶
func (s DeleteMovieService) Delete(ctx context.Context, extlID string) (dr DeleteResponse, err error)
Delete is used to delete a movie
type DeleteResponse ¶ added in v0.41.0
DeleteResponse is the response struct for things that have been deleted
type FindMovieService ¶
type FindMovieService struct {
Datastorer Datastorer
}
FindMovieService is a service for reading Movies from the DB
func (FindMovieService) FindAllMovies ¶
func (s FindMovieService) FindAllMovies(ctx context.Context) (smr []MovieResponse, err error)
FindAllMovies is used to list all movies in the db
func (FindMovieService) FindMovieByID ¶
func (s FindMovieService) FindMovieByID(ctx context.Context, extlID string) (mr MovieResponse, err error)
FindMovieByID is used to find an individual movie
type FindUserParams ¶ added in v0.39.0
type FindUserParams struct {
Realm string
App app.App
Provider auth.Provider
Token oauth2.Token
RetrieveFromDB bool
}
FindUserParams is parameters for finding a User
type FullGenesisResponse ¶ added in v0.40.0
type FullGenesisResponse struct {
GenesisResponse GenesisResponse `json:"principal"`
TestResponse TestResponse `json:"test"`
}
FullGenesisResponse contains both the Genesis response and the Test response
type GenesisRequest ¶ added in v0.40.0
type GenesisRequest struct {
// Email: The user's email address.
Email string `json:"email"`
// FirstName: The user's first name.
FirstName string `json:"first_name"`
// LastName: The user's last name.
LastName string `json:"last_name"`
}
GenesisRequest is the request struct for the genesis service
type GenesisResponse ¶ added in v0.40.0
type GenesisResponse struct {
OrgResponse OrgResponse `json:"org"`
AppResponse AppResponse `json:"app"`
}
GenesisResponse is the response struct for the genesis org and app
type GenesisService ¶ added in v0.40.0
type GenesisService struct {
Datastorer Datastorer
RandomStringGenerator CryptoRandomGenerator
EncryptionKey *[32]byte
}
GenesisService seeds the database. It should be run only once on initial database setup.
func (GenesisService) ReadConfig ¶ added in v0.43.0
func (s GenesisService) ReadConfig() (FullGenesisResponse, error)
ReadConfig reads the generated config file from Genesis and returns it in the response body
func (GenesisService) Seed ¶ added in v0.40.0
func (s GenesisService) Seed(ctx context.Context, r *GenesisRequest) (fgr FullGenesisResponse, err error)
Seed method seeds the database
type GoogleOauth2TokenConverter ¶ added in v0.39.0
type GoogleOauth2TokenConverter interface {
Convert(ctx context.Context, realm string, token oauth2.Token) (authgateway.ProviderUserInfo, error)
}
GoogleOauth2TokenConverter converts an oauth2.Token to an authgateway.Userinfo struct
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 LoggerService ¶
LoggerService reads and updates the logger state
func (LoggerService) Read ¶
func (ls LoggerService) Read() LoggerResponse
ReadLogger handles GET requests for the /logger endpoint
func (LoggerService) Update ¶
func (ls LoggerService) Update(r *LoggerRequest) (LoggerResponse, error)
Update handles PUT requests for the /logger endpoint and updates the logger globals
type MiddlewareService ¶ added in v0.41.0
type MiddlewareService struct {
Datastorer Datastorer
GoogleOauth2TokenConverter GoogleOauth2TokenConverter
Authorizer Authorizer
EncryptionKey *[32]byte
}
MiddlewareService holds methods used by server middleware handlers
func (MiddlewareService) Authorize ¶ added in v0.41.0
Authorize determines if an app/user (as part of an Audit) is authorized for the route in the request
func (MiddlewareService) FindAppByAPIKey ¶ added in v0.41.0
func (s MiddlewareService) FindAppByAPIKey(ctx context.Context, realm, appExtlID, key string) (app.App, 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
func (MiddlewareService) FindUserByOauth2Token ¶ added in v0.41.0
func (s MiddlewareService) FindUserByOauth2Token(ctx context.Context, params FindUserParams) (user.User, error)
FindUserByOauth2Token retrieves a users' identity from a Provider and then retrieves the associated registered user from the datastore
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"`
CreateUsername string `json:"create_username"`
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"`
UpdateUsername string `json:"update_username"`
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 OrgResponse ¶ added in v0.39.0
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"`
CreateUsername string `json:"create_username"`
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"`
UpdateUsername string `json:"update_username"`
UpdateUserFirstName string `json:"update_user_first_name"`
UpdateUserLastName string `json:"update_user_last_name"`
UpdateDateTime string `json:"update_date_time"`
}
OrgResponse is the response struct for an Org
type OrgService ¶ added in v0.41.0
type OrgService struct {
Datastorer Datastorer
}
OrgService is a service for creating, reading, updating and deleting an Org
func (OrgService) Create ¶ added in v0.41.0
func (s OrgService) Create(ctx context.Context, r *CreateOrgRequest, adt audit.Audit) (or OrgResponse, err error)
Create is used to create an Org
func (OrgService) Delete ¶ added in v0.41.0
func (s OrgService) Delete(ctx context.Context, extlID string) (dr DeleteResponse, err error)
Delete is used to delete an Org
func (OrgService) FindAll ¶ added in v0.41.0
func (s OrgService) FindAll(ctx context.Context) ([]OrgResponse, error)
FindAll is used to list all orgs in the datastore
func (OrgService) FindByExternalID ¶ added in v0.41.0
func (s OrgService) FindByExternalID(ctx context.Context, extlID string) (OrgResponse, error)
FindByExternalID is used to find an Org by its External ID
func (OrgService) Update ¶ added in v0.41.0
func (s OrgService) Update(ctx context.Context, r *UpdateOrgRequest, adt audit.Audit) (or OrgResponse, err error)
Update is used to update an Org
type PermissionService ¶ added in v0.43.0
type PermissionService struct {
Datastorer Datastorer
}
PermissionService is a service for creating, reading, updating and deleting a Permission
func (PermissionService) Create ¶ added in v0.43.0
func (s PermissionService) Create(ctx context.Context, r *auth.Permission, adt audit.Audit) (p auth.Permission, err error)
Create is used to create a Permission
func (PermissionService) FindAll ¶ added in v0.43.0
func (s PermissionService) FindAll(ctx context.Context) ([]auth.Permission, error)
FindAll retrieves all permissions
type PingResponse ¶
type PingResponse struct {
DBUp bool `json:"db_up"`
}
PingResponse is the response struct for the PingService
type PingService ¶
type PingService struct {
Datastorer Datastorer
}
PingService pings the database.
func (PingService) Ping ¶
func (p PingService) Ping(ctx context.Context, lgr zerolog.Logger) PingResponse
Ping method pings the database
type RegisterUserService ¶ added in v0.40.0
type RegisterUserService struct {
Datastorer Datastorer
}
RegisterUserService represents a service for managing new User registration.
func (RegisterUserService) SelfRegister ¶ added in v0.40.0
SelfRegister is used to register a User with an Organization. This is "self registration" as opposed to one user registering another user.
type RoleService ¶ added in v0.43.0
type RoleService struct {
Datastorer Datastorer
}
type TestResponse ¶ added in v0.40.0
type TestResponse struct {
OrgResponse OrgResponse `json:"org"`
AppResponse AppResponse `json:"app"`
}
TestResponse is the response struct for the test org and app
type UpdateAppRequest ¶ added in v0.41.0
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 UpdateMovieService ¶
type UpdateMovieService struct {
Datastorer Datastorer
}
UpdateMovieService is a service for updating a Movie
func (UpdateMovieService) Update ¶
func (s UpdateMovieService) Update(ctx context.Context, r *UpdateMovieRequest, adt audit.Audit) (mr MovieResponse, err error)
Update is used to update a movie
type UpdateOrgRequest ¶ added in v0.39.0
type UpdateOrgRequest struct {
ExternalID string
Name string `json:"name"`
Description string `json:"description"`
}
UpdateOrgRequest is the request struct for Updating an Org