Documentation
¶
Index ¶
- type CedarEngine
- func (c *CedarEngine) Close(ctx context.Context) error
- func (c *CedarEngine) Eval(ctx context.Context, req EvalRequest) (EvalResult, error)
- func (c *CedarEngine) IsAuthorized(ctx context.Context, req EvalRequest) (bool, error)
- func (c *CedarEngine) SetEntitiesFromJson(ctx context.Context, entities string) error
- func (c *CedarEngine) SetPolicies(ctx context.Context, policies string) error
- type EvalRequest
- type EvalResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CedarEngine ¶
type CedarEngine struct {
// contains filtered or unexported fields
}
CedarEngine is an instance of the cedar wasm engine.
func NewCedarEngine ¶
func NewCedarEngine(ctx context.Context) (*CedarEngine, error)
NewCedarEngine creates a new instance of the cedar wasm engine. This is blocking and may take a while to complete. Ensure you do not call this from a hot path.
func (*CedarEngine) Close ¶
func (c *CedarEngine) Close(ctx context.Context) error
Close closes the engine and cleanup the wasm runtime. Ensure you call this when you are done with the engine to free up resources used by the engine.
func (*CedarEngine) Eval ¶
func (c *CedarEngine) Eval(ctx context.Context, req EvalRequest) (EvalResult, error)
Eval evaluates the request against the policies and entities in the engine. See EvalRequest for more information.
func (*CedarEngine) IsAuthorized ¶
func (c *CedarEngine) IsAuthorized(ctx context.Context, req EvalRequest) (bool, error)
IsAuthorized evaluates the request against the policies and entities in the engine and returns true if the request is authorized. It is a convenience method that is equivalent to calling Eval and checking the result. See Eval for more information.
func (*CedarEngine) SetEntitiesFromJson ¶
func (c *CedarEngine) SetEntitiesFromJson(ctx context.Context, entities string) error
SetEntitiesFromJson sets the entities in the engine from a json string. See https://docs.cedarpolicy.com/syntax-entity.html for more information.
func (*CedarEngine) SetPolicies ¶
func (c *CedarEngine) SetPolicies(ctx context.Context, policies string) error
SetPolicies sets the policies in the engine from a string. See https://docs.cedarpolicy.com/syntax-policy.htmle for more information.
type EvalRequest ¶
type EvalRequest struct { // Who is making the request. This is a string in the form of "User::\"alice\"". Principal string `json:"principal"` // What action is being requested. This is a string in the form of "Action::\"update\"". Action string `json:"action"` // What resource is being requested. This is a string in the form of "Photo::\"VacationPhoto94.jpg\"". Resource string `json:"resource"` // Context is a json string that can be used to pass additional information to the policy engine // for use in policy evaluation. // For more information, see https://www.cedarpolicy.com/en/tutorial/context Context string `json:"context"` }
EvalRequest is the request object for the Eval function. Instantion should look like this:
res, err := engine.Eval(context.Background(), cedar.EvalRequest{ Principal: "User::\"alice\"", Action: "Action::\"update\"", Resource: "Photo::\"VacationPhoto94.jpg\"", Context: "{}", })
Do not forget to add a context to the eval call in a json format and escape the quotes. For more information, see https://www.cedarpolicy.com/en/tutorial/abac-pt1
type EvalResult ¶
type EvalResult string
EvalResult is the response object for the Eval function.
const ( EvalResultPermit EvalResult = "Allow" EvalResultDeny EvalResult = "Deny" )
func (EvalResult) IsPermit ¶
func (e EvalResult) IsPermit() bool
func (EvalResult) String ¶
func (e EvalResult) String() string