Documentation
¶
Index ¶
- Constants
- Variables
- type Attribute
- type AttributePathNode
- type Attributes
- type CheckAttributeResponse
- type Client
- func (c *Client) CheckAttribute(ctx context.Context, sourceObjectID, targetObjectID uuid.UUID, ...) (*CheckAttributeResponse, error)
- func (c *Client) CreateEdge(ctx context.Context, id, sourceObjectID, targetObjectID, edgeTypeID uuid.UUID) (*Edge, error)
- func (c *Client) CreateEdgeType(ctx context.Context, id uuid.UUID, ...) (*EdgeType, error)
- func (c *Client) CreateObject(ctx context.Context, id, typeID uuid.UUID, alias string) (*Object, error)
- func (c *Client) CreateObjectType(ctx context.Context, id uuid.UUID, typeName string) (*ObjectType, error)
- func (c *Client) DeleteEdge(ctx context.Context, edgeID uuid.UUID) error
- func (c *Client) DeleteEdgeType(ctx context.Context, edgeTypeID uuid.UUID) error
- func (c *Client) DeleteObject(ctx context.Context, id uuid.UUID) error
- func (c *Client) DeleteObjectType(ctx context.Context, objectTypeID uuid.UUID) error
- func (c *Client) FindEdge(ctx context.Context, sourceObjectID, targetObjectID, edgeTypeID uuid.UUID) (*Edge, error)
- func (c *Client) FindEdgeTypeID(ctx context.Context, typeName string) (uuid.UUID, error)
- func (c *Client) FindObjectTypeID(ctx context.Context, typeName string) (uuid.UUID, error)
- func (c *Client) GetEdgeType(ctx context.Context, edgeTypeID uuid.UUID) (*EdgeType, error)
- func (c *Client) GetObject(ctx context.Context, id uuid.UUID) (*Object, error)
- func (c *Client) GetObjectForName(ctx context.Context, typeID uuid.UUID, name string) (*Object, error)
- func (c *Client) GetObjectType(ctx context.Context, id uuid.UUID) (*ObjectType, error)
- func (c *Client) ListEdgeTypes(ctx context.Context) ([]EdgeType, error)
- func (c *Client) ListEdgesBetweenObjects(ctx context.Context, sourceObjectID, targetObjectID uuid.UUID) ([]Edge, error)
- func (c *Client) ListEdgesOnObject(ctx context.Context, objectID uuid.UUID, opts ...pagination.Option) (*ListEdgesResponse, error)
- func (c *Client) ListObjectTypes(ctx context.Context) ([]ObjectType, error)
- func (c *Client) ListObjects(ctx context.Context, opts ...pagination.Option) (*ListObjectsResponse, error)
- func (c *Client) UpdateEdgeType(ctx context.Context, id uuid.UUID, ...) (*EdgeType, error)
- type Edge
- type EdgeType
- type ListEdgeTypesResponse
- type ListEdgesResponse
- type ListObjectTypesResponse
- type ListObjectsResponse
- type Object
- type ObjectType
- type UserObject
Constants ¶
const ( GroupObjectType = "_group" UserObjectType = "_user" AdminRole = "_admin" MemberRole = "_member" )
AuthZ object types & edge types (roles) provisioned for every tenant. TODO: merge the string constant with the UUID into a const-ish struct to keep them associated, particularly if we add more of these. Keep in sync with TSX constants! TODO: we should have a better way to sync constants between TS and Go
Variables ¶
var AdminRoleTypeID = uuid.Must(uuid.FromString("60b69666-4a8a-4eb3-94dd-621298fb365d"))
AdminRoleTypeID is the ID of a built-in edge type called "_admin"
var ErrObjectNotFound = ucerr.New("object not found")
ErrObjectNotFound is returned if an object is not found.
var ErrRelationshipTypeNotFound = ucerr.New("relationship type not found")
ErrRelationshipTypeNotFound is returned if a relationship type name (e.g. "editor") is not found.
var GroupObjectTypeID = uuid.Must(uuid.FromString("f5bce640-f866-4464-af1a-9e7474c4a90c"))
GroupObjectTypeID is the ID of a built-in object type called "_group"
var MemberRoleTypeID = uuid.Must(uuid.FromString("1eec16ec-6130-4f9e-a51f-21bc19b20d8f"))
MemberRoleTypeID is the ID of a built-in edge type called "_member"
var UserObjectTypeID = uuid.Must(uuid.FromString("1bf2b775-e521-41d3-8b7e-78e89427e6fe"))
UserObjectTypeID is the ID of a built-in object type called "_user"
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute struct {
Name string `db:"name" json:"name" validate:"notempty"`
// Direct = true means that this attribute applies directly from the source to the target, or
// alternately stated that "the source object 'has' the attribute on the target".
// e.g. given an edge {Source: Alice, Target: Readme.txt, Type: Viewer} with attribute {Name:"read", Direct: true},
// then Alice directly 'has' the "read" attribute on Readme.txt
Direct bool `db:"direct" json:"direct"`
// Inherit = true means that, if the target object 'has' (or inherits) the attribute on some other object X,
// then the source object "inherits" that attribute on X as well. This applies transitively across
// multiple consecutive Inherit edges.
// e.g. given an edge {Source: Alice, Target: RootUsersGroup, Type: Member} with attribute {Name:"read", Inherit: true},
// and another edge {Source: RootUsersGroup, Target: Readme.txt, Type: Viewer} with attribute {Name:"read", Direct: true},
// then the Root Users group has direct read permissions on Readme.txt and Alice inherits the read permission
// on Readme.txt through its connection to the RootUsersGroup.
// This flag is typically used when some objects (e.g. users, files) should inherit attributes
// that a "grouping" object has on some final target object without requiring direct edges between
// every source and every target (e.g. between Alice and Readme.txt, in this example).
// The Inherit flag would be used on attributes that associate the source objects with the grouping object.
// This is like a "pull" model for permissions, while Propagate represents a "push" model.
Inherit bool `db:"inherit" json:"inherit"`
// Propagate = true means that some object X which has an attribute on the source object will also have the same
// attribute on the target object. This is effectively the inverse of Inherit, and "propagates" attributes forward.
// e.g. given an edge {Source: Alice, Target: HomeDirectory, Type: Viewer} with attribute {Name: "read", Direct: true},
// and another edge {Source: HomeDirectory, Target: Readme.txt, Type: Contains} with attribute {Name: "read", Propagate: true},
// then Alice's read permission on the HomeDirectory propagates to Readme.txt since that is (presumably) contained in the
// Home directory.
// This is like a "push" model for permissions, while Inherit represents a "pull" model.
// This is different from Direct = true because it doesn't make sense for the Home directory to have
// direct "read" attributes on files within it, but simply propagate the permissions down the tree.
// Permissions don't propagate through Direct links; if Alice has a 'direct' "friend" relationship to Bob,
// and Bob has a 'direct' "friend" relationship to Charlie,
// that wouldn't imply Alice has a 'direct' "friend" relationship to Charlie (direct != propagate).
Propagate bool `db:"propagate" json:"propagate"`
}
Attribute represents a named attribute on an Edge Type.
type AttributePathNode ¶
type AttributePathNode struct {
ObjectID uuid.UUID `json:"object_id"`
EdgeID uuid.UUID `json:"edge_id"`
}
AttributePathNode is a node in a path list from source to target, if CheckAttribute succeeds.
type Attributes ¶
type Attributes []Attribute
Attributes is a collection of Attribute, used as a column/field in EdgeType
type CheckAttributeResponse ¶
type CheckAttributeResponse struct {
HasAttribute bool `json:"has_attribute"`
Path []AttributePathNode `json:"path"`
}
CheckAttributeResponse is returned by the check_attribute endpoint.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a client for the authz service
func NewClient ¶
func NewClient(url string, opts ...jsonclient.Option) (*Client, error)
NewClient creates a new authz client Web API base URL, e.g. "http://localhost:1234".
func (*Client) CheckAttribute ¶
func (c *Client) CheckAttribute(ctx context.Context, sourceObjectID, targetObjectID uuid.UUID, attributeName string) (*CheckAttributeResponse, error)
CheckAttribute returns true if the source object has the given attribute on the target object.
func (*Client) CreateEdge ¶
func (c *Client) CreateEdge(ctx context.Context, id, sourceObjectID, targetObjectID, edgeTypeID uuid.UUID) (*Edge, error)
CreateEdge creates an edge (relationship) between two objects.
func (*Client) CreateEdgeType ¶
func (c *Client) CreateEdgeType(ctx context.Context, id uuid.UUID, sourceObjectTypeID, targetObjectTypeID uuid.UUID, typeName string, attributes Attributes) (*EdgeType, error)
CreateEdgeType creates a new type of edge for the authz system.
func (*Client) CreateObject ¶
func (c *Client) CreateObject(ctx context.Context, id, typeID uuid.UUID, alias string) (*Object, error)
CreateObject creates a new object with a given ID, name, and type.
func (*Client) CreateObjectType ¶
func (c *Client) CreateObjectType(ctx context.Context, id uuid.UUID, typeName string) (*ObjectType, error)
CreateObjectType creates a new type of object for the authz system.
func (*Client) DeleteEdge ¶
DeleteEdge deletes an edge by ID.
func (*Client) DeleteEdgeType ¶
DeleteEdgeType deletes an edge type by ID.
func (*Client) DeleteObject ¶
DeleteObject deletes an object by ID.
func (*Client) DeleteObjectType ¶
DeleteObjectType deletes an object type by ID.
func (*Client) FindEdge ¶
func (c *Client) FindEdge(ctx context.Context, sourceObjectID, targetObjectID, edgeTypeID uuid.UUID) (*Edge, error)
FindEdge finds an existing edge (relationship) between two objects.
func (*Client) FindEdgeTypeID ¶
FindEdgeTypeID resolves an edge type name to an ID.
func (*Client) FindObjectTypeID ¶
FindObjectTypeID resolves an object type name to an ID.
func (*Client) GetEdgeType ¶
GetEdgeType gets an edge type (relationship) by its type ID.
func (*Client) GetObjectForName ¶
func (c *Client) GetObjectForName(ctx context.Context, typeID uuid.UUID, name string) (*Object, error)
GetObjectForName returns an object with a given name.
func (*Client) GetObjectType ¶
GetObjectType returns an object type by ID.
func (*Client) ListEdgeTypes ¶
ListEdgeTypes lists all available edge types
func (*Client) ListEdgesBetweenObjects ¶
func (c *Client) ListEdgesBetweenObjects(ctx context.Context, sourceObjectID, targetObjectID uuid.UUID) ([]Edge, error)
ListEdgesBetweenObjects lists all edges (relationships) with a given source & target objct.
func (*Client) ListEdgesOnObject ¶
func (c *Client) ListEdgesOnObject(ctx context.Context, objectID uuid.UUID, opts ...pagination.Option) (*ListEdgesResponse, error)
ListEdgesOnObject lists `limit` edges (relationships) where the given object is a source or target.
func (*Client) ListObjectTypes ¶
func (c *Client) ListObjectTypes(ctx context.Context) ([]ObjectType, error)
ListObjectTypes lists all object types in the system
func (*Client) ListObjects ¶
func (c *Client) ListObjects(ctx context.Context, opts ...pagination.Option) (*ListObjectsResponse, error)
ListObjects lists `limit` objects in sorted order with pagination, starting after a given ID (or uuid.Nil to start from the beginning).
type Edge ¶
type Edge struct {
ucdb.BaseModel
// This must be a valid EdgeType.ID value
EdgeTypeID uuid.UUID `db:"edge_type_id" json:"edge_type_id" validate:"notnil"`
// These must be valid ObjectType.ID values
SourceObjectID uuid.UUID `db:"source_object_id" json:"source_object_id" validate:"notnil"`
TargetObjectID uuid.UUID `db:"target_object_id" json:"target_object_id" validate:"notnil"`
}
Edge represents a directional relationship between a "source" object and a "target" object.
type EdgeType ¶
type EdgeType struct {
ucdb.BaseModel
TypeName string `db:"type_name" json:"type_name" validate:"notempty"`
SourceObjectTypeID uuid.UUID `db:"source_object_type_id,immutable" json:"source_object_type_id" validate:"notnil"`
TargetObjectTypeID uuid.UUID `db:"target_object_type_id,immutable" json:"target_object_type_id" validate:"notnil"`
Attributes Attributes `db:"attributes" json:"attributes"`
}
EdgeType defines a single, strongly-typed relationship that a "source" object type can have to a "target" object type.
type ListEdgeTypesResponse ¶
type ListEdgeTypesResponse struct {
Data []EdgeType `json:"data"`
pagination.ResponseFields
}
ListEdgeTypesResponse is the paginated response from listing edge types.
type ListEdgesResponse ¶
type ListEdgesResponse struct {
Data []Edge `json:"data"`
pagination.ResponseFields
}
ListEdgesResponse is the paginated response from listing edges.
func (ListEdgesResponse) Len ¶
func (r ListEdgesResponse) Len() int
TODO: get rid of sort.Interface code when the legacy path in ListObjects goes away Len implements sort.Interface
func (ListEdgesResponse) Less ¶
func (r ListEdgesResponse) Less(left, right int) bool
Less implements sort.Interface
func (ListEdgesResponse) Swap ¶
func (r ListEdgesResponse) Swap(left, right int)
Swap implements sort.Interface
type ListObjectTypesResponse ¶
type ListObjectTypesResponse struct {
Data []ObjectType `json:"data"`
pagination.ResponseFields
}
ListObjectTypesResponse is the paginated response from listing object types.
type ListObjectsResponse ¶
type ListObjectsResponse struct {
Data []Object `json:"data"`
pagination.ResponseFields
}
ListObjectsResponse represents a paginated response from listing objects.
func (ListObjectsResponse) Len ¶
func (r ListObjectsResponse) Len() int
TODO: get rid of sort.Interface code when the legacy path in ListObjects goes away Len implements sort.Interface
func (ListObjectsResponse) Less ¶
func (r ListObjectsResponse) Less(left, right int) bool
Less implements sort.Interface
func (ListObjectsResponse) Swap ¶
func (r ListObjectsResponse) Swap(left, right int)
Swap implements sort.Interface
type Object ¶
type Object struct {
ucdb.BaseModel
Alias string `db:"alias" json:"alias" validate:"notempty"`
TypeID uuid.UUID `db:"type_id,immutable" json:"type_id" validate:"notnil"`
}
Object represents an instance of an AuthZ object used for modeling permissions.
type ObjectType ¶
type ObjectType struct {
ucdb.BaseModel
TypeName string `db:"type_name" json:"type_name" validate:"notempty"`
}
ObjectType represents the type definition of an AuthZ object.
func (*ObjectType) Validate ¶
func (o *ObjectType) Validate() error
Validate implements Validateable
type UserObject ¶
UserObject is a limited view of the `users` table used by the AuthZ service. To avoid a dependency on IDP packages, AuthZ uses this stub structure to load a limited slice of User objects for authz purposes instead of depending on `idp/internal/storage`.`