Documentation ¶
Index ¶
- Constants
- Variables
- func ClearManager()
- func FormatParentID(parent string) string
- func PolicyValidate(action, path string, auth Authorization, policies []*Policy) (*Policy, *Role)
- func SetManagerScope(s Scope)
- type Action
- type Authorization
- type BaseAuthorization
- type Catalog
- type Endpoint
- type Extension
- type Link
- type Manager
- func (manager *Manager) ClearExtensions()
- func (manager *Manager) LoadExtensions(extensions []*Resource) error
- func (manager *Manager) LoadNamespaces(namespaces []*Resource) error
- func (manager *Manager) LoadPolicies(policies []*Resource) error
- func (manager *Manager) LoadResource(schemaID string, dataMap map[string]interface{}) (*Resource, error)
- func (manager *Manager) LoadResourceFromJSONString(schemaID string, jsonData string) (*Resource, error)
- func (manager *Manager) LoadSchemaFromFile(filePath string) error
- func (manager *Manager) LoadSchemasFromFiles(filePaths ...string) error
- func (manager *Manager) Namespace(name string) (*Namespace, bool)
- func (manager *Manager) Namespaces() map[string]*Namespace
- func (manager *Manager) NobodyResourcePaths() []*regexp.Regexp
- func (manager *Manager) OrderedSchemas() []*Schema
- func (manager *Manager) Policies() []*Policy
- func (manager *Manager) PolicyValidate(action, path string, auth Authorization) (*Policy, *Role)
- func (manager *Manager) Schema(id string) (*Schema, bool)
- func (manager *Manager) Schemas() Map
- func (manager *Manager) String() string
- func (manager *Manager) UnRegisterSchema(schema *Schema) error
- func (manager *Manager) ValidateSchema(schemaPath, filePath string) error
- type Map
- type Namespace
- type NamespaceResource
- type Policy
- func (p *Policy) AddPropertyConditionFilter(action string, match map[string]interface{})
- func (p *Policy) AddTenantToFilter(action string, tenant Tenant)
- func (p *Policy) ApplyPropertyConditionFilter(action string, data map[string]interface{}, ...) error
- func (p *Policy) Check(action string, authorization Authorization, data map[string]interface{}) error
- func (p *Policy) FilterSchema(properties map[string]interface{}, propertiesOrder, required []string) (map[string]interface{}, []string, []string)
- func (p *Policy) GetTenantFilter(action string, tenant Tenant) []Tenant
- func (p *Policy) GetTenantIDFilter(action string, tenantID string) []string
- func (p *Policy) RemoveHiddenProperty(data map[string]interface{}) map[string]interface{}
- func (p *Policy) RequireOwner() bool
- type Property
- type PropertyMap
- type Resource
- func (resource *Resource) Data() map[string]interface{}
- func (resource *Resource) Get(key string) interface{}
- func (resource *Resource) ID() string
- func (resource *Resource) JSONString() (string, error)
- func (resource *Resource) ParentID() string
- func (resource *Resource) Path() string
- func (resource *Resource) PopulateDefaults() error
- func (resource *Resource) Schema() *Schema
- func (resource *Resource) SetParentID(id string)
- func (resource *Resource) String() string
- func (resource *Resource) Update(updateData map[string]interface{}) error
- func (resource *Resource) Values() []interface{}
- type ResourcePolicy
- type Role
- type Schema
- func (schema *Schema) Extend(fromSchema *Schema) error
- func (schema *Schema) GenerateCustomPath(data map[string]interface{}) (path string, err error)
- func (schema *Schema) GetActionURL(path string) string
- func (schema *Schema) GetActionURLWithParents(path string) string
- func (schema *Schema) GetDbTableName() string
- func (schema *Schema) GetParentURL() string
- func (schema *Schema) GetPluralURL() string
- func (schema *Schema) GetPluralURLWithParents() string
- func (schema *Schema) GetPropertyByID(id string) (*Property, error)
- func (schema *Schema) GetResourceIDFromPath(schemaPath string) string
- func (schema *Schema) GetSingleURL() string
- func (schema *Schema) GetSingleURLWithParents() string
- func (schema *Schema) Init() error
- func (schema *Schema) IsAbstract() bool
- func (schema *Schema) JSON() map[string]interface{}
- func (schema *Schema) ParentID() string
- func (schema *Schema) ParentSchemaPropertyID() string
- func (schema *Schema) SetNamespace(namespace *Namespace)
- func (schema *Schema) SetParentSchema(parentSchema *Schema)
- func (schema *Schema) StateVersioning() bool
- func (schema *Schema) SyncKeyTemplate() (syncKeyTemplate string, ok bool)
- func (schema *Schema) Titles() []string
- func (schema *Schema) Validate(jsonSchema interface{}, object interface{}) error
- func (schema *Schema) ValidateOnCreate(object interface{}) error
- func (schema *Schema) ValidateOnUpdate(object interface{}) error
- type Schemas
- type Scope
- type Tags
- type Tenant
- type Version
Constants ¶
const ( // ActionGlob allows to perform all actions ActionGlob = "*" // ActionCreate allows to create a resource ActionCreate = "create" // ActionRead allows to list resources and show details ActionRead = "read" // ActionUpdate allows to update a resource ActionUpdate = "update" // ActionDelete allows to delete a resource ActionDelete = "delete" )
Variables ¶
var DefaultExtension = "javascript"
DefaultExtension configuraion
Functions ¶
func PolicyValidate ¶
func PolicyValidate(action, path string, auth Authorization, policies []*Policy) (*Policy, *Role)
PolicyValidate validates api request using policy validation
func SetManagerScope ¶
func SetManagerScope(s Scope)
SetManagerScope change how GetManager works. Change managerScope only if you know what you are doing.
Types ¶
type Action ¶
type Action struct { ID string Method string Path string InputSchema map[string]interface{} OutputSchema map[string]interface{} }
Action struct
func NewActionFromObject ¶
NewActionFromObject create Action object from json
type Authorization ¶
type Authorization interface { TenantID() string TenantName() string AuthToken() string Roles() []*Role Catalog() []*Catalog }
Authorization interface
func NewAuthorization ¶
func NewAuthorization(tenantID, tenantName, authToken string, roleIDs []string, catalog []*Catalog) Authorization
NewAuthorization is a constructor for auth info
type BaseAuthorization ¶
type BaseAuthorization struct {
// contains filtered or unexported fields
}
BaseAuthorization is base struct for Authorization
func (*BaseAuthorization) AuthToken ¶
func (auth *BaseAuthorization) AuthToken() string
AuthToken returns X_AUTH_TOKEN
func (*BaseAuthorization) Catalog ¶
func (auth *BaseAuthorization) Catalog() []*Catalog
Catalog returns service catalog
func (*BaseAuthorization) Roles ¶
func (auth *BaseAuthorization) Roles() []*Role
Roles returns authorized roles
func (*BaseAuthorization) TenantID ¶
func (auth *BaseAuthorization) TenantID() string
TenantID returns authorized tenant
func (*BaseAuthorization) TenantName ¶
func (auth *BaseAuthorization) TenantName() string
TenantName returns authorized tenant name
type Catalog ¶
Catalog represents service catalog info
func NewCatalog ¶
NewCatalog initializes Catalog
type Endpoint ¶
Endpoint represents Endpoint information
func NewEndpoint ¶
NewEndpoint initializes Endpoint
type Extension ¶
Extension is a small plugin for gohan
func NewExtension ¶
NewExtension returns new extension from object
type Manager ¶
type Manager struct { Extensions []*Extension // contains filtered or unexported fields }
Manager manages handling of schemas Manager manages routing with external data and gohan resource representation This is a singleton class
func (*Manager) ClearExtensions ¶
func (manager *Manager) ClearExtensions()
ClearExtensions clears extensions
func (*Manager) LoadExtensions ¶
LoadExtensions register extension by db object
func (*Manager) LoadNamespaces ¶
LoadNamespaces register namespaces by db object
func (*Manager) LoadPolicies ¶
LoadPolicies register policy by db object
func (*Manager) LoadResource ¶
func (manager *Manager) LoadResource(schemaID string, dataMap map[string]interface{}) (*Resource, error)
LoadResource makes resource from datamap
func (*Manager) LoadResourceFromJSONString ¶
func (manager *Manager) LoadResourceFromJSONString(schemaID string, jsonData string) (*Resource, error)
LoadResourceFromJSONString makes resource from jsonString
func (*Manager) LoadSchemaFromFile ¶
LoadSchemaFromFile loads schema from json file
func (*Manager) LoadSchemasFromFiles ¶
LoadSchemasFromFiles calls LoadSchemaFromFile for each of provided filePaths
func (*Manager) Namespaces ¶
Namespaces gets namespaces from manager
func (*Manager) NobodyResourcePaths ¶
NobodyResourcePaths returns a list of paths that do not require authorization
func (*Manager) OrderedSchemas ¶
OrderedSchemas gets schema from manager ordered
func (*Manager) PolicyValidate ¶
func (manager *Manager) PolicyValidate(action, path string, auth Authorization) (*Policy, *Role)
PolicyValidate API request using policy statements
func (*Manager) UnRegisterSchema ¶
UnRegisterSchema unregister schema
func (*Manager) ValidateSchema ¶
ValidateSchema validates json schema
type Namespace ¶
Namespace describes a group of schemas that form a common endpoint
func NewNamespace ¶
NewNamespace is a constructor for a namespace
func (*Namespace) GetFullPrefix ¶
GetFullPrefix returns a full prefix of a namespace
func (*Namespace) IsTopLevel ¶
IsTopLevel checks whether namespace is a top-level namespace
func (*Namespace) SetParentNamespace ¶
SetParentNamespace sets a parent of a namespace to the provided one
type NamespaceResource ¶
type NamespaceResource struct { Links []Link `json:"links"` Name string `json:"name"` Collection string `json:"collection"` }
NamespaceResource ...
type Policy ¶
type Policy struct {
ID, Description, Principal, Action, Effect string
Condition []interface{}
Resource *ResourcePolicy
RawData interface{}
TenantID *regexp.Regexp
TenantName *regexp.Regexp
// contains filtered or unexported fields
}
Policy describes policy configuration for APIs
func NewEmptyPolicy ¶
func NewEmptyPolicy() *Policy
NewEmptyPolicy Return Empty policy which match everything
func (*Policy) AddPropertyConditionFilter ¶
AddPropertyConditionFilter adds property based filter for action
func (*Policy) AddTenantToFilter ¶
AddTenantToFilter adds tenant to filter for given action
func (*Policy) ApplyPropertyConditionFilter ¶
func (p *Policy) ApplyPropertyConditionFilter(action string, data map[string]interface{}, updateCandidateData map[string]interface{}) error
ApplyPropertyConditionFilter applies filter based on Property You need to pass candidate update value in updateCandidateData on update API, so that we can limit allowed update value. Let's say we would like to only allow to update from ACTIVE to ERROR on an API. We can define this policy like this.
- action: 'update' condition:
- property: status: ACTIVE: ERROR effect: allow id: member principal: Member
This policy check error in case of followings - Original value isn't ACTIVE - Update candidate value isn't ERROR
func (*Policy) Check ¶
func (p *Policy) Check(action string, authorization Authorization, data map[string]interface{}) error
Check ...
func (*Policy) FilterSchema ¶
func (p *Policy) FilterSchema(properties map[string]interface{}, propertiesOrder, required []string) (map[string]interface{}, []string, []string)
FilterSchema filters properties in the schema itself
func (*Policy) GetTenantFilter ¶
GetTenantFilter returns tenants filter for the action performed by the tenant
func (*Policy) GetTenantIDFilter ¶
GetTenantIDFilter returns tenants filter for the action performed by the tenant
func (*Policy) RemoveHiddenProperty ¶
RemoveHiddenProperty removes hidden data from data by Policy This method returns nil if all data get filtered out
type Property ¶
type Property struct {
ID, Title, Description string
Type, Format string
Properties map[string]interface{}
Relation string
RelationColumn string
RelationProperty string
Unique bool
Nullable bool
SQLType string
OnDeleteCascade bool
Default interface{}
Indexed bool
}
Property is a definition of each Property
func NewProperty ¶
func NewProperty(id, title, description, typeID, format, relation, relationColumn, relationProperty, sqlType string, unique, nullable, onDeleteCascade bool, properties map[string]interface{}, defaultValue interface{}, indexed bool) Property
NewProperty is a constructor for Property type
type Resource ¶
type Resource struct {
// contains filtered or unexported fields
}
Resource is a instance of resource
func NewResource ¶
NewResource is a constructor for a resource
func (*Resource) JSONString ¶
JSONString returns json string of the resource
func (*Resource) PopulateDefaults ¶
PopulateDefaults Populates not provided data with defaults
func (*Resource) SetParentID ¶
SetParentID set parent id of the resource
type ResourcePolicy ¶
ResourcePolicy describes targe resources
type Schema ¶
type Schema struct {
ID, Plural, Title, Description string
Type string
Extends []string
ParentSchema *Schema
Parent string
NamespaceID string
Namespace *Namespace
Metadata map[string]interface{}
Prefix string
Properties []Property
JSONSchema map[string]interface{}
JSONSchemaOnCreate map[string]interface{}
JSONSchemaOnUpdate map[string]interface{}
Actions []Action
Singular string
URL string
URLWithParents string
RawData interface{}
IsolationLevel map[string]interface{}
OnParentDeleteCascade bool
}
Schema type for defining data type
func GetSchemaByPath ¶
GetSchemaByPath - gets schema by sync_key_template path
func GetSchemaByURLPath ¶
GetSchemaByURLPath - gets schema by resource path (from API)
func NewSchemaFromObj ¶
NewSchemaFromObj is a constructor for a schema by obj
func (*Schema) GenerateCustomPath ¶
GenerateCustomPath - returns custom path based on sync_key_template
func (*Schema) GetActionURL ¶
GetActionURL returns a URL for access to resources actions
func (*Schema) GetActionURLWithParents ¶
GetActionURLWithParents returns a URL for access to resources actions with parent suffix
func (*Schema) GetDbTableName ¶
GetDbTableName returns a name of DB table used for storing schema instances
func (*Schema) GetParentURL ¶
GetParentURL returns Parent URL
func (*Schema) GetPluralURL ¶
GetPluralURL returns a URL for access to all schema objects
func (*Schema) GetPluralURLWithParents ¶
GetPluralURLWithParents returns a URL for access to all schema objects
func (*Schema) GetPropertyByID ¶
GetPropertyByID get a property object using ID
func (*Schema) GetResourceIDFromPath ¶
GetResourceIDFromPath - parse path and gets resourceID from it
func (*Schema) GetSingleURL ¶
GetSingleURL returns a URL for access to a single schema object
func (*Schema) GetSingleURLWithParents ¶
GetSingleURLWithParents returns a URL for access to a single schema object
func (*Schema) IsAbstract ¶
IsAbstract checks if this schema is abstract or not
func (*Schema) ParentSchemaPropertyID ¶
ParentSchemaPropertyID get property id for parent relation
func (*Schema) SetNamespace ¶
SetNamespace sets namespace
func (*Schema) SetParentSchema ¶
SetParentSchema sets parent schema
func (*Schema) StateVersioning ¶
StateVersioning whether resources created from this schema should track state and config versions
func (*Schema) SyncKeyTemplate ¶
SyncKeyTemplate - for custom paths in etcd
func (*Schema) ValidateOnCreate ¶
ValidateOnCreate validates json object using jsoncschema on object creation
func (*Schema) ValidateOnUpdate ¶
ValidateOnUpdate validates json object using jsoncschema on object update
type Schemas ¶
type Schemas struct {
Schemas []*Schema
}
Schemas is a list of schema This struct is needed for json decode
type Scope ¶
type Scope uint8
Scope specifies bean scope, default scope is ScopeSingleton.
const ( // ScopeSingleton is default Scope, with this setting there is a single // bean instance shared by all goroutines. ScopeSingleton Scope = iota // ScopeGLSSingleton is goroutine local storage singleton, with this setting // bean instance is shared by a goroutine tree, child goroutines // share bean instance with parent. ScopeGLSSingleton )