authz

package
v0.32.2 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2023 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultSortBy = "createdAt"

Variables

This section is empty.

Functions

func CreateHandler added in v0.11.0

func CreateHandler(svc WarrantService, w http.ResponseWriter, r *http.Request) error

func DeleteHandler added in v0.11.0

func DeleteHandler(svc WarrantService, w http.ResponseWriter, r *http.Request) error

func ListHandler added in v0.11.0

func ListHandler(svc WarrantService, w http.ResponseWriter, r *http.Request) error

Types

type FilterOptions

type FilterOptions struct {
	ObjectType string
	ObjectId   string
	Relation   string
	Subject    *SubjectSpec
	Policy     Policy
	ObjectIds  []string
	SubjectIds []string
}

FilterOptions type for the filter options available on the warrant table

type Model added in v0.8.0

type Model interface {
	GetID() int64
	GetObjectType() string
	GetObjectId() string
	GetRelation() string
	GetSubjectType() string
	GetSubjectId() string
	GetSubjectRelation() string
	GetPolicy() Policy
	GetPolicyHash() string
	GetCreatedAt() time.Time
	GetUpdatedAt() time.Time
	GetDeletedAt() *time.Time
	ToWarrantSpec() *WarrantSpec
	String() string
}

type MySQLRepository

type MySQLRepository struct {
	database.SQLRepository
}

func NewMySQLRepository

func NewMySQLRepository(db *database.MySQL) *MySQLRepository

func (MySQLRepository) Create

func (repo MySQLRepository) Create(ctx context.Context, model Model) (int64, error)

func (MySQLRepository) Delete added in v0.28.0

func (repo MySQLRepository) Delete(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) error

func (MySQLRepository) DeleteById

func (repo MySQLRepository) DeleteById(ctx context.Context, ids []int64) error

func (MySQLRepository) Get

func (repo MySQLRepository) Get(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) (Model, error)

func (MySQLRepository) GetAllMatchingObject added in v0.28.0

func (repo MySQLRepository) GetAllMatchingObject(ctx context.Context, objectType string, objectId string) ([]Model, error)

func (MySQLRepository) GetAllMatchingObjectAndRelation

func (repo MySQLRepository) GetAllMatchingObjectAndRelation(ctx context.Context, objectType string, objectId string, relation string) ([]Model, error)

func (MySQLRepository) GetAllMatchingObjectAndRelationBySubjectType added in v0.16.1

func (repo MySQLRepository) GetAllMatchingObjectAndRelationBySubjectType(ctx context.Context, objectType string, objectId string, relation string, subjectType string) ([]Model, error)

func (MySQLRepository) GetAllMatchingObjectRelationAndSubject added in v0.18.0

func (repo MySQLRepository) GetAllMatchingObjectRelationAndSubject(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string) ([]Model, error)

func (MySQLRepository) GetAllMatchingSubject added in v0.28.0

func (repo MySQLRepository) GetAllMatchingSubject(ctx context.Context, subjectType string, subjectId string) ([]Model, error)

func (MySQLRepository) GetByID

func (repo MySQLRepository) GetByID(ctx context.Context, id int64) (Model, error)

func (MySQLRepository) List

func (repo MySQLRepository) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, error)

type Policy added in v0.19.0

type Policy string

func (Policy) Eval added in v0.19.0

func (policy Policy) Eval(ctx PolicyContext) (bool, error)

func (Policy) Hash added in v0.19.0

func (policy Policy) Hash() string

func (Policy) Validate added in v0.19.0

func (policy Policy) Validate() error

type PolicyContext added in v0.19.0

type PolicyContext map[string]interface{}

func (PolicyContext) String added in v0.19.0

func (pc PolicyContext) String() string

type PostgresRepository added in v0.4.0

type PostgresRepository struct {
	database.SQLRepository
}

func NewPostgresRepository added in v0.4.0

func NewPostgresRepository(db *database.Postgres) *PostgresRepository

func (PostgresRepository) Create added in v0.4.0

func (repo PostgresRepository) Create(ctx context.Context, model Model) (int64, error)

func (PostgresRepository) Delete added in v0.28.0

func (repo PostgresRepository) Delete(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) error

func (PostgresRepository) DeleteById added in v0.4.0

func (repo PostgresRepository) DeleteById(ctx context.Context, ids []int64) error

func (PostgresRepository) Get added in v0.4.0

func (repo PostgresRepository) Get(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) (Model, error)

func (PostgresRepository) GetAllMatchingObject added in v0.28.0

func (repo PostgresRepository) GetAllMatchingObject(ctx context.Context, objectType string, objectId string) ([]Model, error)

func (PostgresRepository) GetAllMatchingObjectAndRelation added in v0.4.0

func (repo PostgresRepository) GetAllMatchingObjectAndRelation(ctx context.Context, objectType string, objectId string, relation string) ([]Model, error)

func (PostgresRepository) GetAllMatchingObjectAndRelationBySubjectType added in v0.16.1

func (repo PostgresRepository) GetAllMatchingObjectAndRelationBySubjectType(ctx context.Context, objectType string, objectId string, relation string, subjectType string) ([]Model, error)

func (PostgresRepository) GetAllMatchingObjectRelationAndSubject added in v0.18.0

func (repo PostgresRepository) GetAllMatchingObjectRelationAndSubject(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string) ([]Model, error)

func (PostgresRepository) GetAllMatchingSubject added in v0.28.0

func (repo PostgresRepository) GetAllMatchingSubject(ctx context.Context, subjectType string, subjectId string) ([]Model, error)

func (PostgresRepository) GetByID added in v0.4.0

func (repo PostgresRepository) GetByID(ctx context.Context, id int64) (Model, error)

func (PostgresRepository) List added in v0.4.0

func (repo PostgresRepository) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, error)

type SQLiteRepository added in v0.11.0

type SQLiteRepository struct {
	database.SQLRepository
}

func NewSQLiteRepository added in v0.11.0

func NewSQLiteRepository(db *database.SQLite) *SQLiteRepository

func (SQLiteRepository) Create added in v0.11.0

func (repo SQLiteRepository) Create(ctx context.Context, model Model) (int64, error)

func (SQLiteRepository) Delete added in v0.28.0

func (repo SQLiteRepository) Delete(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) error

func (SQLiteRepository) DeleteById added in v0.11.0

func (repo SQLiteRepository) DeleteById(ctx context.Context, ids []int64) error

func (SQLiteRepository) Get added in v0.11.0

func (repo SQLiteRepository) Get(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) (Model, error)

func (SQLiteRepository) GetAllMatchingObject added in v0.28.0

func (repo SQLiteRepository) GetAllMatchingObject(ctx context.Context, objectType string, objectId string) ([]Model, error)

func (SQLiteRepository) GetAllMatchingObjectAndRelation added in v0.11.0

func (repo SQLiteRepository) GetAllMatchingObjectAndRelation(ctx context.Context, objectType string, objectId string, relation string) ([]Model, error)

func (SQLiteRepository) GetAllMatchingObjectAndRelationBySubjectType added in v0.16.1

func (repo SQLiteRepository) GetAllMatchingObjectAndRelationBySubjectType(ctx context.Context, objectType string, objectId string, relation string, subjectType string) ([]Model, error)

func (SQLiteRepository) GetAllMatchingObjectRelationAndSubject added in v0.18.0

func (repo SQLiteRepository) GetAllMatchingObjectRelationAndSubject(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string) ([]Model, error)

func (SQLiteRepository) GetAllMatchingSubject added in v0.28.0

func (repo SQLiteRepository) GetAllMatchingSubject(ctx context.Context, subjectType string, subjectId string) ([]Model, error)

func (SQLiteRepository) GetByID added in v0.11.0

func (repo SQLiteRepository) GetByID(ctx context.Context, id int64) (Model, error)

func (SQLiteRepository) List added in v0.11.0

func (repo SQLiteRepository) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, error)

type SortOptions

type SortOptions struct {
	Column      string
	IsAscending bool
}

SortOptions type for sorting filtered results from the warrant table

type SubjectSpec

type SubjectSpec struct {
	ObjectType string `json:"objectType,omitempty" validate:"required_with=ObjectId,valid_object_type"`
	ObjectId   string `json:"objectId,omitempty" validate:"required_with=ObjectType,valid_object_id"`
	Relation   string `json:"relation,omitempty" validate:"omitempty,valid_relation"`
}

func StringToSubjectSpec

func StringToSubjectSpec(str string) (*SubjectSpec, error)

func (*SubjectSpec) String

func (spec *SubjectSpec) String() string

func (*SubjectSpec) ToMap added in v0.20.0

func (spec *SubjectSpec) ToMap() map[string]interface{}

type Warrant

type Warrant struct {
	ID              int64      `mysql:"id" postgres:"id" sqlite:"id"`
	ObjectType      string     `mysql:"objectType" postgres:"object_type" sqlite:"objectType"`
	ObjectId        string     `mysql:"objectId" postgres:"object_id" sqlite:"objectId"`
	Relation        string     `mysql:"relation" postgres:"relation" sqlite:"relation"`
	SubjectType     string     `mysql:"subjectType" postgres:"subject_type" sqlite:"subjectType"`
	SubjectId       string     `mysql:"subjectId" postgres:"subject_id" sqlite:"subjectId"`
	SubjectRelation string     `mysql:"subjectRelation" postgres:"subject_relation" sqlite:"subjectRelation"`
	Policy          Policy     `mysql:"policy" postgres:"policy" sqlite:"policy"`
	PolicyHash      string     `mysql:"policyHash" postgres:"policy_hash" sqlite:"policyHash"`
	CreatedAt       time.Time  `mysql:"createdAt" postgres:"created_at" sqlite:"createdAt"`
	UpdatedAt       time.Time  `mysql:"updatedAt" postgres:"updated_at" sqlite:"updatedAt"`
	DeletedAt       *time.Time `mysql:"deletedAt" postgres:"deleted_at" sqlite:"deletedAt"`
}

func StringToWarrant

func StringToWarrant(warrantString string) (*Warrant, error)

func (Warrant) GetCreatedAt added in v0.8.0

func (warrant Warrant) GetCreatedAt() time.Time

func (Warrant) GetDeletedAt added in v0.8.0

func (warrant Warrant) GetDeletedAt() *time.Time

func (Warrant) GetID added in v0.8.0

func (warrant Warrant) GetID() int64

func (Warrant) GetObjectId added in v0.8.0

func (warrant Warrant) GetObjectId() string

func (Warrant) GetObjectType added in v0.8.0

func (warrant Warrant) GetObjectType() string

func (Warrant) GetPolicy added in v0.18.0

func (warrant Warrant) GetPolicy() Policy

func (Warrant) GetPolicyHash added in v0.18.0

func (warrant Warrant) GetPolicyHash() string

func (Warrant) GetRelation added in v0.8.0

func (warrant Warrant) GetRelation() string

func (Warrant) GetSubjectId added in v0.8.0

func (warrant Warrant) GetSubjectId() string

func (Warrant) GetSubjectRelation added in v0.8.0

func (warrant Warrant) GetSubjectRelation() string

func (Warrant) GetSubjectType added in v0.8.0

func (warrant Warrant) GetSubjectType() string

func (Warrant) GetUpdatedAt added in v0.8.0

func (warrant Warrant) GetUpdatedAt() time.Time

func (Warrant) String added in v0.4.0

func (warrant Warrant) String() string

func (Warrant) ToWarrantSpec

func (warrant Warrant) ToWarrantSpec() *WarrantSpec

type WarrantListParamParser

type WarrantListParamParser struct{}

func (WarrantListParamParser) GetDefaultSortBy

func (parser WarrantListParamParser) GetDefaultSortBy() string

func (WarrantListParamParser) GetSupportedSortBys

func (parser WarrantListParamParser) GetSupportedSortBys() []string

func (WarrantListParamParser) ParseValue

func (parser WarrantListParamParser) ParseValue(val string, sortBy string) (interface{}, error)

type WarrantRepository

type WarrantRepository interface {
	Create(ctx context.Context, warrant Model) (int64, error)
	Get(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) (Model, error)
	GetByID(ctx context.Context, id int64) (Model, error)
	GetAllMatchingObjectRelationAndSubject(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string) ([]Model, error)
	GetAllMatchingObjectAndRelation(ctx context.Context, objectType string, objectId string, relation string) ([]Model, error)
	GetAllMatchingObjectAndRelationBySubjectType(ctx context.Context, objectType string, objectId string, relation string, subjectType string) ([]Model, error)
	List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]Model, error)
	Delete(ctx context.Context, objectType string, objectId string, relation string, subjectType string, subjectId string, subjectRelation string, policyHash string) error
	DeleteById(ctx context.Context, ids []int64) error
	GetAllMatchingObject(ctx context.Context, objectType string, objectId string) ([]Model, error)
	GetAllMatchingSubject(ctx context.Context, subjectType string, subjectId string) ([]Model, error)
}

func NewRepository

func NewRepository(db database.Database) (WarrantRepository, error)

type WarrantService

type WarrantService struct {
	service.BaseService
	Repository    WarrantRepository
	EventSvc      event.Service
	ObjectTypeSvc *objecttype.ObjectTypeService
	WookieSvc     *wookie.WookieService
}

func NewService

func NewService(env service.Env, repository WarrantRepository, eventSvc event.Service, objectTypeSvc *objecttype.ObjectTypeService, wookieService *wookie.WookieService) *WarrantService

func (WarrantService) Create

func (svc WarrantService) Create(ctx context.Context, warrantSpec WarrantSpec) (*WarrantSpec, *wookie.Token, error)

func (WarrantService) Delete

func (svc WarrantService) Delete(ctx context.Context, warrantSpec WarrantSpec) (*wookie.Token, error)

func (WarrantService) DeleteRelatedWarrants

func (svc WarrantService) DeleteRelatedWarrants(ctx context.Context, objectType string, objectId string) (*wookie.Token, error)

func (WarrantService) List

func (svc WarrantService) List(ctx context.Context, filterOptions *FilterOptions, listParams service.ListParams) ([]*WarrantSpec, *wookie.Token, error)

func (WarrantService) Routes added in v0.8.0

func (svc WarrantService) Routes() ([]service.Route, error)

GetRoutes registers all route handlers for this module

type WarrantSpec

type WarrantSpec struct {
	ObjectType string            `json:"objectType" validate:"required,valid_object_type"`
	ObjectId   string            `json:"objectId" validate:"required,valid_object_id"`
	Relation   string            `json:"relation" validate:"required,valid_relation"`
	Subject    *SubjectSpec      `json:"subject" validate:"required"`
	Context    map[string]string `json:"context,omitempty" validate:"excluded_with=Policy"`
	Policy     Policy            `json:"policy,omitempty" validate:"excluded_with=Context"`
	CreatedAt  time.Time         `json:"createdAt"`
}

func StringToWarrantSpec

func StringToWarrantSpec(str string) (*WarrantSpec, error)

func (WarrantSpec) String

func (spec WarrantSpec) String() string

func (*WarrantSpec) ToMap

func (spec *WarrantSpec) ToMap() map[string]interface{}

func (*WarrantSpec) ToWarrant

func (spec *WarrantSpec) ToWarrant() (*Warrant, error)

Jump to

Keyboard shortcuts

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