Documentation
¶
Overview ¶
Package extargs adds external arguments to the invocation's arguments before the policy is evaluated.
Index ¶
Examples ¶
Constants ¶
View Source
const HttpArgsKey = "http"
HttpArgsKey is the key in the args, used for: - if it exists in the invocation, holds a hash of the args derived from the HTTP request - in the final args to be evaluated against the policies, holds the args derived from the HTTP request
Variables ¶
This section is empty.
Functions ¶
func MakeHttpHash ¶
func MakeHttpHash(req *http.Request) (invocation.Option, error)
MakeHttpHash compute the hash of the derived arguments from the HTTP request. If that hash is inserted at the HttpArgsKey key in the invocation arguments, this increases the security as the UCAN token cannot be used with a different HTTP request. For convenience, the hash is returned as a ready-to-use invocation argument.
Types ¶
type CustomExtArgs ¶
type CustomExtArgs struct {
// contains filtered or unexported fields
}
Example ¶
// Note: this is an example for how to build arguments, but you likely want to use CustomExtArgs
// through UcanCtx.
pol := policy.Policy{} // policies from the delegations
// We will construct the following args:
// "key": {
// "ntwk":"eth-mainnet",
// "quota":{
// "ur":1234,
// "udc":1234,
// "arch":1234,
// "down":1234,
// "store":1234,
// "up":1234
// }
// }
customArgs := NewCustomExtArgs("key", pol, func(ma datamodel.MapAssembler) {
qp.MapEntry(ma, "ntwk", qp.String("eth-mainnet"))
qp.MapEntry(ma, "quota", qp.Map(6, func(ma datamodel.MapAssembler) {
qp.MapEntry(ma, "ur", qp.Int(1234))
qp.MapEntry(ma, "udc", qp.Int(1234))
qp.MapEntry(ma, "arch", qp.Int(1234))
qp.MapEntry(ma, "down", qp.Int(1234))
qp.MapEntry(ma, "store", qp.Int(1234))
qp.MapEntry(ma, "up", qp.Int(1234))
}))
})
err := customArgs.Verify()
fmt.Println(err)
Output: <nil>
func NewCustomExtArgs ¶
func NewCustomExtArgs(key string, pol policy.Policy, assembler func(ma datamodel.MapAssembler)) *CustomExtArgs
func (*CustomExtArgs) Verify ¶
func (cea *CustomExtArgs) Verify() error
type HttpExtArgs ¶
type HttpExtArgs struct {
// contains filtered or unexported fields
}
func NewHttpExtArgs ¶
func (*HttpExtArgs) Verify ¶
func (hea *HttpExtArgs) Verify() error
Click to show internal directories.
Click to hide internal directories.