actions

package
v0.378.1-next.10 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultBearerTokenExpiry time.Duration = time.Hour * 24
	ResetTokenExpiry         time.Duration = time.Minute * 15
)

Variables

View Source
var (
	ErrInvalidToken     = common.NewAuthenticationFailedMessageErr("cannot be parsed or verified as a valid JWT")
	ErrTokenExpired     = common.NewAuthenticationFailedMessageErr("token has expired")
	ErrIdentityNotFound = common.NewAuthenticationFailedMessageErr("identity not found")
)

Functions

func AuthoriseAction

func AuthoriseAction(scope *Scope, input map[string]any, rowsToAuthorise []map[string]any) (authorised bool, err error)

AuthoriseAction checks authorisation for rows using the permission and role rules applicable for an action, which could be defined at model- and action- levels.

func AuthoriseForActionType

func AuthoriseForActionType(scope *Scope, opType proto.ActionType, rowsToAuthorise []map[string]any) (authorised bool, err error)

AuthoriseForActionType checks authorisation for rows using permission and role rules defined for some action type, i.e. agnostic to any action.

func Create

func Create(scope *Scope, input map[string]any) (res map[string]any, err error)

func CreateExternalIdentity deprecated

func CreateExternalIdentity(ctx context.Context, schema *proto.Schema, externalId string, issuer string, jwt string) (*auth.Identity, error)

Deprecated: used by the the authenticate action which is to be deprecated.

func CreateIdentity

func CreateIdentity(ctx context.Context, schema *proto.Schema, email string, password string, issuer string) (*auth.Identity, error)

func CreateIdentityWithIdTokenClaims added in v0.372.0

func CreateIdentityWithIdTokenClaims(ctx context.Context, schema *proto.Schema, externalId string, issuer string, claims oauth.IdTokenClaims) (*auth.Identity, error)

func Delete

func Delete(scope *Scope, input map[string]any) (res *string, err error)

func Execute

func Execute(scope *Scope, inputs any) (result any, meta *common.ResponseMetadata, err error)

func FindIdentityByEmail

func FindIdentityByEmail(ctx context.Context, schema *proto.Schema, email string, issuer string) (*auth.Identity, error)

func FindIdentityByExternalId

func FindIdentityByExternalId(ctx context.Context, schema *proto.Schema, externalId string, issuer string) (*auth.Identity, error)

func FindIdentityById

func FindIdentityById(ctx context.Context, schema *proto.Schema, id string) (*auth.Identity, error)

func GenerateBearerToken

func GenerateBearerToken(ctx context.Context, identityId string) (string, error)

func GenerateListStatement

func GenerateListStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, *Page, error)

func GenerateResetToken deprecated

func GenerateResetToken(ctx context.Context, identityId string) (string, error)

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func Get

func Get(scope *Scope, input map[string]any) (map[string]any, error)

func HandleAuthorizationHeader deprecated

func HandleAuthorizationHeader(ctx context.Context, schema *proto.Schema, headers http.Header) (*auth.Identity, error)

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func HandleBearerToken deprecated

func HandleBearerToken(ctx context.Context, schema *proto.Schema, token string) (*auth.Identity, error)

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func List

func List(scope *Scope, input map[string]any) (map[string]any, error)

func ResetPassword deprecated

func ResetPassword(scope *Scope, input map[string]any) error

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func ResetRequestPassword deprecated

func ResetRequestPassword(scope *Scope, input map[string]any) error

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func TryResolveAuthorisationEarly

func TryResolveAuthorisationEarly(scope *Scope, permissions []*proto.PermissionRule) (canResolveAll bool, authorised bool, err error)

TryResolveAuthorisationEarly will attempt to check authorisation early without row-based querying. This will take into account logical conditions and multiple expression and role permission attributes.

func Update

func Update(scope *Scope, input map[string]any) (res map[string]any, err error)

func UpdateIdentityWithIdTokenClaims added in v0.372.0

func UpdateIdentityWithIdTokenClaims(ctx context.Context, schema *proto.Schema, externalId string, issuer string, claims oauth.IdTokenClaims) (*auth.Identity, error)

func ValidateBearerToken deprecated

func ValidateBearerToken(ctx context.Context, tokenString string) (string, string, error)

Verifies the bearer token and returns the JWT subject and issuer.

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

func ValidateResetToken deprecated

func ValidateResetToken(ctx context.Context, tokenString string) (string, error)

Verifies the reset token and returns the JWT subject.

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

Types

type ActionOperator

type ActionOperator int

An ActionOperator gives a symbolic, machine-readable name to each of the comparison operators that Keel Actions work with at a CONCEPTUAL level.

By design, the ActionOperator has no knowledge (in of itself) of how these might be expressed in schema's or in request inputs, or in expressions for example.

const (
	Unknown ActionOperator = iota

	After
	Before
	Contains
	Equals
	EndsWith
	GreaterThan
	GreaterThanEquals
	LessThan
	LessThanEquals
	NotContains
	NotEquals
	NotOneOf
	OneOf
	OnOrAfter
	OnOrBefore
	StartsWith
)

type AuthenticateResult

type AuthenticateResult struct {
	Token           string `json:"token"`
	IdentityCreated bool   `json:"identityCreated"`
}

func Authenticate deprecated

func Authenticate(scope *Scope, input map[string]any) (*AuthenticateResult, error)

Authenticate will return the identity ID if it is successfully authenticated or when a new identity is created.

Deprecated: we will be deprecating the authenticate action and password flow in favour of the new auth endpoints

type Claims

type Claims struct {
	jwt.RegisteredClaims
}

https://pkg.go.dev/github.com/golang-jwt/jwt/v4#RegisteredClaims

type ExternalUserDetails

type ExternalUserDetails struct {
	Email         string `json:"email"`
	EmailVerified bool   `json:"email-verified"`
}

type JoinOption

type JoinOption struct {
	Type JoinType
}

type JoinType

type JoinType string
const (
	JoinTypeInner JoinType = "INNER"
	JoinTypeLeft  JoinType = "LEFT"
)

type Page

type Page struct {
	First  int
	Last   int
	After  string
	Before string
}

A Page describes which page you want from a list of records, in the style of this "Connection" pattern: https://relay.dev/graphql/connections.htm

Consider for example, that you previously fetched a page of 10 records and from that previous response you also knew that the last of those 10 records could be referred to with the opaque cursor "abc123". Armed with that information you can ask for the next page of 10 records by setting First to 10, and After to "abc123".

To move backwards, you'd set the Last and Before fields instead.

When you have no prior positional context you should specify First but leave Before and After to the empty string. This gives you the first N records.

func ParsePage

func ParsePage(args map[string]any) (Page, error)

ParsePage extracts page mandate information from the given map and uses it to compose a Page.

type PageInfo

type PageInfo struct {
	// Count returns the number of rows returned for the current page
	Count int

	// TotalCount returns the total number of rows across all pages
	TotalCount int

	// HasNextPage indicates if there is a subsequent page after the current page
	HasNextPage bool

	// StartCursor is the identifier representing the first row in the set
	StartCursor string

	// EndCursor is the identifier representing the last row in the set
	EndCursor string
}

func (*PageInfo) ToMap

func (pi *PageInfo) ToMap() map[string]any

type QueryBuilder

type QueryBuilder struct {
	// The base model this query builder is acting on.
	Model *proto.Model
	// contains filtered or unexported fields
}

func NewQuery

func NewQuery(model *proto.Model, opts ...QueryBuilderOption) *QueryBuilder

func (*QueryBuilder) AddWriteValue

func (query *QueryBuilder) AddWriteValue(operand *QueryOperand, value *QueryOperand)

Includes a value to be written during an INSERT or UPDATE.

func (*QueryBuilder) AddWriteValues

func (query *QueryBuilder) AddWriteValues(values map[string]*QueryOperand)

Includes values to be written during an INSERT or UPDATE.

func (*QueryBuilder) And

func (query *QueryBuilder) And()

Appends the next condition with a logical AND.

func (*QueryBuilder) AppendDistinctOn

func (query *QueryBuilder) AppendDistinctOn(operand *QueryOperand)

Include a column in this table in DISTINCT ON.

func (*QueryBuilder) AppendOrderBy

func (query *QueryBuilder) AppendOrderBy(operand *QueryOperand, direction string)

Include a column in ORDER BY. If the column already exists, then just update the sort direction.

func (*QueryBuilder) AppendReturning

func (query *QueryBuilder) AppendReturning(operand *QueryOperand)

Include a column in RETURNING.

func (*QueryBuilder) AppendSelect

func (query *QueryBuilder) AppendSelect(operand *QueryOperand)

Includes a column in SELECT.

func (*QueryBuilder) AppendSelectClause

func (query *QueryBuilder) AppendSelectClause(clause string)

Include a clause in SELECT.

func (*QueryBuilder) ApplyPaging

func (query *QueryBuilder) ApplyPaging(page Page) error

Apply pagination filters to the query.

func (*QueryBuilder) CloseParenthesis

func (query *QueryBuilder) CloseParenthesis()

Closes the current conditional scope in the where expression (i.e. close parethesis).

func (*QueryBuilder) Copy

func (query *QueryBuilder) Copy() *QueryBuilder

Creates a copy of the query builder.

func (*QueryBuilder) DeleteStatement

func (query *QueryBuilder) DeleteStatement(ctx context.Context) *Statement

Generates an executable DELETE statement with the list of arguments.

func (*QueryBuilder) InsertStatement

func (query *QueryBuilder) InsertStatement(ctx context.Context) *Statement

Generates an executable INSERT statement with the list of arguments.

func (*QueryBuilder) Join

func (query *QueryBuilder) Join(joinModel string, joinField *QueryOperand, modelField *QueryOperand)

Include an JOIN clause.

func (*QueryBuilder) Limit

func (query *QueryBuilder) Limit(limit int)

Set the LIMIT to a number.

func (*QueryBuilder) OpenParenthesis

func (query *QueryBuilder) OpenParenthesis()

Opens a new conditional scope in the where expression (i.e. open parethesis).

func (*QueryBuilder) Or

func (query *QueryBuilder) Or()

Appends the next condition with a logical OR.

func (*QueryBuilder) SelectStatement

func (query *QueryBuilder) SelectStatement() *Statement

Generates an executable SELECT statement with the list of arguments.

func (*QueryBuilder) UpdateStatement

func (query *QueryBuilder) UpdateStatement(ctx context.Context) *Statement

Generates an executable UPDATE statement with the list of arguments.

func (*QueryBuilder) Where

func (query *QueryBuilder) Where(left *QueryOperand, operator ActionOperator, right *QueryOperand) error

Include a WHERE condition, ANDed to the existing filters (unless an OR has been specified)

type QueryBuilderOption

type QueryBuilderOption func(qb *QueryBuilder)

func WithJoinType

func WithJoinType(joinType JoinType) QueryBuilderOption

type QueryOperand

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

func AllFields

func AllFields() *QueryOperand

All fields on the query builder's model.

func ExpressionField

func ExpressionField(fragments []string, field string) *QueryOperand

Some field from the fragments of an expression or input.

func Field

func Field(field string) *QueryOperand

Some field on the query builder's model.

func IdField

func IdField() *QueryOperand

The identifier field on the query builder's model.

func InlineQuery

func InlineQuery(query *QueryBuilder, column *QueryOperand) *QueryOperand

Represents an inline query. column refers to the single column to select from the inline query statement.

func Null

func Null() *QueryOperand

Represents a null value operand.

func Raw added in v0.369.1

func Raw(sql string) *QueryOperand

Represents a raw SQL operand.

func Value

func Value(value any) *QueryOperand

Represents a value operand.

func (*QueryOperand) IsField

func (o *QueryOperand) IsField() bool

func (*QueryOperand) IsInlineQuery

func (o *QueryOperand) IsInlineQuery() bool

A query builder to be evaluated and injected as an operand.

func (*QueryOperand) IsNull

func (o *QueryOperand) IsNull() bool

func (*QueryOperand) IsRaw added in v0.369.1

func (o *QueryOperand) IsRaw() bool

Raw SQL to be used as a operand.

func (*QueryOperand) IsValue

func (o *QueryOperand) IsValue() bool

type Relationship

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

type Row

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

type Rows

type Rows = []map[string]interface{}

type Scope

type Scope struct {
	Context context.Context
	Action  *proto.Action
	Model   *proto.Model
	Job     *proto.Job
	Schema  *proto.Schema
}

func NewJobScope

func NewJobScope(
	ctx context.Context,
	job *proto.Job,
	schema *proto.Schema) *Scope

func NewModelScope

func NewModelScope(
	ctx context.Context,
	model *proto.Model,
	schema *proto.Schema) *Scope

func NewScope

func NewScope(
	ctx context.Context,
	action *proto.Action,
	schema *proto.Schema) *Scope

func (*Scope) WithContext

func (s *Scope) WithContext(ctx context.Context) *Scope

type Statement

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

The templated SQL statement and associated values, ready to be executed.

func GenerateCreateStatement

func GenerateCreateStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func GenerateDeleteStatement

func GenerateDeleteStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func GenerateGetStatement

func GenerateGetStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func GeneratePermissionStatement

func GeneratePermissionStatement(scope *Scope, permissions []*proto.PermissionRule, input map[string]any, idsToAuthorise []string) (*Statement, error)

func GenerateUpdateStatement

func GenerateUpdateStatement(query *QueryBuilder, scope *Scope, input map[string]any) (*Statement, error)

func (*Statement) Execute

func (statement *Statement) Execute(ctx context.Context) (int, error)

Execute the SQL statement against the database, returning the number of rows affected.

func (*Statement) ExecuteToMany

func (statement *Statement) ExecuteToMany(ctx context.Context, page *Page) (Rows, *PageInfo, error)

Execute the SQL statement against the database, return the rows, number of rows affected, and a boolean to indicate if there is a next page.

func (*Statement) ExecuteToSingle

func (statement *Statement) ExecuteToSingle(ctx context.Context) (map[string]any, error)

Execute the SQL statement against the database and expects a single row, returns the single row or nil if no data is found.

func (*Statement) SqlArgs

func (statement *Statement) SqlArgs() []any

func (*Statement) SqlTemplate

func (statement *Statement) SqlTemplate() string

Jump to

Keyboard shortcuts

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