Documentation ¶
Overview ¶
Package service orchestrates components between handlers and other packages (datastore, gateway, domain, etc.)
Index ¶
- Constants
- func FindAppByName(ctx context.Context, tx datastore.DBTX, o *diygoapi.Org, name string) (*diygoapi.App, error)
- func FindOrgByName(ctx context.Context, tx datastore.DBTX, name string) (*diygoapi.Org, error)
- func FindRoleByCode(ctx context.Context, tx datastore.DBTX, code string) (diygoapi.Role, error)
- func FindUserByID(ctx context.Context, dbtx datastore.DBTX, id uuid.UUID) (*diygoapi.User, error)
- func UpdateRolePermissions(ctx context.Context, tx pgx.Tx, params UpdateRolePermissionsParams) (err error)
- type AppService
- func (s *AppService) Create(ctx context.Context, r *diygoapi.CreateAppRequest, adt diygoapi.Audit) (ar *diygoapi.AppResponse, err error)
- func (s *AppService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
- func (s *AppService) FindAll(ctx context.Context) (sar []*diygoapi.AppResponse, err error)
- func (s *AppService) FindByExternalID(ctx context.Context, extlID string) (ar *diygoapi.AppResponse, err error)
- func (s *AppService) Update(ctx context.Context, r *diygoapi.UpdateAppRequest, adt diygoapi.Audit) (ar *diygoapi.AppResponse, err error)
- type DBAuthenticationService
- func (s DBAuthenticationService) AuthenticationParamExchange(ctx context.Context, params *diygoapi.AuthenticationParams) (*diygoapi.ProviderInfo, error)
- func (s DBAuthenticationService) DetermineAppContext(ctx context.Context, auth diygoapi.Auth, realm string) (context.Context, error)
- func (s DBAuthenticationService) FindAppByAPIKey(r *http.Request, realm string) (*diygoapi.App, error)
- func (s DBAuthenticationService) FindAppByProviderClientID(ctx context.Context, realm string, auth diygoapi.Auth) (a *diygoapi.App, err error)
- func (s DBAuthenticationService) FindExistingAuth(r *http.Request, realm string) (diygoapi.Auth, error)
- func (s DBAuthenticationService) NewAuthenticationParams(r *http.Request, realm string) (*diygoapi.AuthenticationParams, error)
- func (s DBAuthenticationService) SelfRegister(ctx context.Context, params *diygoapi.AuthenticationParams) (ur *diygoapi.UserResponse, err error)
- type DBAuthorizationService
- type GenesisService
- type LoggerService
- type MovieService
- func (s *MovieService) Create(ctx context.Context, r *diygoapi.CreateMovieRequest, adt diygoapi.Audit) (mr *diygoapi.MovieResponse, err error)
- func (s *MovieService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
- func (s *MovieService) FindAllMovies(ctx context.Context) (smr []*diygoapi.MovieResponse, err error)
- func (s *MovieService) FindMovieByExternalID(ctx context.Context, extlID string) (mr *diygoapi.MovieResponse, err error)
- func (s *MovieService) Update(ctx context.Context, r *diygoapi.UpdateMovieRequest, adt diygoapi.Audit) (mr *diygoapi.MovieResponse, err error)
- type OrgService
- func (s *OrgService) Create(ctx context.Context, r *diygoapi.CreateOrgRequest, adt diygoapi.Audit) (or *diygoapi.OrgResponse, err error)
- func (s *OrgService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
- func (s *OrgService) FindAll(ctx context.Context) (responses []*diygoapi.OrgResponse, err error)
- func (s *OrgService) FindByExternalID(ctx context.Context, extlID string) (or *diygoapi.OrgResponse, err error)
- func (s *OrgService) Update(ctx context.Context, r *diygoapi.UpdateOrgRequest, adt diygoapi.Audit) (or *diygoapi.OrgResponse, err error)
- type PermissionService
- func (s *PermissionService) Create(ctx context.Context, r *diygoapi.CreatePermissionRequest, adt diygoapi.Audit) (response *diygoapi.PermissionResponse, err error)
- func (s *PermissionService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
- func (s *PermissionService) FindAll(ctx context.Context) (permissions []*diygoapi.PermissionResponse, err error)
- type PingService
- type RoleService
- type UpdateRolePermissionsParams
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" // 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" // TestRoleCode is the role created to flag the test account in the test org. TestRoleCode = "TestAdminRole" // LocalJSONGenesisResponseFile is the local JSON Genesis Response File path // (relative to project root) LocalJSONGenesisResponseFile = "./config/genesis/response.json" )
Variables ¶
This section is empty.
Functions ¶
func FindAppByName ¶
func FindAppByName(ctx context.Context, tx datastore.DBTX, o *diygoapi.Org, name string) (*diygoapi.App, error)
FindAppByName finds an App in the database given an org and app name.
func FindOrgByName ¶
FindOrgByName finds an Org in the database using its unique name.
func FindRoleByCode ¶
FindRoleByCode returns a Role and its permissions.
func FindUserByID ¶
FindUserByID finds a User in the datastore given their User ID
func UpdateRolePermissions ¶
func UpdateRolePermissions(ctx context.Context, tx pgx.Tx, params UpdateRolePermissionsParams) (err error)
UpdateRolePermissions writes the Permissions attached to the role to the database. If there are existing permissions, in the database, they are removed.
Types ¶
type AppService ¶
type AppService struct { Datastorer diygoapi.Datastorer APIKeyGenerator diygoapi.APIKeyGenerator EncryptionKey *[32]byte }
AppService is a service for creating an App
func (*AppService) Create ¶
func (s *AppService) Create(ctx context.Context, r *diygoapi.CreateAppRequest, adt diygoapi.Audit) (ar *diygoapi.AppResponse, err error)
Create is used to create an App
func (*AppService) Delete ¶
func (s *AppService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
Delete is used to delete an App
func (*AppService) FindAll ¶
func (s *AppService) FindAll(ctx context.Context) (sar []*diygoapi.AppResponse, err error)
FindAll is used to list all apps in the datastore
func (*AppService) FindByExternalID ¶
func (s *AppService) FindByExternalID(ctx context.Context, extlID string) (ar *diygoapi.AppResponse, err error)
FindByExternalID is used to find an App by its External ID
func (*AppService) Update ¶
func (s *AppService) Update(ctx context.Context, r *diygoapi.UpdateAppRequest, adt diygoapi.Audit) (ar *diygoapi.AppResponse, err error)
Update is used to update an App. API Keys for an App cannot be updated.
type DBAuthenticationService ¶
type DBAuthenticationService struct { Datastorer diygoapi.Datastorer TokenExchanger diygoapi.TokenExchanger EncryptionKey *[32]byte LanguageMatcher language.Matcher }
DBAuthenticationService is a service which manages Oauth2 authentication using the database.
func (DBAuthenticationService) AuthenticationParamExchange ¶ added in v0.52.0
func (s DBAuthenticationService) AuthenticationParamExchange(ctx context.Context, params *diygoapi.AuthenticationParams) (*diygoapi.ProviderInfo, error)
AuthenticationParamExchange returns a ProviderInfo struct given Authentication parameters
func (DBAuthenticationService) DetermineAppContext ¶ added in v0.52.0
func (s DBAuthenticationService) DetermineAppContext(ctx context.Context, auth diygoapi.Auth, realm string) (context.Context, 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.
func (DBAuthenticationService) FindAppByAPIKey ¶
func (s DBAuthenticationService) FindAppByAPIKey(r *http.Request, realm string) (*diygoapi.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 (DBAuthenticationService) FindAppByProviderClientID ¶
func (s DBAuthenticationService) FindAppByProviderClientID(ctx context.Context, realm string, auth diygoapi.Auth) (a *diygoapi.App, err error)
FindAppByProviderClientID finds an app given a Provider's Unique Client ID
func (DBAuthenticationService) FindExistingAuth ¶ added in v0.52.0
func (s DBAuthenticationService) FindExistingAuth(r *http.Request, realm string) (diygoapi.Auth, error)
FindExistingAuth searches for an existing Auth object in the datastore.
If an auth object already exists in the datastore for the oauth2.AccessToken and the oauth2.AccessToken is not past its expiration date, that auth is returned.
If no auth object exists in the datastore for the access token, an attempt will be made to find the user's auth with the provider id and unique ID given by the provider (found by calling the provider API). If an auth object exists, it will be updated with the new access token details.
The returned app and user as part of the auth object from either scenario above will be set to the request context for downstream use. The only exception is if an app is already set to the request context from upstream authentication, in which case, the upstream app overrides the app derived from the Oauth2 provider.
func (DBAuthenticationService) NewAuthenticationParams ¶ added in v0.52.0
func (s DBAuthenticationService) NewAuthenticationParams(r *http.Request, realm string) (*diygoapi.AuthenticationParams, error)
NewAuthenticationParams parses the provider and authorization headers and returns AuthenticationParams based on the results
func (DBAuthenticationService) SelfRegister ¶
func (s DBAuthenticationService) SelfRegister(ctx context.Context, params *diygoapi.AuthenticationParams) (ur *diygoapi.UserResponse, err error)
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 creates an Auth object and a Person/User and stores them in the database. A search is done prior to creation to determine if user is already registered, and if so, the existing user is returned.
type DBAuthorizationService ¶
type DBAuthorizationService struct {
Datastorer diygoapi.Datastorer
}
DBAuthorizationService manages authorization using the database.
func (*DBAuthorizationService) Authorize ¶
func (s *DBAuthorizationService) Authorize(r *http.Request, lgr zerolog.Logger, adt diygoapi.Audit) (err error)
Authorize ensures that a subject (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.
Authorize implements Role Based Access Control (RBAC), in this case, determining authorization for a user by running sql against tables in the database
type GenesisService ¶
type GenesisService struct { Datastorer diygoapi.Datastorer APIKeyGenerator diygoapi.APIKeyGenerator EncryptionKey *[32]byte TokenExchanger diygoapi.TokenExchanger LanguageMatcher language.Matcher }
GenesisService seeds the database. It should be run only once on initial database setup.
func (*GenesisService) Arche ¶
func (s *GenesisService) Arche(ctx context.Context, r *diygoapi.GenesisRequest) (gr diygoapi.GenesisResponse, err error)
Arche creates the initial seed data in the database.
func (*GenesisService) ReadConfig ¶
func (s *GenesisService) ReadConfig() (gr diygoapi.GenesisResponse, err error)
ReadConfig reads the generated config file from Genesis and returns it in the response body
type LoggerService ¶
LoggerService reads and updates the logger state
func (*LoggerService) Read ¶
func (ls *LoggerService) Read() *diygoapi.LoggerResponse
ReadLogger handles GET requests for the /logger endpoint
func (*LoggerService) Update ¶
func (ls *LoggerService) Update(r *diygoapi.LoggerRequest) (*diygoapi.LoggerResponse, error)
Update handles PUT requests for the /logger endpoint and updates the logger globals
type MovieService ¶
type MovieService struct {
Datastorer diygoapi.Datastorer
}
MovieService is a service for creating a Movie
func (*MovieService) Create ¶
func (s *MovieService) Create(ctx context.Context, r *diygoapi.CreateMovieRequest, adt diygoapi.Audit) (mr *diygoapi.MovieResponse, err error)
Create is used to create a Movie
func (*MovieService) Delete ¶
func (s *MovieService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
Delete is used to delete a movie
func (*MovieService) FindAllMovies ¶
func (s *MovieService) FindAllMovies(ctx context.Context) (smr []*diygoapi.MovieResponse, err error)
FindAllMovies is used to list all movies in the db
func (*MovieService) FindMovieByExternalID ¶
func (s *MovieService) FindMovieByExternalID(ctx context.Context, extlID string) (mr *diygoapi.MovieResponse, err error)
FindMovieByExternalID is used to find an individual movie
func (*MovieService) Update ¶
func (s *MovieService) Update(ctx context.Context, r *diygoapi.UpdateMovieRequest, adt diygoapi.Audit) (mr *diygoapi.MovieResponse, err error)
Update is used to update a movie
type OrgService ¶
type OrgService struct { Datastorer diygoapi.Datastorer APIKeyGenerator diygoapi.APIKeyGenerator EncryptionKey *[32]byte }
OrgService is a service for updating, reading and deleting an Org
func (*OrgService) Create ¶
func (s *OrgService) Create(ctx context.Context, r *diygoapi.CreateOrgRequest, adt diygoapi.Audit) (or *diygoapi.OrgResponse, err error)
Create is used to create an Org
func (*OrgService) Delete ¶
func (s *OrgService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
Delete is used to delete an Org
func (*OrgService) FindAll ¶
func (s *OrgService) FindAll(ctx context.Context) (responses []*diygoapi.OrgResponse, err error)
FindAll is used to list all orgs in the datastore
func (*OrgService) FindByExternalID ¶
func (s *OrgService) FindByExternalID(ctx context.Context, extlID string) (or *diygoapi.OrgResponse, err error)
FindByExternalID is used to find an Org by its External ID
func (*OrgService) Update ¶
func (s *OrgService) Update(ctx context.Context, r *diygoapi.UpdateOrgRequest, adt diygoapi.Audit) (or *diygoapi.OrgResponse, err error)
Update is used to update an Org
type PermissionService ¶
type PermissionService struct {
Datastorer diygoapi.Datastorer
}
PermissionService is a service for creating, reading, updating and deleting a Permission
func (*PermissionService) Create ¶
func (s *PermissionService) Create(ctx context.Context, r *diygoapi.CreatePermissionRequest, adt diygoapi.Audit) (response *diygoapi.PermissionResponse, err error)
Create is used to create a Permission
func (*PermissionService) Delete ¶
func (s *PermissionService) Delete(ctx context.Context, extlID string) (dr diygoapi.DeleteResponse, err error)
Delete is used to delete a Permission
func (*PermissionService) FindAll ¶
func (s *PermissionService) FindAll(ctx context.Context) (permissions []*diygoapi.PermissionResponse, err error)
FindAll retrieves all permissions
type PingService ¶
type PingService struct {
Datastorer diygoapi.Datastorer
}
PingService pings the database.
func (*PingService) Ping ¶
func (s *PingService) Ping(ctx context.Context, lgr zerolog.Logger) diygoapi.PingResponse
Ping method pings the database
type RoleService ¶
type RoleService struct {
Datastorer diygoapi.Datastorer
}
RoleService is a service for creating, reading, updating and deleting a Role
func (*RoleService) Create ¶
func (s *RoleService) Create(ctx context.Context, r *diygoapi.CreateRoleRequest, adt diygoapi.Audit) (response *diygoapi.RoleResponse, err error)
Create is used to create a Role