Documentation ¶
Index ¶
- Variables
- type CertForSign
- type Certificate
- type DefaultKontrol
- func (k DefaultKontrol) AddSimpleObjectWithDefaultPolicy(ctx context.Context, externalid string, serviceid string, servicekey string) (*ObjectPermission, error)
- func (k DefaultKontrol) CreateCert(obj *Object, policy []*Policy, enforce []*Policy) (*CertForSign, string, error)
- func (k DefaultKontrol) CreatePolicy(ctx context.Context, servicekey string, policy *Policy) error
- func (k DefaultKontrol) IssueCertForClient(ctx context.Context, objID string, serID string) (*ObjectPermission, error)
- func (k DefaultKontrol) IssueCertForService(ctx context.Context, objID string, serID string) (*ObjectPermission, error)
- func (k DefaultKontrol) UpdateObject(ctx context.Context, obj *Object, servicekey string) error
- func (k DefaultKontrol) ValidateToken(c context.Context, token string, serviceid string) (*Object, error)
- type Kontrol
- type KontrolOption
- type KontrolStore
- type Object
- type ObjectPermission
- type Policy
- type Service
Constants ¶
This section is empty.
Variables ¶
var CommonError = commonerror{ NOT_FOUND: errors.New("not found"), OBJECT_NOT_FOUND: errors.New("object not found"), PERMISSION_NOT_FOUND: errors.New("permission not found"), POLICY_NOT_FOUND: errors.New("policy not found"), SERVICE_NOT_FOUND: errors.New("service not found"), INVALID_TOKEN: errors.New("invalid or expired token"), INVALID_SERVICE: errors.New("invalid service"), INVALID_POLICY: errors.New("invalid policy"), INVALID_OBJECT: errors.New("invalid object"), MALFORM_PERMISSION: errors.New("policy permission malform"), }
var DefaultKontrolOption = KontrolOption{
DefaultTimeout: 1800,
SecretKey: "",
}
Default config for kontrol
var ObjectPolicyStatus = objectpolicystatus{
INIT: "",
ENABLE: "enable",
DISABLE: "disable",
DEFAULT: "default",
}
var ObjectStatus = objectstatus{
INIT: "",
ENABLE: "enable",
DISABLE: "disable",
}
var PolicyPermission = policypermission{
ANY: 0,
TRUE: 1,
FALSE: 2,
}
Functions ¶
This section is empty.
Types ¶
type CertForSign ¶
type CertForSign struct { ID string `json:"id"` GlobalID string `json:"global_id"` ExternalID string `json:"external_id"` ServiceID string `json:"service_id"` ExpiryDate int64 `json:"expiry_date"` Attributes map[string]interface{} `json:"attributes"` Permission map[string]map[string]bool `json:"permission"` }
type Certificate ¶
type Certificate struct { CertForSign Token string `json:"token"` ExpiryDate int64 `json:"expiry_date"` }
type DefaultKontrol ¶
type DefaultKontrol struct { Option KontrolOption // contains filtered or unexported fields }
DefaultKontrol simple Kontrol
func (DefaultKontrol) AddSimpleObjectWithDefaultPolicy ¶
func (k DefaultKontrol) AddSimpleObjectWithDefaultPolicy(ctx context.Context, externalid string, serviceid string, servicekey string) (*ObjectPermission, error)
AddSimpleObjectWithDefaultPolicy add object with default service schema
func (DefaultKontrol) CreateCert ¶
func (k DefaultKontrol) CreateCert(obj *Object, policy []*Policy, enforce []*Policy) (*CertForSign, string, error)
CreateCert create final cert then sign
func (DefaultKontrol) CreatePolicy ¶
CreatePolicy create a policy
func (DefaultKontrol) IssueCertForClient ¶
func (k DefaultKontrol) IssueCertForClient(ctx context.Context, objID string, serID string) (*ObjectPermission, error)
IssueCertForClient issue cert for current time, does not authen, must be authen-ed beforehand
func (DefaultKontrol) IssueCertForService ¶
func (k DefaultKontrol) IssueCertForService(ctx context.Context, objID string, serID string) (*ObjectPermission, error)
IssueCertForService issue cert for issed time, does not authen, must be authen-ed beforehand
func (DefaultKontrol) UpdateObject ¶
UpdateObject update Object info
func (DefaultKontrol) ValidateToken ¶
func (k DefaultKontrol) ValidateToken(c context.Context, token string, serviceid string) (*Object, error)
ValidateToken validate the given token
type Kontrol ¶
type Kontrol interface { ValidateToken(c context.Context, token string, serviceid string) (*Object, error) // validate if token existed, for tighter check, use IssueCertForService IssueCertForService(ctx context.Context, objID string, serID string) (*ObjectPermission, error) // get client cert for service to store AddSimpleObjectWithDefaultPolicy(ctx context.Context, externalid string, serviceid string, servicekey string) (*ObjectPermission, error) //service create new object UpdateObject(ctx context.Context, obj *Object, servicekey string) error //service update object CreateCert(obj *Object, policy []*Policy, enforce []*Policy) (*CertForSign, string, error) // internal use, centralise function to issue permission CreatePolicy(ctx context.Context, servicekey string, policy *Policy) error // service create policy IssueCertForClient(ctx context.Context, objID string, serID string) (*ObjectPermission, error) // issue cert for client when login success }
func NewBasicKontrol ¶
func NewBasicKontrol(store KontrolStore) Kontrol
NewBasicKontrol simple Kontrol with default option, stores still have to be provided
type KontrolOption ¶
KontrolOption kontrol config options
type KontrolStore ¶
type KontrolStore interface { GetObjectByToken(c context.Context, token string, serviceid string, timestamp int64) (*Object, error) CreateObject(c context.Context, obj *Object) error UpdateObject(c context.Context, obj *Object) error GetObjectByID(c context.Context, id string) (*Object, error) GetObjectByExternalID(c context.Context, extid string, serviceid string) (*Object, error) GetPolicyByID(c context.Context, id string) (*Policy, error) CreatePolicy(c context.Context, policy *Policy) error GetServiceByID(c context.Context, id string) (*Service, error) }
type Object ¶
type Object struct { ID string GlobalID string ExternalID string ServiceID string Status string Attributes map[string]interface{} // ignore for now, extension Token string ExpiryDate int64 ApplyPolicy []*Policy }
Object is basic entity
type ObjectPermission ¶
ObjectPermission Contains object and it's permission