Rebrand policies
This commit is contained in:
@@ -16,7 +16,7 @@ import (
|
||||
// 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: `ocis.mimetype.extensions("application/pdf")`
|
||||
// Rego: `opencloud.mimetype.extensions("application/pdf")`
|
||||
// Result `[.pdf]`
|
||||
func RFMimetypeExtensions(f io.Reader) (func(*rego.Rego), error) {
|
||||
if f != nil {
|
||||
@@ -44,7 +44,7 @@ func RFMimetypeExtensions(f io.Reader) (func(*rego.Rego), error) {
|
||||
|
||||
return rego.Function1(
|
||||
®o.Function{
|
||||
Name: "ocis.mimetype.extensions",
|
||||
Name: "opencloud.mimetype.extensions",
|
||||
Decl: types.NewFunction(types.Args(types.S), types.A),
|
||||
Memoize: true,
|
||||
Nondeterministic: true,
|
||||
@@ -74,11 +74,11 @@ func RFMimetypeExtensions(f io.Reader) (func(*rego.Rego), error) {
|
||||
// RFMimetypeDetect extends the rego dictionary with the possibility to detect mimetypes.
|
||||
// Be careful, the list of known mimetypes is limited.
|
||||
//
|
||||
// Rego: `ocis.mimetype.extensions(".txt")`
|
||||
// Rego: `opencloud.mimetype.extensions(".txt")`
|
||||
// Result `text/plain`
|
||||
var RFMimetypeDetect = rego.Function1(
|
||||
®o.Function{
|
||||
Name: "ocis.mimetype.detect",
|
||||
Name: "opencloud.mimetype.detect",
|
||||
Decl: types.NewFunction(types.Args(types.A), types.S),
|
||||
Memoize: true,
|
||||
Nondeterministic: true,
|
||||
|
||||
@@ -12,22 +12,22 @@ import (
|
||||
"github.com/opencloud-eu/opencloud/services/policies/pkg/engine/opa"
|
||||
)
|
||||
|
||||
var _ = Describe("opa ocis mimetype functions", func() {
|
||||
Describe("ocis.mimetype.detect", func() {
|
||||
var _ = Describe("opa opencloud mimetype functions", func() {
|
||||
Describe("opencloud.mimetype.detect", func() {
|
||||
It("detects the mimetype", func() {
|
||||
r := rego.New(rego.Query(`ocis.mimetype.detect("")`), opa.RFMimetypeDetect)
|
||||
r := rego.New(rego.Query(`opencloud.mimetype.detect("")`), opa.RFMimetypeDetect)
|
||||
rs, err := r.Eval(context.Background())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(rs[0].Expressions[0].String()).To(Equal("text/plain"))
|
||||
})
|
||||
})
|
||||
Describe("ocis.mimetype.extensions", func() {
|
||||
Describe("opencloud.mimetype.extensions", func() {
|
||||
DescribeTable("resolves extensions by mimetype",
|
||||
func(mimetype string, expectations []string, f io.Reader) {
|
||||
rfMimetypeExtensions, err := opa.RFMimetypeExtensions(f)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
r := rego.New(rego.Query(`ocis.mimetype.extensions("`+mimetype+`")`), rfMimetypeExtensions)
|
||||
r := rego.New(rego.Query(`opencloud.mimetype.extensions("`+mimetype+`")`), rfMimetypeExtensions)
|
||||
rs, err := r.Eval(context.Background())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
@@ -48,10 +48,10 @@ var _ = Describe("opa ocis mimetype functions", func() {
|
||||
}
|
||||
},
|
||||
Entry("With default mimetype", "application/pdf", []string{".pdf"}, nil),
|
||||
Entry("With unknown mimetype", "ocis/with.custom.mt", []string{}, nil),
|
||||
Entry("With custom mimetype", "ocis/with.custom.mt", []string{".with.custom.mt"}, strings.NewReader("ocis/with.custom.mt with.custom.mt")),
|
||||
Entry("With multiple custom mimetypes", "ocis/with.multiple.custom.mt", []string{".with.multiple.custom.1.mt", ".with.multiple.custom.2.mt"}, strings.NewReader("ocis/with.multiple.custom.mt with.multiple.custom.1.mt with.multiple.custom.2.mt")),
|
||||
Entry("With custom ignored mimetype", "ocis/with.multiple.custom.ignored.mt", []string{}, strings.NewReader("#ocis/with.multiple.custom.ignored.mt with.multiple.custom.ignored.mt")),
|
||||
Entry("With unknown mimetype", "opencloud/with.custom.mt", []string{}, nil),
|
||||
Entry("With custom mimetype", "opencloud/with.custom.mt", []string{".with.custom.mt"}, strings.NewReader("opencloud/with.custom.mt with.custom.mt")),
|
||||
Entry("With multiple custom mimetypes", "opencloud/with.multiple.custom.mt", []string{".with.multiple.custom.1.mt", ".with.multiple.custom.2.mt"}, strings.NewReader("opencloud/with.multiple.custom.mt with.multiple.custom.1.mt with.multiple.custom.2.mt")),
|
||||
Entry("With custom ignored mimetype", "opencloud/with.multiple.custom.ignored.mt", []string{}, strings.NewReader("#opencloud/with.multiple.custom.ignored.mt with.multiple.custom.ignored.mt")),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"github.com/open-policy-agent/opa/types"
|
||||
)
|
||||
|
||||
// RFResourceDownload extends the rego dictionary with the possibility to download oCis resources.
|
||||
// RFResourceDownload extends the rego dictionary with the possibility to download opencloud resources.
|
||||
//
|
||||
// Rego: `ocis.resource.download("ocis/path/0034892347349827")`
|
||||
// Rego: `opencloud.resource.download("opencloud/path/0034892347349827")`
|
||||
// Result: bytes
|
||||
var RFResourceDownload = rego.Function1(
|
||||
®o.Function{
|
||||
Name: "ocis.resource.download",
|
||||
Name: "opencloud.resource.download",
|
||||
Decl: types.NewFunction(types.Args(types.S), types.A),
|
||||
Memoize: true,
|
||||
Nondeterministic: true,
|
||||
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
"github.com/opencloud-eu/opencloud/services/policies/pkg/engine/opa"
|
||||
)
|
||||
|
||||
var _ = Describe("opa ocis resource functions", func() {
|
||||
Describe("ocis.resource.download", func() {
|
||||
var _ = Describe("opa opencloud resource functions", func() {
|
||||
Describe("opencloud.resource.download", func() {
|
||||
It("downloads reva resources", func() {
|
||||
ts := []byte("Lorem Ipsum is simply dummy text of the printing and typesetting")
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -22,7 +22,7 @@ var _ = Describe("opa ocis resource functions", func() {
|
||||
}))
|
||||
defer srv.Close()
|
||||
|
||||
r := rego.New(rego.Query(`ocis.resource.download("`+srv.URL+`")`), opa.RFResourceDownload)
|
||||
r := rego.New(rego.Query(`opencloud.resource.download("`+srv.URL+`")`), opa.RFResourceDownload)
|
||||
rs, err := r.Eval(context.Background())
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user