Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var RFMimetypeDetect = rego.Function1( ®o.Function{ Name: "opencloud.mimetype.detect", Decl: types.NewFunction(types.Args(types.A), types.S), Memoize: true, Nondeterministic: true, }, func(_ rego.BuiltinContext, a *ast.Term) (*ast.Term, error) { var body []byte if err := ast.As(a.Value, &body); err != nil { return nil, err } mimetype := mimetype.Detect(body).String() return ast.StringTerm(strings.Split(mimetype, ";")[0]), nil }, )
RFMimetypeDetect extends the rego dictionary with the possibility to detect mimetypes. Be careful, the list of known mimetypes is limited.
Rego: `opencloud.mimetype.extensions(".txt")` Result `text/plain`
var RFResourceDownload = rego.Function1( ®o.Function{ Name: "opencloud.resource.download", Decl: types.NewFunction(types.Args(types.S), types.A), Memoize: true, Nondeterministic: true, }, func(_ rego.BuiltinContext, a *ast.Term) (*ast.Term, error) { var url string if err := ast.As(a.Value, &url); err != nil { return nil, err } req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err } client := rhttp.GetHTTPClient(rhttp.Insecure(true)) res, err := client.Do(req) if err != nil { return nil, err } defer res.Body.Close() if res.StatusCode != http.StatusOK { return nil, fmt.Errorf("unexpected status code from Download %v", res.StatusCode) } buf := new(bytes.Buffer) if _, err := buf.ReadFrom(res.Body); err != nil { return nil, err } v, err := ast.InterfaceToValue(buf.Bytes()) if err != nil { return nil, err } return ast.NewTerm(v), nil }, )
RFResourceDownload extends the rego dictionary with the possibility to download opencloud resources.
Rego: `opencloud.resource.download("opencloud/path/0034892347349827")` Result: bytes
Functions ¶
func RFMimetypeExtensions ¶
RFMimetypeExtensions extends the rego dictionary with the possibility of mapping mimetypes to file extensions. Be careful calling this multiple times with individual readers, the mime store is global, which results in one global store which holds all known mimetype mappings at once.
Rego: `opencloud.mimetype.extensions("application/pdf")` Result `[.pdf]`