hiro

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2021 License: GPL-3.0 Imports: 68 Imported by: 0

README

Hiro Application Platform

Controller

The hiro.Controller interface is designed to built on-top of the hiro.Backend implementation, but it is abstracted into an interface to simplify testing and improve extensibility such that it could be provided over other interfaces easily like grpc.

The interface is responsbile for managing the CRUD operations and persistence of audiences, applications, roles, users, and secrets.

Audiences
Secrets
Applications
Roles
Users

Daemon

The hiro service is the core platform component that provides all of the underlying services for higher level client implementations. The only dependencies are a hiro.Controller, an oauth.Controller and a session.Controller. These three interfaces can be implemented by the same object.

API Server

The service will ensure the core services are ready for platforms to utilize by creating both an api.Server and a grpc.Server instance. The api server will always provide hiro services at the /hiro/{version} (i.e. /hiro/1.0.0) path.

This api is defined as an Open API 2.0 (aka Swagger) spec. And can be fetched from the service at /hiro/{version}/swagger.{json|yaml}.

Routes

The API routes are defined in the route_*.go modules. These are wrappers around the hiro.Controller, providing a REST/CRUD to the controller methods. Most of the routes are secured by the oauth.Authorizer.

OAuth Controller

The service adds the oauth controller to the path /oauth. This provides all of the neccessary authentication and authorization support for the api server.

This api is defined as an Open API 2.0 (aka Swagger) spec. And can be fetched from the service at /oauth/swagger.{json|yaml}.

RPC Server
Scheduler

Documentation

Overview

Package hiro is a foundational component for Model Rocket platform API services

Index

Constants

View Source
const (
	// DefaultTokenAlgorithm is the default token algorithm
	DefaultTokenAlgorithm = oauth.TokenAlgorithmRS256

	// DefaultTokenLifetime is the default audience token lifetime
	DefaultTokenLifetime = time.Hour

	// DefaultSessionLifetime is the default audience session lifetime
	DefaultSessionLifetime = time.Hour * 24 * 30
)
View Source
const (
	// ScopeAudienceRead is used to read audience properties
	ScopeAudienceRead = "audience:read"

	// ScopeAudienceWrite is used to create or modify audiences
	ScopeAudienceWrite = "audience:write"

	// ScopeApplicationRead is used to read application properties
	ScopeApplicationRead = "application:read"

	// ScopeApplicationWrite is used to create or modify applications
	ScopeApplicationWrite = "application:write"

	// ScopeRoleRead is used to read roles
	ScopeRoleRead = "role:read"

	// ScopeRoleWrite is used to create or modify roles
	ScopeRoleWrite = "role:write"

	// ScopeAssetRead is required to read assets
	ScopeAssetRead = "asset:read"

	// ScopeAssetWrite is required to write and update assets
	ScopeAssetWrite = "asset:write"

	// ScopeUserRead is used to read users
	ScopeUserRead = "user:read"

	// ScopeUserWrite is used to create or modify users
	ScopeUserWrite = "user:write"

	// ScopeTokenRead is used to read request and access tokens
	ScopeTokenRead = "token:read"

	// ScopeTokenCreate is used to create access tokens
	ScopeTokenCreate = "token:create"

	// ScopeTokenRevoke is used to revoke request or access tokens
	ScopeTokenRevoke = "token:revoked"

	// ScopeSessionRead is used to read sessions
	ScopeSessionRead = "session:read"

	// ScopeSessionRevoke is used to destory sessions
	ScopeSessionRevoke = "session:destroy"
)
View Source
const (
	// MaxPasswordAge is the max age of a password before it must be changed
	MaxPasswordAge = time.Hour * 24 * 90
)

Variables

View Source
var (
	// ErrDuplicateObject is returned where there is unique constraint violation
	ErrDuplicateObject = api.ErrConflict

	// ErrInputValidation is returned when a object validation fails
	ErrInputValidation = api.ErrBadRequest

	// ErrNotFound is returned when an object is not found
	ErrNotFound = api.ErrNotFound

	// ErrAuthFailed is returned when user authentication fails to due to password mistmatch
	ErrAuthFailed = api.ErrUnauthorized

	// ErrDatabaseTimeout is returned when the database cannot be reached
	ErrDatabaseTimeout = api.ErrServerError.WithDetail("database connection timeout")

	// ErrContextNotFound is returned when hiro is not in the context
	ErrContextNotFound = api.ErrServerError.WithDetail("hiro not found in context")
)
View Source
var (
	// DefaultPasswordManager is the default password manager
	DefaultPasswordManager = passwordManager{}
)

Functions

func ErrTxCommit

func ErrTxCommit(err error) error

ErrTxCommit is used to return an error from within a tx handler but still commit

func IsTransaction

func IsTransaction(db DB) bool

IsTransaction returns true of the DB interface is a transaction

func ParseSQLError

func ParseSQLError(err error) error

ParseSQLError provides cleaner errors for database issues

func RegisterOption

func RegisterOption(name string, val interface{}) error

RegisterOption registers an option type

func RegisterOptionUpdateHandler

func RegisterOptionUpdateHandler(name string, handler OptionUpdateHandler)

RegisterOptionUpdateHandler registers an update handler for options

func Routes

func Routes() []api.Route

Routes returns the oauth api routes

func TokenSecret

func TokenSecret(s *Secret) (oauth.TokenSecret, error)

TokenSecret retuns a token secret from the Secret key

Types

type AccessToken

type AccessToken struct {
	ID            ID             `json:"id" db:"id"`
	Issuer        *oauth.URI     `json:"issuer,omitempty" db:"issuer"`
	Audience      ID             `json:"audience_id" db:"audience_id"`
	ApplicationID ID             `json:"application_id" db:"application_id"`
	UserID        ID             `json:"user_id,omitempty" db:"user_id,omitempty"`
	Use           oauth.TokenUse `json:"token_use" db:"token_use"`
	AuthTime      *oauth.Time    `db:"-"`
	Scope         oauth.Scope    `json:"scope,omitempty" db:"scope"`
	CreatedAt     oauth.Time     `json:"created_at" db:"created_at"`
	ExpiresAt     *oauth.Time    `json:"expires_at,omitempty" db:"expires_at"`
	Revokable     bool           `db:"-"`
	RevokedAt     *oauth.Time    `json:"revoked_at,omitempty" db:"revoked_at"`
	Claims        oauth.Claims   `json:"claims,omitempty" db:"claims"`
	Bearer        *string        `db:"-"`
}

AccessToken is the backend representation of an oauth.Token (type=TokenTypeAccess)

type Application

type Application struct {
	ID          ID               `json:"id" db:"id"`
	Name        string           `json:"name" db:"name"`
	Slug        string           `json:"slug" db:"slug"`
	Description *string          `json:"description,omitempty" db:"description"`
	Type        oauth.ClientType `json:"type" db:"type"`
	SecretKey   *string          `json:"secret_key,omitempty" db:"secret_key"`
	Permissions oauth.ScopeSet   `json:"permissions,omitempty" db:"-"`
	Grants      oauth.Grants     `json:"grants,omitempty" db:"-"`
	URIs        oauth.URIList    `json:"uris,omitempty" db:"uris"`
	CreatedAt   time.Time        `json:"created_at" db:"created_at"`
	UpdatedAt   *time.Time       `json:"updated_at,omitempty" db:"updated_at"`
	Metadata    common.Map       `json:"metadata,omitempty" db:"metadata"`
}

Application is the database model for an application

type ApplicationController added in v0.1.1

type ApplicationController interface {
	ApplicationCreate(ctx context.Context, params ApplicationCreateInput) (*Application, error)
	ApplicationGet(ctx context.Context, params ApplicationGetInput) (*Application, error)
	ApplicationList(ctx context.Context, params ApplicationListInput) ([]*Application, error)
	ApplicationUpdate(ctx context.Context, params ApplicationUpdateInput) (*Application, error)
	ApplicationDelete(ctx context.Context, params ApplicationDeleteInput) error
}

ApplicationController is the applications API interface

type ApplicationCountRoute

type ApplicationCountRoute func(ctx context.Context, params *ApplicationListInput) api.Responder

ApplicationCountRoute is the application count route definition

func (ApplicationCountRoute) Methods

func (ApplicationCountRoute) Methods() []string

Methods implements api.Route

func (ApplicationCountRoute) Name

Name implements api.Route

func (ApplicationCountRoute) Path

Path implements api.Route

func (ApplicationCountRoute) RequireAuth

func (ApplicationCountRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (ApplicationCountRoute) Scopes

Scopes implements oauth.Route

type ApplicationCreateInput

type ApplicationCreateInput struct {
	Name        string           `json:"name"`
	Description *string          `json:"description,omitempty"`
	Type        oauth.ClientType `json:"type" db:"type"`
	Permissions oauth.ScopeSet   `json:"permissions,omitempty"`
	Grants      oauth.Grants     `json:"grants,omitempty"`
	URIs        oauth.URIList    `json:"uris,omitempty"`
	Metadata    common.Map       `json:"metadata,omitempty"`
}

ApplicationCreateInput is the application create request

func (ApplicationCreateInput) ValidateWithContext

func (a ApplicationCreateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the ApplicationCreateInput struct

type ApplicationCreateRoute

type ApplicationCreateRoute func(ctx context.Context, params *ApplicationCreateInput) api.Responder

ApplicationCreateRoute is the application create route definition

func (ApplicationCreateRoute) Methods

func (ApplicationCreateRoute) Methods() []string

Methods implements api.Route

func (ApplicationCreateRoute) Name

Name implements api.Route

func (ApplicationCreateRoute) Path

Path implements api.Route

func (ApplicationCreateRoute) RequireAuth

func (ApplicationCreateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (ApplicationCreateRoute) Scopes

Scopes implements oauth.Route

type ApplicationDeleteInput

type ApplicationDeleteInput struct {
	ApplicationID ID `json:"application_id"`
}

ApplicationDeleteInput is the application delete request input

func (ApplicationDeleteInput) ValidateWithContext

func (a ApplicationDeleteInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the ApplicationDeleteInput

type ApplicationDeleteRoute

type ApplicationDeleteRoute func(ctx context.Context, params *ApplicationDeleteInput) api.Responder

ApplicationDeleteRoute is the application create route definition

func (ApplicationDeleteRoute) Methods

func (ApplicationDeleteRoute) Methods() []string

Methods implements api.Route

func (ApplicationDeleteRoute) Name

Name implements api.Route

func (ApplicationDeleteRoute) Path

Path implements api.Route

func (ApplicationDeleteRoute) RequireAuth

func (ApplicationDeleteRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (ApplicationDeleteRoute) Scopes

Scopes implements oauth.Route

type ApplicationGetInput

type ApplicationGetInput struct {
	ApplicationID ID      `json:"application_id,omitempty"`
	Name          *string `json:"name,omitempty"`
}

ApplicationGetInput is used to get an application for the id

func (ApplicationGetInput) ValidateWithContext

func (a ApplicationGetInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the ApplicationGetInput struct

type ApplicationGetRoute

type ApplicationGetRoute func(ctx context.Context, params *ApplicationGetInput) api.Responder

ApplicationGetRoute is the application create route definition

func (ApplicationGetRoute) Methods

func (ApplicationGetRoute) Methods() []string

Methods implements api.Route

func (ApplicationGetRoute) Name

func (ApplicationGetRoute) Name() string

Name implements api.Route

func (ApplicationGetRoute) Path

func (ApplicationGetRoute) Path() string

Path implements api.Route

func (ApplicationGetRoute) RequireAuth

func (ApplicationGetRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (ApplicationGetRoute) Scopes

Scopes implements oauth.Route

type ApplicationListInput

type ApplicationListInput struct {
	Limit  *uint64 `json:"limit,omitempty"`
	Offset *uint64 `json:"offset,omitempty"`
	Count  *uint64 `json:"count,omitempty"`
}

ApplicationListInput is the application list request

func (ApplicationListInput) ValidateWithContext

func (a ApplicationListInput) ValidateWithContext(context.Context) error

ValidateWithContext handles validation of the ApplicationListInput struct

type ApplicationListRoute

type ApplicationListRoute func(ctx context.Context, params *ApplicationListInput) api.Responder

ApplicationListRoute is the application count route definition

func (ApplicationListRoute) Methods

func (ApplicationListRoute) Methods() []string

Methods implements api.Route

func (ApplicationListRoute) Name

Name implements api.Route

func (ApplicationListRoute) Path

Path implements api.Route

func (ApplicationListRoute) RequireAuth

func (ApplicationListRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (ApplicationListRoute) Scopes

Scopes implements oauth.Route

type ApplicationType

type ApplicationType string

ApplicationType defines an application type

type ApplicationUpdateInput

type ApplicationUpdateInput struct {
	ApplicationID ID                 `json:"id" structs:"-"`
	Name          *string            `json:"name" structs:"name,omitempty"`
	Description   *string            `json:"description,omitempty" structs:"description,omitempty"`
	Type          *oauth.ClientType  `json:"type" structs:"type,omitempty"`
	Permissions   *PermissionsUpdate `json:"permissions,omitempty" structs:"-"`
	Grants        oauth.Grants       `json:"grants,omitempty" structs:"-"`
	URIs          oauth.URIList      `json:"uris,omitempty" structs:"-"`
	Metadata      common.Map         `json:"metadata,omitempty" structs:"metadata,omitempty"`
}

ApplicationUpdateInput is the application update request

func (ApplicationUpdateInput) ValidateWithContext

func (a ApplicationUpdateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the ApplicationUpdateInput struct

type ApplicationUpdateRoute

type ApplicationUpdateRoute func(ctx context.Context, params *ApplicationUpdateInput) api.Responder

ApplicationUpdateRoute is the application create route definition

func (ApplicationUpdateRoute) Methods

func (ApplicationUpdateRoute) Methods() []string

Methods implements api.Route

func (ApplicationUpdateRoute) Name

Name implements api.Route

func (ApplicationUpdateRoute) Path

Path implements api.Route

func (ApplicationUpdateRoute) RequireAuth

func (ApplicationUpdateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (ApplicationUpdateRoute) Scopes

Scopes implements oauth.Route

type Asset

type Asset struct {
	ID          ID          `json:"id" db:"id"`
	AudienceID  ID          `json:"audience_id" db:"audience_id"`
	OwnerID     *ID         `json:"owner_id,omitempty" db:"owner_id"`
	Title       string      `json:"title" db:"title"`
	Description *string     `json:"description,omitempty" db:"description"`
	Filename    string      `json:"filename" db:"filename"`
	MimeType    string      `json:"mime_type" db:"mime_type"`
	Size        int64       `json:"size" db:"size"`
	Public      bool        `json:"public" db:"public"`
	CreatedAt   time.Time   `json:"created_at" db:"created_at"`
	UpdatedAt   *time.Time  `json:"updated_at,omitempty" db:"updated_at"`
	Metadata    common.Map  `json:"metadata,omitempty" db:"metadata"`
	SHA256      *string     `json:"sha256,omitempty" db:"sha256"`
	Payload     AssetReader `json:"-" db:"-"`
}

Asset objects are application assets that are stored in the asset volume

type AssetController added in v0.1.1

type AssetController interface {
	AssetCreate(ctx context.Context, params AssetCreateInput) (*Asset, error)
	AssetGet(ctc context.Context, params AssetGetInput) (*Asset, error)
	AssetList(ctx context.Context, params AssetListInput) ([]*Asset, error)
	AssetUpdate(ctx context.Context, params AssetUpdateInput) (*Asset, error)
	AssetDelete(ctx context.Context, params AssetDeleteInput) error
}

AssetController is the asset API interface

type AssetCountRoute added in v0.1.1

type AssetCountRoute func(ctx context.Context, params *AssetListInput) api.Responder

AssetCountRoute is the asset count route definition

func (AssetCountRoute) Methods added in v0.1.1

func (AssetCountRoute) Methods() []string

Methods implements api.Route

func (AssetCountRoute) Name added in v0.1.1

func (AssetCountRoute) Name() string

Name implements api.Route

func (AssetCountRoute) Path added in v0.1.1

func (AssetCountRoute) Path() string

Path implements api.Route

func (AssetCountRoute) RequireAuth added in v0.1.1

func (AssetCountRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AssetCountRoute) Scopes added in v0.1.1

func (AssetCountRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type AssetCreateInput added in v0.1.1

type AssetCreateInput struct {
	AudienceID  ID         `json:"audience_id"`
	OwnerID     *ID        `json:"owner_id,omitempty"`
	Title       string     `json:"title"`
	Description *string    `json:"description,omitempty"`
	Filename    string     `json:"filename"`
	Public      bool       `json:"public"`
	Metadata    common.Map `json:"metadata,omitempty"`
	Payload     io.Reader  `json:"-"`
}

AssetCreateInput is the input to AssetCreate

func (*AssetCreateInput) ValidateWithContext added in v0.1.1

func (a *AssetCreateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles the validation for the AssetCreateInput

type AssetCreateRoute added in v0.1.1

type AssetCreateRoute func(ctx context.Context, params *AssetCreateInput) api.Responder

AssetCreateRoute is the asset create route definition

func (AssetCreateRoute) Methods added in v0.1.1

func (AssetCreateRoute) Methods() []string

Methods implements api.Route

func (AssetCreateRoute) Name added in v0.1.1

func (AssetCreateRoute) Name() string

Name implements api.Route

func (AssetCreateRoute) Path added in v0.1.1

func (AssetCreateRoute) Path() string

Path implements api.Route

func (AssetCreateRoute) RequireAuth added in v0.1.1

func (AssetCreateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AssetCreateRoute) Scopes added in v0.1.1

func (AssetCreateRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type AssetDeleteInput added in v0.1.1

type AssetDeleteInput struct {
	AudienceID ID `json:"audience_id"`
	AssetID    ID `json:"asset_id"`
}

AssetDeleteInput is the input to AssetDelete

func (AssetDeleteInput) ValidateWithContext added in v0.1.1

func (a AssetDeleteInput) ValidateWithContext(ctx context.Context) error

Validate handles validation for AssetGetInput

type AssetDeleteRoute added in v0.1.1

type AssetDeleteRoute func(ctx context.Context, params *AssetDeleteInput) api.Responder

AssetDeleteRoute is the asset create route definition

func (AssetDeleteRoute) Methods added in v0.1.1

func (AssetDeleteRoute) Methods() []string

Methods implements api.Route

func (AssetDeleteRoute) Name added in v0.1.1

func (AssetDeleteRoute) Name() string

Name implements api.Route

func (AssetDeleteRoute) Path added in v0.1.1

func (AssetDeleteRoute) Path() string

Path implements api.Route

func (AssetDeleteRoute) RequireAuth added in v0.1.1

func (AssetDeleteRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AssetDeleteRoute) Scopes added in v0.1.1

func (AssetDeleteRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type AssetGetInput added in v0.1.1

type AssetGetInput struct {
	AudienceID  ID      `json:"audience_id"`
	AssetID     *ID     `json:"asset_id"`
	Filename    *string `json:"filename"`
	WithPayload bool    `json:"-"`
}

AssetGetInput is the input to AssetGet

func (AssetGetInput) ValidateWithContext added in v0.1.1

func (a AssetGetInput) ValidateWithContext(ctx context.Context) error

Validate handles validation for AssetGetInput

type AssetGetRoute added in v0.1.1

type AssetGetRoute func(ctx context.Context, params *AssetGetInput) api.Responder

AssetGetRoute is the asset create route definition

func (AssetGetRoute) Methods added in v0.1.1

func (AssetGetRoute) Methods() []string

Methods implements api.Route

func (AssetGetRoute) Name added in v0.1.1

func (AssetGetRoute) Name() string

Name implements api.Route

func (AssetGetRoute) Path added in v0.1.1

func (AssetGetRoute) Path() string

Path implements api.Route

func (AssetGetRoute) RequireAuth added in v0.1.1

func (AssetGetRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AssetGetRoute) Scopes added in v0.1.1

func (AssetGetRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type AssetListInput added in v0.1.1

type AssetListInput struct {
	AudienceID ID      `json:"audience_id"`
	Offset     *uint64 `json:"offset,omitempty"`
	Limit      *uint64 `json:"limit,omitempty"`
	Count      *uint64 `json:"count,omitempty"`
	MimeType   *string `json:"mime_type,omitempty"`
}

AssetListInput is the input to AssetList

func (AssetListInput) ValidateWithContext added in v0.1.1

func (a AssetListInput) ValidateWithContext(ctx context.Context) error

Validate handles validation for AssetGetInput

type AssetListRoute added in v0.1.1

type AssetListRoute func(ctx context.Context, params *AssetListInput) api.Responder

AssetListRoute is the asset count route definition

func (AssetListRoute) Methods added in v0.1.1

func (AssetListRoute) Methods() []string

Methods implements api.Route

func (AssetListRoute) Name added in v0.1.1

func (AssetListRoute) Name() string

Name implements api.Route

func (AssetListRoute) Path added in v0.1.1

func (AssetListRoute) Path() string

Path implements api.Route

func (AssetListRoute) RequireAuth added in v0.1.1

func (AssetListRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AssetListRoute) Scopes added in v0.1.1

func (AssetListRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type AssetReader added in v0.1.1

type AssetReader interface {
	io.ReadSeeker
	io.Closer
}

AssetReader is an interface for asset io

type AssetUpdateInput added in v0.1.1

type AssetUpdateInput struct {
	AudienceID  ID         `json:"audience_id" structs:"audience_id"`
	AssetID     ID         `json:"asset_id" structs:"asset_id"`
	Title       *string    `json:"title" structs:"title,omitempty"`
	Description *string    `json:"description,omitempty" structs:"description,omitempty"`
	Filename    *string    `json:"filename" structs:"filename,omitempty"`
	Public      *bool      `json:"public" structs:"public,omitempty"`
	Metadata    common.Map `json:"metadata,omitempty" structs:"metadata,omitempty"`
	Payload     io.Reader  `json:"-" structs:"-"`
}

AssetUpdateInput is the input to AssetUpdate

func (*AssetUpdateInput) ValidateWithContext added in v0.1.1

func (a *AssetUpdateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles the validation for the AssetUpdateInput

type AssetUpdateRoute added in v0.1.1

type AssetUpdateRoute func(ctx context.Context, params *AssetUpdateInput) api.Responder

AssetUpdateRoute is the asset create route definition

func (AssetUpdateRoute) Methods added in v0.1.1

func (AssetUpdateRoute) Methods() []string

Methods implements api.Route

func (AssetUpdateRoute) Name added in v0.1.1

func (AssetUpdateRoute) Name() string

Name implements api.Route

func (AssetUpdateRoute) Path added in v0.1.1

func (AssetUpdateRoute) Path() string

Path implements api.Route

func (AssetUpdateRoute) RequireAuth added in v0.1.1

func (AssetUpdateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AssetUpdateRoute) Scopes added in v0.1.1

func (AssetUpdateRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type Audience

type Audience struct {
	ID              ID                   `json:"id" db:"id"`
	Name            string               `json:"name" db:"name"`
	Slug            string               `json:"slug" db:"slug"`
	Domain          *string              `json:"domain" db:"domain"`
	Description     *string              `json:"description,omitempty" db:"description"`
	TokenSecrets    []oauth.TokenSecret  `json:"-" db:"-"`
	SessionKeys     []SessionKey         `json:"-" db:"-"`
	Secrets         []*Secret            `json:"secrets,omitempty" db:"-"`
	TokenAlgorithm  oauth.TokenAlgorithm `json:"token_algorithm" db:"token_algorithm"`
	TokenLifetime   time.Duration        `json:"token_lifetime" db:"token_lifetime"`
	SessionLifetime time.Duration        `json:"session_lifetime,omitempty" db:"session_lifetime"`
	CreatedAt       time.Time            `json:"created_at" db:"created_at"`
	UpdatedAt       *time.Time           `json:"updated_at,omitempty" db:"updated_at"`
	Permissions     oauth.Scope          `json:"permissions,omitempty" db:"-"`
	Metadata        common.Map           `json:"metadata,omitempty" db:"metadata"`
}

Audience is the database model for an audience

func (*Audience) FromProto

func (a *Audience) FromProto(p *pb.Audience)

FromProto convert the proto audience to an api audience

func (Audience) ToProto

func (a Audience) ToProto() (*pb.Audience, error)

ToProto converts the audiece to its protobuf conterpart

type AudienceController added in v0.1.1

type AudienceController interface {
	AudienceCreate(ctx context.Context, params AudienceCreateInput) (*Audience, error)
	AudienceGet(ctx context.Context, params AudienceGetInput) (*Audience, error)
	AudienceList(ctx context.Context, params AudienceListInput) ([]*Audience, error)
	AudienceUpdate(ctx context.Context, params AudienceUpdateInput) (*Audience, error)
	AudienceDelete(ctx context.Context, params AudienceDeleteInput) error
}

AudienceController is the audience API interface

type AudienceCountRoute

type AudienceCountRoute func(ctx context.Context, params *AudienceListInput) api.Responder

AudienceCountRoute is the audience count route definition

func (AudienceCountRoute) Methods

func (AudienceCountRoute) Methods() []string

Methods implements api.Route

func (AudienceCountRoute) Name

func (AudienceCountRoute) Name() string

Name implements api.Route

func (AudienceCountRoute) Path

func (AudienceCountRoute) Path() string

Path implements api.Route

func (AudienceCountRoute) RequireAuth

func (AudienceCountRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AudienceCountRoute) Scopes

Scopes implements oauth.Route

type AudienceCreateInput

type AudienceCreateInput struct {
	Name            string               `json:"name"`
	Description     *string              `json:"description,omitempty"`
	Domain          *string              `json:"domain" db:"domain"`
	TokenLifetime   time.Duration        `json:"token_lifetime"`
	TokenAlgorithm  oauth.TokenAlgorithm `json:"token_algorithm"`
	SessionLifetime time.Duration        `json:"session_lifetime,omitempty"`
	Permissions     oauth.Scope          `json:"permissions,omitempty"`
	Metadata        common.Map           `json:"metadata,omitempty"`
}

AudienceCreateInput is the audience create request

func (AudienceCreateInput) ValidateWithContext

func (a AudienceCreateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the AudienceCreateInput struct

type AudienceCreateRoute

type AudienceCreateRoute func(ctx context.Context, params *AudienceCreateInput) api.Responder

AudienceCreateRoute is the audience create route definition

func (AudienceCreateRoute) Methods

func (AudienceCreateRoute) Methods() []string

Methods implements api.Route

func (AudienceCreateRoute) Name

func (AudienceCreateRoute) Name() string

Name implements api.Route

func (AudienceCreateRoute) Path

func (AudienceCreateRoute) Path() string

Path implements api.Route

func (AudienceCreateRoute) RequireAuth

func (AudienceCreateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AudienceCreateRoute) Scopes

Scopes implements oauth.Route

type AudienceDeleteInput

type AudienceDeleteInput struct {
	AudienceID ID `json:"audience_id"`
}

AudienceDeleteInput is the audience delete request input

func (AudienceDeleteInput) ValidateWithContext

func (a AudienceDeleteInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the ApplicationDeleteInput

type AudienceDeleteRoute

type AudienceDeleteRoute func(ctx context.Context, params *AudienceDeleteInput) api.Responder

AudienceDeleteRoute is the audience create route definition

func (AudienceDeleteRoute) Methods

func (AudienceDeleteRoute) Methods() []string

Methods implements api.Route

func (AudienceDeleteRoute) Name

func (AudienceDeleteRoute) Name() string

Name implements api.Route

func (AudienceDeleteRoute) Path

func (AudienceDeleteRoute) Path() string

Path implements api.Route

func (AudienceDeleteRoute) RequireAuth

func (AudienceDeleteRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AudienceDeleteRoute) Scopes

Scopes implements oauth.Route

type AudienceGetInput

type AudienceGetInput struct {
	AudienceID ID      `json:"audience_id,omitempty"`
	Name       *string `json:"name,omitempty"`
	Domain     *string `json:"domain,omitempty"`
}

AudienceGetInput is used to get an audience for the id

func (AudienceGetInput) ValidateWithContext

func (a AudienceGetInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the AudienceGetInput struct

type AudienceGetRoute

type AudienceGetRoute func(ctx context.Context, params *AudienceGetInput) api.Responder

AudienceGetRoute is the audience create route definition

func (AudienceGetRoute) Methods

func (AudienceGetRoute) Methods() []string

Methods implements api.Route

func (AudienceGetRoute) Name

func (AudienceGetRoute) Name() string

Name implements api.Route

func (AudienceGetRoute) Path

func (AudienceGetRoute) Path() string

Path implements api.Route

func (AudienceGetRoute) RequireAuth

func (AudienceGetRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AudienceGetRoute) Scopes

func (AudienceGetRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type AudienceInitializeInput

type AudienceInitializeInput struct {
	Name            string                `json:"name"`
	Description     *string               `json:"description,omitempty"`
	Domain          *string               `json:"domain" db:"domain"`
	TokenLifetime   *time.Duration        `json:"token_lifetime"`
	TokenAlgorithm  *oauth.TokenAlgorithm `json:"token_algorithm"`
	SessionLifetime *time.Duration        `json:"session_lifetime,omitempty"`
	Permissions     oauth.Scope           `json:"permissions,omitempty"`
	Metadata        common.Map            `json:"metadata,omitempty"`
	Roles           oauth.ScopeSet        `json:"roles,omitempty"`
}

AudienceInitializeInput is the input to the audience initialization

func (AudienceInitializeInput) ValidateWithContext

func (a AudienceInitializeInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the AudienceInitializeInput struct

type AudienceListInput

type AudienceListInput struct {
	Limit  *uint64 `json:"limit,omitempty"`
	Offset *uint64 `json:"offset,omitempty"`
	Count  *uint64 `json:"count,omitempty"`
}

AudienceListInput is the audience list request

func (AudienceListInput) ValidateWithContext

func (a AudienceListInput) ValidateWithContext(context.Context) error

ValidateWithContext handles validation of the AudienceListInput struct

type AudienceListRoute

type AudienceListRoute func(ctx context.Context, params *AudienceListInput) api.Responder

AudienceListRoute is the audience count route definition

func (AudienceListRoute) Methods

func (AudienceListRoute) Methods() []string

Methods implements api.Route

func (AudienceListRoute) Name

func (AudienceListRoute) Name() string

Name implements api.Route

func (AudienceListRoute) Path

func (AudienceListRoute) Path() string

Path implements api.Route

func (AudienceListRoute) RequireAuth

func (AudienceListRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AudienceListRoute) Scopes

Scopes implements oauth.Route

type AudiencePermissionsUpdate

type AudiencePermissionsUpdate struct {
	Add       oauth.Scope `json:"add,omitempty"`
	Remove    oauth.Scope `json:"remove,omitempty"`
	Overwrite bool        `json:"overrite"`
}

AudiencePermissionsUpdate is used to update audience permissions

type AudienceUpdateInput

type AudienceUpdateInput struct {
	AudienceID      ID                         `json:"audience_id" structs:"-"`
	Name            *string                    `json:"name" structs:"name,omitempty"`
	Description     *string                    `json:"description,omitempty" structs:"description,omitempty"`
	Domain          *string                    `json:"domain" structs:"domain,omitempty"`
	TokenAlgorithm  *oauth.TokenAlgorithm      `json:"token_algorithm,omitempty" structs:"token_algorithm,omitempty"`
	TokenLifetime   *time.Duration             `json:"token_lifetime" structs:"token_lifetime,omitempty"`
	SessionLifetime *time.Duration             `json:"session_lifetime,omitempty" structs:"session_lifetime,omitempty"`
	Permissions     *AudiencePermissionsUpdate `json:"permissions,omitempty" structs:"-"`
	Metadata        common.Map                 `json:"metadata,omitempty" structs:"-"`
}

AudienceUpdateInput is the audience update request

func (AudienceUpdateInput) ValidateWithContext

func (a AudienceUpdateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the AudienceUpdateInput struct

type AudienceUpdateRoute

type AudienceUpdateRoute func(ctx context.Context, params *AudienceUpdateInput) api.Responder

AudienceUpdateRoute is the audience create route definition

func (AudienceUpdateRoute) Methods

func (AudienceUpdateRoute) Methods() []string

Methods implements api.Route

func (AudienceUpdateRoute) Name

func (AudienceUpdateRoute) Name() string

Name implements api.Route

func (AudienceUpdateRoute) Path

func (AudienceUpdateRoute) Path() string

Path implements api.Route

func (AudienceUpdateRoute) RequireAuth

func (AudienceUpdateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (AudienceUpdateRoute) Scopes

Scopes implements oauth.Route

type Backend

type Backend struct {
	// contains filtered or unexported fields
}

Backend is the hiro api backend implementation

func FromContext

func FromContext(ctx context.Context) *Backend

FromContext returns a hiro from the context

func New

func New(opts ...BackendOption) (*Backend, error)

New returns a new hiro backend

func (*Backend) ApplicationCreate

func (b *Backend) ApplicationCreate(ctx context.Context, params ApplicationCreateInput) (*Application, error)

ApplicationCreate create a new permission object

func (*Backend) ApplicationDelete

func (b *Backend) ApplicationDelete(ctx context.Context, params ApplicationDeleteInput) error

ApplicationDelete deletes an application by id

func (*Backend) ApplicationGet

func (b *Backend) ApplicationGet(ctx context.Context, params ApplicationGetInput) (*Application, error)

ApplicationGet gets an application by id and optionally preloads child objects

func (*Backend) ApplicationList

func (b *Backend) ApplicationList(ctx context.Context, params ApplicationListInput) ([]*Application, error)

ApplicationList returns a listing of applications

func (*Backend) ApplicationUpdate

func (b *Backend) ApplicationUpdate(ctx context.Context, params ApplicationUpdateInput) (*Application, error)

ApplicationUpdate updates an application by id, including child objects

func (*Backend) AssetCreate added in v0.1.1

func (b *Backend) AssetCreate(ctx context.Context, params AssetCreateInput) (*Asset, error)

AssetCreate creates a new asset for the audience

func (*Backend) AssetDelete added in v0.1.1

func (b *Backend) AssetDelete(ctx context.Context, params AssetDeleteInput) error

AssetDelete deletes an asset

func (*Backend) AssetGet added in v0.1.1

func (b *Backend) AssetGet(ctx context.Context, params AssetGetInput) (*Asset, error)

AssetGet returns the asset in the audience

func (*Backend) AssetList added in v0.1.1

func (b *Backend) AssetList(ctx context.Context, params AssetListInput) ([]*Asset, error)

AssetList lists the assets in the audience

func (*Backend) AssetUpdate added in v0.1.1

func (b *Backend) AssetUpdate(ctx context.Context, params AssetUpdateInput) (*Asset, error)

AssetUpdate updates an asset

func (*Backend) AudienceCreate

func (b *Backend) AudienceCreate(ctx context.Context, params AudienceCreateInput) (*Audience, error)

AudienceCreate create a new permission object

func (*Backend) AudienceDelete

func (b *Backend) AudienceDelete(ctx context.Context, params AudienceDeleteInput) error

AudienceDelete deletes an audience by id

func (*Backend) AudienceGet

func (b *Backend) AudienceGet(ctx context.Context, params AudienceGetInput) (*Audience, error)

AudienceGet gets an audience by id and optionally preloads child objects

func (*Backend) AudienceInitialize

func (b *Backend) AudienceInitialize(ctx context.Context, params AudienceInitializeInput) (*Audience, error)

AudienceInitialize will create or update and audience, intialize a default application and secrets

func (*Backend) AudienceList

func (b *Backend) AudienceList(ctx context.Context, params AudienceListInput) ([]*Audience, error)

AudienceList returns a listing of audiences

func (*Backend) AudienceUpdate

func (b *Backend) AudienceUpdate(ctx context.Context, params AudienceUpdateInput) (*Audience, error)

AudienceUpdate updates an application by id, including child objects

func (*Backend) Context

func (b *Backend) Context(ctx context.Context) context.Context

Context returns the context with hiro

func (*Backend) DB

func (b *Backend) DB(ctx context.Context) DB

DB returns a transaction from the context if it exists or the db

func (*Backend) Log

func (b *Backend) Log(ctx context.Context) log.Interface

Log returns the log from the context or from the server

func (*Backend) OAuthController

func (b *Backend) OAuthController() oauth.Controller

OAuthController returns an oauth controller from a hiro.Backend

func (*Backend) OptionGet

func (b *Backend) OptionGet(ctx context.Context, params *OptionGetInput) (Option, error)

OptionGet returns a named option from the backend

func (*Backend) OptionRemove

func (b *Backend) OptionRemove(ctx context.Context, params *OptionRemoveInput) error

OptionRemove removes the named option from the backend

func (*Backend) OptionUpdate

func (b *Backend) OptionUpdate(ctx context.Context, params *OptionUpdateInput) (Option, error)

OptionUpdate stores a named option in the backend data store

func (*Backend) PasswordManager

func (b *Backend) PasswordManager() PasswordManager

PasswordManager returns the current password manager for the instance

func (*Backend) RoleCreate

func (b *Backend) RoleCreate(ctx context.Context, params RoleCreateInput) (*Role, error)

RoleCreate create a new permission object

func (*Backend) RoleDelete

func (b *Backend) RoleDelete(ctx context.Context, params RoleDeleteInput) error

RoleDelete deletes an role by id

func (*Backend) RoleGet

func (b *Backend) RoleGet(ctx context.Context, params RoleGetInput) (*Role, error)

RoleGet gets an role by id and optionally preloads child objects

func (*Backend) RoleList

func (b *Backend) RoleList(ctx context.Context, params RoleListInput) ([]*Role, error)

RoleList returns a listing of roles

func (*Backend) RoleUpdate

func (b *Backend) RoleUpdate(ctx context.Context, params RoleUpdateInput) (*Role, error)

RoleUpdate updates an role by id, including child objects

func (*Backend) SecretCreate

func (b *Backend) SecretCreate(ctx context.Context, params SecretCreateInput) (*Secret, error)

SecretCreate creates a new secret, generating the key if not is provided

func (*Backend) SecretDelete

func (b *Backend) SecretDelete(ctx context.Context, params SecretDeleteInput) error

SecretDelete deletes an audience by id

func (*Backend) SessionController

func (b *Backend) SessionController() session.Controller

SessionController returns an oauth controller from a hiro.Backend

func (*Backend) Transact

func (b *Backend) Transact(ctx context.Context, handler TxHandler, ignore ...error) (err error)

Transact starts a db transaction, adds it to the context and calls the handler

func (*Backend) UserCreate

func (b *Backend) UserCreate(ctx context.Context, params UserCreateInput) (*User, error)

UserCreate create a new permission object

func (*Backend) UserDelete

func (b *Backend) UserDelete(ctx context.Context, params UserDeleteInput) error

UserDelete deletes an user by id

func (*Backend) UserGet

func (b *Backend) UserGet(ctx context.Context, params UserGetInput) (*User, error)

UserGet gets an user by id and optionally preloads child objects

func (*Backend) UserList

func (b *Backend) UserList(ctx context.Context, params UserListInput) ([]*User, error)

UserList returns a listing of users

func (*Backend) UserUpdate

func (b *Backend) UserUpdate(ctx context.Context, params UserUpdateInput) (*User, error)

UserUpdate updates an user by id, including child objects

type BackendOption

type BackendOption func(b *Backend)

BackendOption defines a backend option

func Automigrate

func Automigrate(m ...Migration) BackendOption

Automigrate will perform the database initialization, creating tables and indexes.

func Initialize

func Initialize(a ...AudienceInitializeInput) BackendOption

Initialize will create the default hiro audience and application to use for management

func WithAssetVolume added in v0.1.1

func WithAssetVolume(v string) BackendOption

WithAssetVolume sets the asset volume for the instance

func WithDB

func WithDB(db *sql.DB) BackendOption

WithDB sets the database instance

func WithDBSource

func WithDBSource(source string) BackendOption

WithDBSource sets the database source string

func WithLog

func WithLog(l log.Interface) BackendOption

WithLog sets the log for the backend

type Controller

type Controller interface {
	AudienceController
	SecretsController
	ApplicationController
	RoleController
	UserController
	AssetController

	// Returns the log from the context
	Log(ctx context.Context) log.Interface

	// Starts a database transaction
	Transact(ctx context.Context, handler TxHandler, ignore ...error) error

	// Gets a handle to the database
	DB(ctx context.Context) DB

	oauth.ControllerProxy

	// SessionController return the session controller
	SessionController() session.Controller
}

Controller is the hiro API controller interface

type DB

type DB interface {
	sqlx.Ext
	sqlx.ExtContext
	SelectContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
	GetContext(ctx context.Context, dest interface{}, query string, args ...interface{}) error
}

DB is an aggregate interface for sqlx transactions

type ID

type ID string

ID is the hiro uuid implementation wrapper that base58 encodes/decodes the values as text or json

func NullID

func NullID(id ...interface{}) ID

NullID will parse or generate a value to make a new ID

func (ID) Hex

func (id ID) Hex() string

Hex encode the id as hex

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

MarshalJSON handles json marshaling of this type

func (*ID) Scan

func (id *ID) Scan(value interface{}) error

Scan implements the Scanner interface.

func (ID) String

func (id ID) String() string

func (*ID) UnmarshalJSON

func (id *ID) UnmarshalJSON(b []byte) error

UnmarshalJSON handles the unmarshaling of this type

func (ID) Valid

func (id ID) Valid() bool

Valid returns true if the id is valid

func (ID) Validate

func (id ID) Validate() error

Validate validates the id as a uuid

func (ID) Value

func (id ID) Value() (driver.Value, error)

Value implements the driver Valuer interface.

type Job

type Job struct {
	Function interface{}
	Params   []interface{}
	Interval time.Duration
	At       *time.Time
}

Job is a job handler that the service will schedule

type Migration

type Migration struct {
	*migrate.AssetMigrationSource
	Schema string
}

Migration is a db migration

type Option

type Option interface {
	Name() string
	SetName(string)
	Audience() string
	SetAudience(string)
}

Option An instance configuration option

func UnmarshalOption

func UnmarshalOption(reader io.Reader, name ...string) (Option, error)

UnmarshalOption unmarshals polymorphic Option

func UnmarshalOptionSlice

func UnmarshalOptionSlice(reader io.Reader) ([]Option, error)

UnmarshalOptionSlice unmarshals polymorphic slices of Option

type OptionController

type OptionController interface {
	// OptionUpdate stores a named option in the backend data store, the value should be created if it does not exist
	OptionUpdate(ctx context.Context, params *OptionUpdateInput) (Option, error)

	// OptionGet returns a named option from the backend, an error should be returned if the option does not exist
	OptionGet(ctx context.Context, params *OptionGetInput) (Option, error)

	// OptionRemove removes the named option from the backend, and error should not be returned if the option does not exist
	OptionRemove(ctx context.Context, params *OptionRemoveInput) error
}

OptionController provides instance configuration

type OptionGetInput

type OptionGetInput struct {
	Name  string      `json:"name"`
	Value interface{} `json:"-"`
}

OptionGetInput is the option get input

func (OptionGetInput) Validate

func (o OptionGetInput) Validate() error

Validate validates OptionGetInput

type OptionRemoveInput

type OptionRemoveInput struct {
	Name string `json:"name"`
}

OptionRemoveInput is the option get input

func (OptionRemoveInput) Validate

func (o OptionRemoveInput) Validate() error

Validate validates OptionRemoveInput

type OptionUpdateHandler

type OptionUpdateHandler func(context.Context, Option) error

OptionUpdateHandler is called when options are updated

type OptionUpdateInput

type OptionUpdateInput struct {
	AudienceID ID     `json:"audience_id"`
	Name       string `json:"name"`
	Option     Option `json:"-"`
	// contains filtered or unexported fields
}

OptionUpdateInput is the option update input

func (OptionUpdateInput) Validate

func (o OptionUpdateInput) Validate() error

Validate validates OptionUpdateInput

type PasswordManager

type PasswordManager interface {
	HashPassword(password string) (string, error)
	CheckPasswordHash(password, hash string) bool
	EnforcePasswordPolicy(enabled bool)
	ValidatePassword(password string) error
	PasswordExpiry() time.Duration
	MaxLoginAttempts() int
	AccountLockoutPeriod() time.Duration
}

PasswordManager is an interface for hashing and validation of passwords

type PermissionsUpdate

type PermissionsUpdate struct {
	Add       oauth.ScopeSet `json:"add,omitempty"`
	Remove    oauth.ScopeSet `json:"remove,omitempty"`
	Overwrite bool           `json:"overwrite"`
}

PermissionsUpdate is used to modify permissions

type RPCServer

type RPCServer struct {
	Controller
	pb.UnimplementedHiroServer
}

RPCServer is a hiro rpc server

func NewRPCServer

func NewRPCServer(c Controller) *RPCServer

NewRPCServer returns a new hiro rpc Server

func (*RPCServer) ApplicationCreate

func (s *RPCServer) ApplicationCreate(ctx context.Context, params *pb.ApplicationCreateRequest) (*pb.Application, error)

ApplicationCreate implements the pb.HiroServer interface

func (*RPCServer) ApplicationDelete

func (s *RPCServer) ApplicationDelete(ctx context.Context, params *pb.ApplicationDeleteRequest) (*empty.Empty, error)

ApplicationDelete implements the pb.HiroServer interface

func (*RPCServer) ApplicationGet

func (s *RPCServer) ApplicationGet(ctx context.Context, params *pb.ApplicationGetRequest) (*pb.Application, error)

ApplicationGet implements the pb.HiroServer interface

func (*RPCServer) ApplicationList

func (s *RPCServer) ApplicationList(req *pb.ApplicationListRequest, stream pb.Hiro_ApplicationListServer) error

ApplicationList implements the pb.HiroServer interface

func (*RPCServer) ApplicationUpdate

func (s *RPCServer) ApplicationUpdate(ctx context.Context, params *pb.ApplicationUpdateRequest) (*pb.Application, error)

ApplicationUpdate implements the pb.HiroServer interface

func (*RPCServer) AudienceCreate

func (s *RPCServer) AudienceCreate(ctx context.Context, params *pb.AudienceCreateRequest) (*pb.Audience, error)

AudienceCreate implements the pb.HiroServer interface

func (*RPCServer) AudienceDelete

func (s *RPCServer) AudienceDelete(ctx context.Context, params *pb.AudienceDeleteRequest) (*empty.Empty, error)

AudienceDelete implements the pb.HiroServer interface

func (*RPCServer) AudienceGet

func (s *RPCServer) AudienceGet(ctx context.Context, params *pb.AudienceGetRequest) (*pb.Audience, error)

AudienceGet implements the pb.HiroServer interface

func (*RPCServer) AudienceList

func (s *RPCServer) AudienceList(req *pb.AudienceListRequest, stream pb.Hiro_AudienceListServer) error

AudienceList implements the pb.HiroServer interface

func (*RPCServer) AudienceUpdate

func (s *RPCServer) AudienceUpdate(ctx context.Context, params *pb.AudienceUpdateRequest) (*pb.Audience, error)

AudienceUpdate implements the pb.HiroServer interface

func (*RPCServer) SecretCreate

func (s *RPCServer) SecretCreate(ctx context.Context, params *pb.SecretCreateRequest) (*pb.Secret, error)

SecretCreate implements the pb.HiroServer interface

func (*RPCServer) SecreteDelete

func (s *RPCServer) SecreteDelete(ctx context.Context, params *pb.SecretDeleteRequest) (*empty.Empty, error)

SecreteDelete implements the pb.HiroServer interface

type RequestToken

type RequestToken struct {
	ID                  ID                        `json:"id" db:"id"`
	Type                oauth.RequestTokenType    `json:"type" db:"type"`
	CreatedAt           oauth.Time                `json:"created_at" db:"created_at"`
	Audience            ID                        `json:"audience_id" db:"audience_id"`
	ApplicationID       ID                        `json:"application_id" db:"application_id"`
	UserID              ID                        `json:"user_id,omitempty" db:"user_id"`
	Scope               oauth.Scope               `json:"scope,omitempty" db:"scope"`
	Passcode            *string                   `json:"passcode,omitempty" db:"passcode"`
	ExpiresAt           oauth.Time                `json:"expires_at" db:"expires_at"`
	CodeChallenge       oauth.PKCEChallenge       `json:"code_challenge,omitempty" db:"code_challenge"`
	CodeChallengeMethod oauth.PKCEChallengeMethod `json:"code_challenge_method,omitempty" db:"code_challenge_method"`
	LoginAttempts       *int                      `json:"login_attempts,omitempty" db:"login_attempts"`
	AppURI              *oauth.URI                `json:"app_uri,omitempty" db:"app_uri"`
	RedirectURI         *oauth.URI                `json:"redirect_uri,omitempty" db:"redirect_uri"`
	State               *string                   `json:"state,omitempty" db:"state"`
}

RequestToken is the backend representation of an oauth.RequestToken

type Role

type Role struct {
	ID          ID             `json:"id" db:"id"`
	AudienceID  ID             `json:"audience_id" db:"audience_id"`
	Name        string         `json:"name" db:"name"`
	Slug        string         `json:"slug" db:"slug"`
	Description *string        `json:"description,omitempty" db:"description"`
	Permissions oauth.ScopeSet `json:"permissions,omitempty" db:"-"`
	CreatedAt   time.Time      `json:"created_at" db:"created_at"`
	UpdatedAt   *time.Time     `json:"updated_at,omitempty" db:"updated_at"`
	Metadata    common.Map     `json:"metadata,omitempty" db:"metadata"`
}

Role is the database model for an role

type RoleController added in v0.1.1

type RoleController interface {
	RoleCreate(ctx context.Context, params RoleCreateInput) (*Role, error)
	RoleGet(ctx context.Context, params RoleGetInput) (*Role, error)
	RoleList(ctx context.Context, params RoleListInput) ([]*Role, error)
	RoleUpdate(ctx context.Context, params RoleUpdateInput) (*Role, error)
	RoleDelete(ctx context.Context, params RoleDeleteInput) error
}

RoleController is roles API interfcace

type RoleCreateInput

type RoleCreateInput struct {
	AudienceID  ID             `json:"audience_id"`
	Name        string         `json:"name"`
	Description *string        `json:"description,omitempty"`
	Permissions oauth.ScopeSet `json:"permissions,omitempty"`
	Metadata    common.Map     `json:"metadata,omitempty"`
}

RoleCreateInput is the role create request

func (RoleCreateInput) ValidateWithContext

func (a RoleCreateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the RoleCreateInput struct

type RoleDeleteInput

type RoleDeleteInput struct {
	RoleID ID `json:"role_id"`
}

RoleDeleteInput is the role delete request input

func (RoleDeleteInput) ValidateWithContext

func (a RoleDeleteInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the RoleDeleteInput

type RoleGetInput

type RoleGetInput struct {
	RoleID  *ID     `json:"role_id,omitempty"`
	Name    *string `json:"name,omitempty"`
	Preload *bool   `json:"preload,omitempty"`
}

RoleGetInput is used to get an role for the id

func (RoleGetInput) ValidateWithContext

func (a RoleGetInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the RoleGetInput struct

type RoleListInput

type RoleListInput struct {
	Limit  *uint64 `json:"limit,omitempty"`
	Offset *uint64 `json:"offset,omitempty"`
}

RoleListInput is the role list request

func (RoleListInput) ValidateWithContext

func (a RoleListInput) ValidateWithContext(context.Context) error

ValidateWithContext handles validation of the RoleListInput struct

type RoleType

type RoleType string

RoleType defines an role type

type RoleUpdateInput

type RoleUpdateInput struct {
	RoleID      ID                 `json:"id" structs:"-"`
	Name        *string            `json:"name" structs:"name,omitempty"`
	Description *string            `json:"description,omitempty" structs:"description,omitempty"`
	Permissions *PermissionsUpdate `json:"permissions,omitempty" structs:"-"`
	Metadata    common.Map         `json:"metadata,omitempty" structs:"metadata,omitempty"`
}

RoleUpdateInput is the role update request

func (RoleUpdateInput) ValidateWithContext

func (a RoleUpdateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the RoleUpdateInput struct

type Secret

type Secret struct {
	ID         ID                    `json:"id" db:"id"`
	Type       SecretType            `json:"type"`
	AudienceID ID                    `json:"audience_id" db:"audience_id"`
	Algorithm  *oauth.TokenAlgorithm `json:"algorithm,omitempty" db:"algorithm"`
	Key        string                `json:"key" db:"key"`
	CreatedAt  time.Time             `json:"created_at" db:"created_at"`
	ExpiresAt  *time.Time            `json:"expires_at,omitempty" db:"expires_at"`
}

Secret is a secret key implemenation of oauth.TokenSecret

func (*Secret) FromProto

func (s *Secret) FromProto(p *pb.Secret)

FromProto convert the proto Secret to an api Secret

func (Secret) ToProto

func (s Secret) ToProto() *pb.Secret

ToProto converts the Secret to its protobuf conterpart

type SecretCreateInput

type SecretCreateInput struct {
	AudienceID ID                    `json:"audience_id"`
	Type       SecretType            `json:"type"`
	Algorithm  *oauth.TokenAlgorithm `json:"algorithm,omitempty"`
	Key        *string               `json:"key,omitempty"`
	ExpiresAt  *time.Time            `json:"expires_at,omitempty"`
}

SecretCreateInput is the params used to create a secret

func (SecretCreateInput) ValidateWithContext

func (s SecretCreateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the AudienceCreateInput struct

type SecretCreateRoute

type SecretCreateRoute func(ctx context.Context, params *SecretCreateInput) api.Responder

SecretCreateRoute is the secret create route definition

func (SecretCreateRoute) Methods

func (SecretCreateRoute) Methods() []string

Methods implements api.Route

func (SecretCreateRoute) Name

func (SecretCreateRoute) Name() string

Name implements api.Route

func (SecretCreateRoute) Path

func (SecretCreateRoute) Path() string

Path implements api.Route

func (SecretCreateRoute) RequireAuth

func (SecretCreateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (SecretCreateRoute) Scopes

Scopes implements oauth.Route

type SecretDeleteInput

type SecretDeleteInput struct {
	SecretID ID `json:"secret_id"`
}

SecretDeleteInput is the secret delete request input

func (SecretDeleteInput) ValidateWithContext

func (s SecretDeleteInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the SecretDeleteInput

type SecretDeleteRoute

type SecretDeleteRoute func(ctx context.Context, params *SecretDeleteInput) api.Responder

SecretDeleteRoute is the secret create route definition

func (SecretDeleteRoute) Methods

func (SecretDeleteRoute) Methods() []string

Methods implements api.Route

func (SecretDeleteRoute) Name

func (SecretDeleteRoute) Name() string

Name implements api.Route

func (SecretDeleteRoute) Path

func (SecretDeleteRoute) Path() string

Path implements api.Route

func (SecretDeleteRoute) RequireAuth

func (SecretDeleteRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (SecretDeleteRoute) Scopes

Scopes implements oauth.Route

type SecretType

type SecretType string

SecretType is a secret type

const (
	// SecretTypeToken are used for token signing
	SecretTypeToken SecretType = "token"

	// SecretTypeSession are used for session signing
	SecretTypeSession SecretType = "session"
)

type SecretsController added in v0.1.1

type SecretsController interface {
	SecretCreate(ctx context.Context, params SecretCreateInput) (*Secret, error)
	SecretDelete(ctx context.Context, params SecretDeleteInput) error
}

SecretsController is the secrets API interface

type Service added in v0.1.1

type Service struct {
	// contains filtered or unexported fields
}

Service is the core hiro service object Platoform projects use the hiro.Service to provide services

func NewService added in v0.1.1

func NewService(opts ...ServiceOption) (*Service, error)

NewService creates a new service object

func (*Service) APIServer added in v0.1.1

func (d *Service) APIServer() *api.Server

APIServer returns the api server that services can register with

func (*Service) AddJob added in v0.1.1

func (d *Service) AddJob(job Job) error

AddJob adds a job to the service scheduler

func (*Service) RPCServer added in v0.1.1

func (d *Service) RPCServer() *grpc.Server

RPCServer returns the rpc server services can register with

func (*Service) Run added in v0.1.1

func (d *Service) Run() error

Run starts the service, blocks and handle interrupts

func (*Service) Serve added in v0.1.1

func (d *Service) Serve(ready func()) error

Serve starts the dameon server

func (*Service) Shutdown added in v0.1.1

func (d *Service) Shutdown(ctx context.Context) error

Shutdown terminates the service services

type ServiceOption added in v0.1.1

type ServiceOption func(d *Service)

ServiceOption is a service option

func WithAPIOptions

func WithAPIOptions(o ...api.Option) ServiceOption

WithAPIOptions sets api server options; mutally exclusive with WithAPIServer

func WithAPIServer

func WithAPIServer(srv *api.Server) ServiceOption

WithAPIServer sets the service api server; mutally exclusive with WithAPIOptions

func WithBackendOptions

func WithBackendOptions(o []BackendOption) ServiceOption

WithBackendOptions sets backend options

func WithController

func WithController(c Controller) ServiceOption

WithController sets the service controller

func WithName

func WithName(name string) ServiceOption

WithName sets the service name

func WithOAuthController

func WithOAuthController(o oauth.Controller) ServiceOption

WithOAuthController set the service oauth controller

func WithRPCServer

func WithRPCServer(r *grpc.Server) ServiceOption

WithRPCServer sets the service rpc server

func WithServerAddr

func WithServerAddr(addr string) ServiceOption

WithServerAddr sets the service listening address

func WithSessionController

func WithSessionController(c session.Controller) ServiceOption

WithSessionController set the service session controller

type Session

type Session struct {
	ID         ID         `json:"id" db:"id"`
	AudienceID ID         `json:"audience_id" db:"audience_id"`
	UserID     ID         `json:"user_id" db:"user_id"`
	Data       string     `json:"data" db:"data"`
	CreatedAt  time.Time  `json:"created_at" db:"created_at"`
	ExpiresAt  time.Time  `json:"expires_at" db:"expires_at"`
	RevokedAt  *time.Time `json:"revoked_at,omitempty" db:"revoked_at"`
}

Session is the backend store representation of session.Session

type SessionKey

type SessionKey Secret

SessionKey is a wrapper around a token secret

func (SessionKey) Block

func (s SessionKey) Block() []byte

Block returns the session key block

func (SessionKey) Hash

func (s SessionKey) Hash() []byte

Hash returns the session key hash

type SpecGetInput

type SpecGetInput struct {
	Format string `json:"format"`
	Pretty bool   `json:"pretty"`
}

SpecGetInput is the input for spec get method

type SpecRoute

type SpecRoute func(ctx context.Context, params *SpecGetInput) api.Responder

SpecRoute is the swagger spec route handler

func (SpecRoute) Methods

func (SpecRoute) Methods() []string

Methods implements api.Route

func (SpecRoute) Name

func (SpecRoute) Name() string

Name implements api.Route

func (SpecRoute) Path

func (SpecRoute) Path() string

Path implements api.Route

type TxHandler

type TxHandler func(context.Context, DB) error

TxHandler is a db transaction handler

type User

type User struct {
	ID                ID              `json:"id" db:"id"`
	CreatedAt         time.Time       `json:"created_at" db:"created_at"`
	UpdatedAt         *time.Time      `json:"updated_at,omitempty" db:"updated_at"`
	Login             string          `json:"login" db:"login"`
	Password          *string         `json:"-" db:"-"`
	PasswordHash      *string         `json:"-" db:"password_hash,omitempty"`
	PasswordExpiresAt *time.Time      `json:"password_expires_at,omitempty" db:"password_expires_at"`
	LockedUntil       *time.Time      `json:"locked_until,omitempty" db:"locked_until,omitempty"`
	Roles             []string        `json:"roles,omitempty"`
	Permissions       oauth.ScopeSet  `json:"permissions,omitempty" db:"-"`
	Profile           *openid.Profile `json:"profile,omitempty" db:"profile"`
	Metadata          common.Map      `json:"metadata,omitempty" db:"metadata"`
}

User is a hiro user

type UserController added in v0.1.1

type UserController interface {
	UserCreate(ctx context.Context, params UserCreateInput) (*User, error)
	UserGet(ctx context.Context, params UserGetInput) (*User, error)
	UserList(ctx context.Context, params UserListInput) ([]*User, error)
	UserUpdate(ctx context.Context, params UserUpdateInput) (*User, error)
	UserDelete(ctx context.Context, params UserDeleteInput) error
}

UserController is the user API interface

type UserCountRoute

type UserCountRoute func(ctx context.Context, params *UserListInput) api.Responder

UserCountRoute is the user count route definition

func (UserCountRoute) Methods

func (UserCountRoute) Methods() []string

Methods implements api.Route

func (UserCountRoute) Name

func (UserCountRoute) Name() string

Name implements api.Route

func (UserCountRoute) Path

func (UserCountRoute) Path() string

Path implements api.Route

func (UserCountRoute) RequireAuth

func (UserCountRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (UserCountRoute) Scopes

func (UserCountRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type UserCreateInput

type UserCreateInput struct {
	Login             string          `json:"login"`
	Password          *string         `json:"password,omitempty"`
	Roles             []string        `json:"roles,omitempty"`
	Profile           *openid.Profile `json:"profile,omitempty"`
	PasswordExpiresAt *time.Time      `json:"password_expires_at,omitempty" `
	Metadata          common.Map      `json:"metadata,omitempty"`
}

UserCreateInput is the user create request input

func (UserCreateInput) ValidateWithContext

func (u UserCreateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the UserCreateInput struct

type UserCreateRoute

type UserCreateRoute func(ctx context.Context, params *UserCreateInput) api.Responder

UserCreateRoute is the user create route definition

func (UserCreateRoute) Methods

func (UserCreateRoute) Methods() []string

Methods implements api.Route

func (UserCreateRoute) Name

func (UserCreateRoute) Name() string

Name implements api.Route

func (UserCreateRoute) Path

func (UserCreateRoute) Path() string

Path implements api.Route

func (UserCreateRoute) RequireAuth

func (UserCreateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (UserCreateRoute) Scopes

func (UserCreateRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type UserDeleteInput

type UserDeleteInput struct {
	UserID ID `json:"user_id"`
}

UserDeleteInput is the user delete request input

func (UserDeleteInput) ValidateWithContext

func (u UserDeleteInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the UserDeleteInput

type UserDeleteRoute

type UserDeleteRoute func(ctx context.Context, params *UserDeleteInput) api.Responder

UserDeleteRoute is the user create route definition

func (UserDeleteRoute) Methods

func (UserDeleteRoute) Methods() []string

Methods implements api.Route

func (UserDeleteRoute) Name

func (UserDeleteRoute) Name() string

Name implements api.Route

func (UserDeleteRoute) Path

func (UserDeleteRoute) Path() string

Path implements api.Route

func (UserDeleteRoute) RequireAuth

func (UserDeleteRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (UserDeleteRoute) Scopes

func (UserDeleteRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type UserGetInput

type UserGetInput struct {
	UserID ID      `json:"user_id,omitempty"`
	Login  *string `json:"login,omitempty"`
}

UserGetInput is used to get an user for the id

func (UserGetInput) ValidateWithContext

func (u UserGetInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the UserGetInput struct

type UserGetRoute

type UserGetRoute func(ctx context.Context, params *UserGetInput) api.Responder

UserGetRoute is the user create route definition

func (UserGetRoute) Methods

func (UserGetRoute) Methods() []string

Methods implements api.Route

func (UserGetRoute) Name

func (UserGetRoute) Name() string

Name implements api.Route

func (UserGetRoute) Path

func (UserGetRoute) Path() string

Path implements api.Route

func (UserGetRoute) RequireAuth

func (UserGetRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (UserGetRoute) Scopes

func (UserGetRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type UserListInput

type UserListInput struct {
	Limit  *uint64 `json:"limit,omitempty"`
	Offset *uint64 `json:"offset,omitempty"`
	Count  *uint64 `json:"count,omitempty"`
}

UserListInput is the user list request

func (UserListInput) ValidateWithContext

func (u UserListInput) ValidateWithContext(context.Context) error

ValidateWithContext handles validation of the UserListInput struct

type UserListRoute

type UserListRoute func(ctx context.Context, params *UserListInput) api.Responder

UserListRoute is the user count route definition

func (UserListRoute) Methods

func (UserListRoute) Methods() []string

Methods implements api.Route

func (UserListRoute) Name

func (UserListRoute) Name() string

Name implements api.Route

func (UserListRoute) Path

func (UserListRoute) Path() string

Path implements api.Route

func (UserListRoute) RequireAuth

func (UserListRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (UserListRoute) Scopes

func (UserListRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

type UserUpdateInput

type UserUpdateInput struct {
	UserID            ID              `json:"user_id" structs:"-"`
	Login             *string         `json:"login,omitempty"`
	Password          *string         `json:"password,omitempty" structs:"-"`
	Profile           *openid.Profile `json:"profile,omitempty" structs:"profile,omitempty"`
	PasswordExpiresAt *time.Time      `json:"-" structs:"password_expires_at,omitempty"`
	LockedUntil       *time.Time      `json:"locked_until,omitempty" structs:"-"`
	Roles             []string        `json:"roles,omitempty" structs:"-"`
	Metadata          common.Map      `json:"metadata,omitempty" structs:"-"`
}

UserUpdateInput is the update user request input

func (UserUpdateInput) ValidateWithContext

func (u UserUpdateInput) ValidateWithContext(ctx context.Context) error

ValidateWithContext handles validation of the UserCreateInput struct

type UserUpdateRoute

type UserUpdateRoute func(ctx context.Context, params *UserUpdateInput) api.Responder

UserUpdateRoute is the user create route definition

func (UserUpdateRoute) Methods

func (UserUpdateRoute) Methods() []string

Methods implements api.Route

func (UserUpdateRoute) Name

func (UserUpdateRoute) Name() string

Name implements api.Route

func (UserUpdateRoute) Path

func (UserUpdateRoute) Path() string

Path implements api.Route

func (UserUpdateRoute) RequireAuth

func (UserUpdateRoute) RequireAuth() []api.CredentialType

RequireAuth implements the api.AuthorizedRoute

func (UserUpdateRoute) Scopes

func (UserUpdateRoute) Scopes() oauth.ScopeList

Scopes implements oauth.Route

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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