service

package
v0.40.0 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2022 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package service orchestrates components between handlers and other packages (datastore, gateway, domain, etc.)

Index

Constants

This section is empty.

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"`
	APIKeys     []APIKeyResponse `json:"api_keys"`
}

AppResponse is the response struct for an App

type AuthorizeService added in v0.39.0

type AuthorizeService struct {
	Authorizer Authorizer
}

func (AuthorizeService) Authorize added in v0.39.0

func (aas AuthorizeService) Authorize(lgr zerolog.Logger, r *http.Request, sub audit.Audit) error

type Authorizer added in v0.39.0

type Authorizer interface {
	Authorize(lgr zerolog.Logger, r *http.Request, sub audit.Audit) error
}

type CreateAppRequest added in v0.39.0

type CreateAppRequest struct {
	Name        string `json:"name"`
	Description string `json:"description"`
}

CreateAppRequest is the request struct for Creating an App

type CreateAppService added in v0.39.0

type CreateAppService struct {
	Datastorer            Datastorer
	RandomStringGenerator CryptoRandomGenerator
	EncryptionKey         *[32]byte
}

CreateAppService is a service for creating an App

func (CreateAppService) Create added in v0.39.0

Create is used to create 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

Create is used to create an 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 CreateOrgService added in v0.39.0

type CreateOrgService struct {
	Datastorer Datastorer
}

CreateOrgService is a service for creating an Org

func (CreateOrgService) Create added in v0.39.0

Create is used to create 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 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 DeleteMovieResponse

type DeleteMovieResponse struct {
	ExternalID string `json:"extl_id"`
	Deleted    bool   `json:"deleted"`
}

DeleteMovieResponse is the response struct for deleted Movies

type DeleteMovieService

type DeleteMovieService struct {
	Datastorer Datastorer
}

DeleteMovieService is a service for deleting a Movie

func (DeleteMovieService) Delete

Delete is used to delete a movie

type FindAppService added in v0.39.0

type FindAppService struct {
	Datastorer    Datastorer
	EncryptionKey *[32]byte
}

FindAppService is a service for retrieving an App from the datastore

func (FindAppService) FindAppByAPIKey added in v0.39.0

func (fas FindAppService) FindAppByAPIKey(ctx context.Context, realm, appExtlID, apiKey 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

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) ([]MovieResponse, error)

FindAllMovies is used to list all movies in the db

func (FindMovieService) FindMovieByID

func (s FindMovieService) FindMovieByID(ctx context.Context, extlID string) (MovieResponse, error)

FindMovieByID is used to find an individual movie

type FindOrgService added in v0.39.0

type FindOrgService struct {
	Datastorer Datastorer
}

FindOrgService interface reads Orgs form the datastore

func (FindOrgService) FindAll added in v0.39.0

func (fos FindOrgService) FindAll(ctx context.Context) ([]OrgResponse, error)

FindAll is used to list all orgs in the datastore

func (FindOrgService) FindByExternalID added in v0.39.0

func (fos FindOrgService) FindByExternalID(ctx context.Context, extlID string) (OrgResponse, error)

FindByExternalID is used to find an Org by its External ID

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 FindUserService added in v0.39.0

type FindUserService struct {
	GoogleOauth2TokenConverter GoogleOauth2TokenConverter
	Datastorer                 Datastorer
}

FindUserService represents a service for managing User retrieval from a Provider and/or the database.

func (FindUserService) FindUserByOauth2Token added in v0.39.0

func (s FindUserService) 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 FullGenesisResponse added in v0.40.0

type FullGenesisResponse struct {
	GenesisResponse GenesisResponse `json:"genesis"`
	TestResponse    TestResponse    `json:"test"`
}

type GenesisRequest added in v0.40.0

type GenesisRequest struct {
	SeedUsername      string `json:"seed_username"`
	SeedUserFirstName string `json:"seed_user_first_name"`
	SeedUserLastName  string `json:"seed_user_last_name"`
}

GenesisRequest is the request struct for initializing the database with data for the first time.

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) Seed added in v0.40.0

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

type LoggerService struct {
	Logger zerolog.Logger
}

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

Update handles PUT requests for the /logger endpoint and updates the logger globals

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"`
	CreateAudit auditResponse `json:"create_audit"`
	UpdateAudit auditResponse `json:"update_audit"`
}

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"`
	Kind        string        `json:"kind"`
	Description string        `json:"description"`
	CreateAudit auditResponse `json:"create_audit"`
	UpdateAudit auditResponse `json:"update_audit"`
}

OrgResponse is the response struct for an Org

type PingResponse

type PingResponse struct {
	DBUp bool `json:"db_up"`
}

PingResponse is the response struct for the PingService

type PingService

type PingService struct {
	Pinger Pinger
}

PingService pings the database.

func (PingService) Ping

func (p PingService) Ping(ctx context.Context, logger zerolog.Logger) PingResponse

Ping method pings the database

type Pinger

type Pinger interface {
	PingDB(context.Context) error
}

Pinger 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

func (s RegisterUserService) SelfRegister(ctx context.Context, adt audit.Audit) error

SelfRegister is used to register a User with an Organization. This is "self registration" as opposed to one user registering another user.

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 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

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

type UpdateOrgService added in v0.39.0

type UpdateOrgService struct {
	Datastorer Datastorer
}

UpdateOrgService is a service for updating an Org

func (UpdateOrgService) Update added in v0.39.0

Update is used to update an Org

Jump to

Keyboard shortcuts

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