fga

package
v4.18.0 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2024 License: MIT Imports: 15 Imported by: 1

Documentation

Index

Constants

View Source
const (
	Asc                      Order = "asc"
	Desc                     Order = "desc"
	CheckOpAllOf                   = "all_of"
	CheckOpAnyOf                   = "any_of"
	CheckOpBatch                   = "batch"
	CheckResultAuthorized          = "authorized"
	CheckResultNotAuthorized       = "not_authorized"
	WarrantOpCreate                = "create"
	WarrantOpDelete                = "delete"
)

Constants that enumerate the available orders.

View Source
const ResponseLimit = 10

ResponseLimit is the default number of records to limit a response to.

Variables

View Source
var (
	DefaultClient = &Client{
		Endpoint: "https://api.workos.com",
	}
)

DefaultClient is the client used by SetAPIKey and FGA functions.

Functions

func DeleteResource

func DeleteResource(
	ctx context.Context,
	opts DeleteResourceOpts,
) error

DeleteResource deletes a Resource.

func SetAPIKey

func SetAPIKey(apiKey string)

SetAPIKey sets the WorkOS API key for FGA requests.

func TestBatchWarrants

func TestBatchWarrants(t *testing.T)

func TestCrudResources

func TestCrudResources(t *testing.T)

func TestMultiTenancy

func TestMultiTenancy(t *testing.T)

func TestPricingTiersFeaturesAndUsers

func TestPricingTiersFeaturesAndUsers(t *testing.T)

func TestQueryWarrants

func TestQueryWarrants(t *testing.T)

func TestRBAC

func TestRBAC(t *testing.T)

func TestWarrants

func TestWarrants(t *testing.T)

func TestWarrantsWithPolicy

func TestWarrantsWithPolicy(t *testing.T)

Types

type CheckBatchOpts

type CheckBatchOpts struct {
	// List of warrants to check.
	Checks []WarrantCheck `json:"checks"`

	// Flag to include debug information in the response.
	Debug bool `json:"debug,omitempty"`

	// Optional token to specify desired read consistency
	WarrantToken string `json:"-"`
}

type CheckOpts

type CheckOpts struct {
	// The operator to use for the given warrants.
	Op string `json:"op,omitempty"`

	// List of warrants to check.
	Checks []WarrantCheck `json:"checks"`

	// Flag to include debug information in the response.
	Debug bool `json:"debug,omitempty"`

	// Optional token to specify desired read consistency
	WarrantToken string `json:"-"`
}

type CheckResponse

type CheckResponse struct {
	Result     string    `json:"result"`
	IsImplicit bool      `json:"is_implicit"`
	DebugInfo  DebugInfo `json:"debug_info,omitempty"`
}

func Check

func Check(
	ctx context.Context,
	opts CheckOpts,
) (CheckResponse, error)

Check performs access checks on multiple Warrants.

func CheckBatch

func CheckBatch(
	ctx context.Context,
	opts CheckBatchOpts,
) ([]CheckResponse, error)

CheckBatch performs individual access checks on multiple Warrants in one request.

func (CheckResponse) Authorized

func (checkResponse CheckResponse) Authorized() bool

type Client

type Client struct {
	// The WorkOS API Key. It can be found in https://dashboard.workos.com/api-keys.
	APIKey string

	// The http.Client that is used to get FGA records from WorkOS.
	// Defaults to http.Client.
	HTTPClient *retryablehttp.HttpClient

	// The endpoint to WorkOS API. Defaults to https://api.workos.com.
	Endpoint string

	// The function used to encode in JSON. Defaults to json.Marshal.
	JSONEncode func(v interface{}) ([]byte, error)
	// contains filtered or unexported fields
}

Client represents a client that performs FGA requests to the WorkOS API.

func (*Client) BatchUpdateResourceTypes

func (c *Client) BatchUpdateResourceTypes(ctx context.Context, opts []UpdateResourceTypeOpts) ([]ResourceType, error)

BatchUpdateResourceTypes sets the environment's set of resource types to match the resource types passed.

func (*Client) BatchWriteWarrants

func (c *Client) BatchWriteWarrants(ctx context.Context, opts []WriteWarrantOpts) (WriteWarrantResponse, error)

BatchWriteWarrants performs a write operation on a Warrant.

func (*Client) Check

func (c *Client) Check(ctx context.Context, opts CheckOpts) (CheckResponse, error)

func (*Client) CheckBatch

func (c *Client) CheckBatch(ctx context.Context, opts CheckBatchOpts) ([]CheckResponse, error)

func (*Client) CreateResource

func (c *Client) CreateResource(ctx context.Context, opts CreateResourceOpts) (Resource, error)

CreateResource creates a new resource

func (*Client) DeleteResource

func (c *Client) DeleteResource(ctx context.Context, opts DeleteResourceOpts) error

DeleteResource deletes a Resource

func (*Client) GetResource

func (c *Client) GetResource(ctx context.Context, opts GetResourceOpts) (Resource, error)

GetResource gets a Resource.

func (*Client) ListResourceTypes

func (c *Client) ListResourceTypes(ctx context.Context, opts ListResourceTypesOpts) (ListResourceTypesResponse, error)

ListResourceTypes gets a list of FGA resource types.

func (*Client) ListResources

func (c *Client) ListResources(ctx context.Context, opts ListResourcesOpts) (ListResourcesResponse, error)

ListResources gets a list of FGA resources.

func (*Client) ListWarrants

func (c *Client) ListWarrants(ctx context.Context, opts ListWarrantsOpts) (ListWarrantsResponse, error)

ListWarrants gets a list of Warrants.

func (*Client) Query

func (c *Client) Query(ctx context.Context, opts QueryOpts) (QueryResponse, error)

Query executes a query for a set of resources.

func (*Client) UpdateResource

func (c *Client) UpdateResource(ctx context.Context, opts UpdateResourceOpts) (Resource, error)

UpdateResource updates an existing Resource

func (*Client) WriteWarrant

func (c *Client) WriteWarrant(ctx context.Context, opts WriteWarrantOpts) (WriteWarrantResponse, error)

WriteWarrant performs a write operation on a Warrant.

type Context

type Context map[string]interface{}

Check

func (Context) EncodeValues

func (context Context) EncodeValues(key string, values *url.Values) error

type CreateResourceOpts

type CreateResourceOpts struct {
	// The type of the resource.
	ResourceType string `json:"resource_type"`

	// The customer defined string identifier for this resource.
	ResourceId string `json:"resource_id,omitempty"`

	// Map containing additional information about this resource.
	Meta map[string]interface{} `json:"meta,omitempty"`
}

type DebugInfo

type DebugInfo struct {
	ProcessingTime time.Duration     `json:"processing_time"`
	DecisionTree   *DecisionTreeNode `json:"decision_tree"`
}

type DecisionTreeNode

type DecisionTreeNode struct {
	Check          WarrantCheck       `json:"check"`
	Policy         string             `json:"policy,omitempty"`
	Decision       string             `json:"decision"`
	ProcessingTime time.Duration      `json:"processing_time"`
	Children       []DecisionTreeNode `json:"children"`
}

type DeleteResourceOpts

type DeleteResourceOpts struct {
	// The type of the resource.
	ResourceType string

	// The customer defined string identifier for this resource.
	ResourceId string
}

DeleteResourceOpts contains the options to delete a resource.

type GetResourceOpts

type GetResourceOpts struct {
	// The type of the resource.
	ResourceType string

	// The customer defined string identifier for this resource.
	ResourceId string
}

type ListResourceTypesOpts

type ListResourceTypesOpts struct {
	// Maximum number of records to return.
	Limit int `url:"limit,omitempty"`

	// The order in which to paginate records.
	Order Order `url:"order,omitempty"`

	// Pagination cursor to receive records before a provided ResourceType ID.
	Before string `url:"before,omitempty"`

	// Pagination cursor to receive records after a provided ResourceType ID.
	After string `url:"after,omitempty"`
}

type ListResourceTypesResponse

type ListResourceTypesResponse struct {
	// List of Resource Types.
	Data []ResourceType `json:"data"`

	// Cursor pagination options.
	ListMetadata common.ListMetadata `json:"list_metadata"`
}

func ListResourceTypes

func ListResourceTypes(
	ctx context.Context,
	opts ListResourceTypesOpts,
) (ListResourceTypesResponse, error)

ListResourceTypes gets a list of ResourceTypes.

type ListResourcesOpts

type ListResourcesOpts struct {
	// The type of the resource.
	ResourceType string `url:"resource_type,omitempty"`

	// Searchable text for a Resource. Can be empty.
	Search string `url:"search,omitempty"`

	// Maximum number of records to return.
	Limit int `url:"limit,omitempty"`

	// The order in which to paginate records.
	Order Order `url:"order,omitempty"`

	// Pagination cursor to receive records before a provided Resource ID.
	Before string `url:"before,omitempty"`

	// Pagination cursor to receive records after a provided Resource ID.
	After string `url:"after,omitempty"`
}

type ListResourcesResponse

type ListResourcesResponse struct {
	// List of provisioned Resources.
	Data []Resource `json:"data"`

	// Cursor pagination options.
	ListMetadata common.ListMetadata `json:"list_metadata"`
}

ListResourcesResponse describes the response structure when requesting Resources

func ListResources

func ListResources(
	ctx context.Context,
	opts ListResourcesOpts,
) (ListResourcesResponse, error)

ListResources gets a list of Resources.

type ListWarrantsOpts

type ListWarrantsOpts struct {
	// Only return warrants whose resourceType matches this value.
	ResourceType string `url:"resource_type,omitempty"`

	// Only return warrants whose resourceId matches this value.
	ResourceId string `url:"resource_id,omitempty"`

	// Only return warrants whose relation matches this value.
	Relation string `url:"relation,omitempty"`

	// Only return warrants with a subject whose resourceType matches this value.
	SubjectType string `url:"subject_type,omitempty"`

	// Only return warrants with a subject whose resourceId matches this value.
	SubjectId string `url:"subject_id,omitempty"`

	// Only return warrants with a subject whose relation matches this value.
	SubjectRelation string `url:"subject_relation,omitempty"`

	// Maximum number of records to return.
	Limit int `url:"limit,omitempty"`

	// Pagination cursor to receive records after a provided Warrant ID.
	After string `url:"after,omitempty"`

	// Optional token to specify desired read consistency
	WarrantToken string `url:"-"`
}

type ListWarrantsResponse

type ListWarrantsResponse struct {
	// List of provisioned Warrants.
	Data []Warrant `json:"data"`

	// Cursor pagination options.
	ListMetadata common.ListMetadata `json:"list_metadata"`
}

ListWarrantsResponse describes the response structure when requesting Warrants

func ListWarrants

func ListWarrants(
	ctx context.Context,
	opts ListWarrantsOpts,
) (ListWarrantsResponse, error)

ListWarrants gets a list of Warrants.

type Order

type Order string

Order represents the order of records.

type QueryOpts

type QueryOpts struct {
	// Query to be executed.
	Query string `url:"q"`

	// Contextual data to use for the query.
	Context Context `url:"context,omitempty"`

	// Maximum number of records to return.
	Limit int `url:"limit,omitempty"`

	// The order in which to paginate records.
	Order Order `url:"order,omitempty"`

	// Pagination cursor to receive records before a provided Warrant ID.
	Before string `url:"before,omitempty"`

	// Pagination cursor to receive records after a provided Warrant ID.
	After string `url:"after,omitempty"`

	// Optional token to specify desired read consistency
	WarrantToken string `url:"-"`
}

Query

type QueryResponse

type QueryResponse struct {
	// List of query results.
	Data []QueryResult `json:"data"`

	// Cursor pagination options.
	ListMetadata common.ListMetadata `json:"list_metadata"`
}

func Query

func Query(
	ctx context.Context,
	opts QueryOpts,
) (QueryResponse, error)

Query performs a query for a set of resources.

type QueryResult

type QueryResult struct {
	// The type of the resource.
	ResourceType string `json:"resource_type"`

	// Id of the specific resource.
	ResourceId string `json:"resource_id"`

	// Relation between the resource and subject.
	Relation string `json:"relation"`

	// Warrant matching the provided query
	Warrant Warrant `json:"warrant"`

	// Specifies whether the warrant is implicitly defined.
	IsImplicit bool `json:"is_implicit"`

	// Metadata of the resource.
	Meta map[string]interface{} `json:"meta,omitempty"`
}

type Resource

type Resource struct {
	// The type of the resource.
	ResourceType string `json:"resource_type"`

	// The customer defined string identifier for this resource.
	ResourceId string `json:"resource_id"`

	// Map containing additional information about this resource.
	Meta map[string]interface{} `json:"meta"`
}

Resources

func CreateResource

func CreateResource(
	ctx context.Context,
	opts CreateResourceOpts,
) (Resource, error)

CreateResource creates a Resource.

func GetResource

func GetResource(
	ctx context.Context,
	opts GetResourceOpts,
) (Resource, error)

GetResource gets a Resource.

func UpdateResource

func UpdateResource(
	ctx context.Context,
	opts UpdateResourceOpts,
) (Resource, error)

UpdateResource updates a Resource.

type ResourceType

type ResourceType struct {
	// Unique string ID of the resource type.
	Type string `json:"type"`

	// Set of relationships that subjects can have on resources of this type.
	Relations map[string]interface{} `json:"relations"`
}

Resource types

func BatchUpdateResourceTypes

func BatchUpdateResourceTypes(
	ctx context.Context,
	opts []UpdateResourceTypeOpts,
) ([]ResourceType, error)

BatchUpdateResourceTypes sets the environment's object types to match the provided types.

type Subject

type Subject struct {
	// The type of the subject.
	ResourceType string `json:"resource_type"`

	// The customer defined string identifier for this subject.
	ResourceId string `json:"resource_id"`

	// The relation of the subject.
	Relation string `json:"relation,omitempty"`
}

Warrants

type UpdateResourceOpts

type UpdateResourceOpts struct {
	// The type of the resource.
	ResourceType string `json:"resource_type"`

	// The customer defined string identifier for this resource.
	ResourceId string `json:"resource_id"`

	// Map containing additional information about this resource.
	Meta map[string]interface{} `json:"meta,omitempty"`
}

type UpdateResourceTypeOpts

type UpdateResourceTypeOpts struct {
	// Unique string ID of the resource type.
	Type string `json:"type"`

	// Set of relationships that subjects can have on resources of this type.
	Relations map[string]interface{} `json:"relations"`
}

type Warrant

type Warrant struct {
	// Type of resource to assign a relation to. Must be an existing type.
	ResourceType string `json:"resource_type"`

	// Id of the resource to assign a relation to.
	ResourceId string `json:"resource_id"`

	// Relation to assign to the resource.
	Relation string `json:"relation"`

	// Subject of the warrant
	Subject Subject `json:"subject"`

	// Policy that must evaluate to true for warrant to be valid
	Policy string `json:"policy,omitempty"`
}

type WarrantCheck

type WarrantCheck struct {
	// The type of the resource.
	ResourceType string `json:"resource_type"`

	// Id of the specific resource.
	ResourceId string `json:"resource_id"`

	// Relation to check between the resource and subject.
	Relation string `json:"relation"`

	// The subject that must have the specified relation.
	Subject Subject `json:"subject"`

	// Contextual data to use for the access check.
	Context Context `json:"context,omitempty"`
}

type WriteWarrantOpts

type WriteWarrantOpts struct {
	// Operation to perform for the given warrant
	Op string `json:"op,omitempty"`

	// Type of resource to assign a relation to. Must be an existing type.
	ResourceType string `json:"resource_type"`

	// Id of the resource to assign a relation to.
	ResourceId string `json:"resource_id"`

	// Relation to assign to the resource.
	Relation string `json:"relation"`

	// Subject of the warrant
	Subject Subject `json:"subject"`

	// Policy that must evaluate to true for warrant to be valid
	Policy string `json:"policy,omitempty"`
}

type WriteWarrantResponse

type WriteWarrantResponse struct {
	WarrantToken string `json:"warrant_token"`
}

func BatchWriteWarrants

func BatchWriteWarrants(
	ctx context.Context,
	opts []WriteWarrantOpts,
) (WriteWarrantResponse, error)

BatchWriteWarrants performs write operations on multiple Warrants in one request.

func WriteWarrant

func WriteWarrant(
	ctx context.Context,
	opts WriteWarrantOpts,
) (WriteWarrantResponse, error)

WriteWarrant performs a write operation on a Warrant.

Jump to

Keyboard shortcuts

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