Merge pull request #61 from opencloud-eu/policies-rename

Rebrand policies
This commit is contained in:
Florian Schade
2025-01-17 11:33:17 +01:00
committed by GitHub
6 changed files with 26 additions and 26 deletions

View File

@@ -136,16 +136,16 @@ Note that additional steps can be configured and their position in the list defi
## Rego Key Match
To identify available keys for OPA, you need to look at [engine.go](https://github.com/owncloud/ocis/blob/master/services/policies/pkg/engine/engine.go) and the [policies.swagger.json](https://github.com/owncloud/ocis/blob/master/protogen/gen/opencloud/services/policies/v0/policies.swagger.json) file. Note that which keys are available depends on from which module it is used.
To identify available keys for OPA, you need to look at [engine.go](https://github.com/opencloud-eu/opencloud/blob/master/services/policies/pkg/engine/engine.go) and the [policies.swagger.json](https://github.com/opencloud/blob/blob/master/protogen/gen/opencloud/services/policies/v0/policies.swagger.json) file. Note that which keys are available depends on from which module it is used.
## Extend Mimetype File Extension Mapping
In the extended set of the rego query language, it is possible to get a list of associated file extensions based on a mimetype, for example `ocis.mimetype.extensions("application/pdf")`.
In the extended set of the rego query language, it is possible to get a list of associated file extensions based on a mimetype, for example `opencloud.mimetype.extensions("application/pdf")`.
The list of mappings is restricted by default and is provided by the host system ocis is installed on.
The list of mappings is restricted by default and is provided by the host system OpenCloud is installed on.
In order to extend this list, ocis must be provided with the path to a custom `mime.types` file that maps mimetypes to extensions.
The location for the file must be accessible by all instances of the policy service. As a rule of thumb, use the directory where the ocis configuration files are stored.
In order to extend this list, OpenCloud must be provided with the path to a custom `mime.types` file that maps mimetypes to extensions.
The location for the file must be accessible by all instances of the policy service. As a rule of thumb, use the directory where the OpenCloud configuration files are stored.
Note that existing mappings from the host are extended by the definitions from the mime types file, but not replaced.
The path to that file can be provided via a yaml configuration or an environment variable. Note to replace the `OC_CONFIG_DIR` string by an existing path.
@@ -164,4 +164,4 @@ A good example of how such a file should be formatted can be found in the [Apach
## Example Policies
The policies service contains a set of preconfigured example policies. See the [deployment examples](https://github.com/owncloud/ocis/tree/master/deployments/examples) directory for details. The contained policies disallow Infinite Scale to create certain file types, both via the proxy middleware and the events service via postprocessing.
The policies service contains a set of preconfigured example policies. See the [deployment examples](https://github.com/opencloud-eu/opencloud/tree/master/deployments/examples) directory for details. The contained policies disallow OpenCloud to create certain file types, both via the proxy middleware and the events service via postprocessing.

View File

@@ -21,7 +21,7 @@ func GetCommands(cfg *config.Config) cli.Commands {
func Execute(cfg *config.Config) error {
app := clihelper.DefaultApp(&cli.App{
Name: "policies",
Usage: "Serve ownCloud policies for oCIS",
Usage: "Serve policies for OpenCloud",
Commands: GetCommands(cfg),
})

View File

@@ -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(
&rego.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(
&rego.Function{
Name: "ocis.mimetype.detect",
Name: "opencloud.mimetype.detect",
Decl: types.NewFunction(types.Args(types.A), types.S),
Memoize: true,
Nondeterministic: true,

View File

@@ -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")),
)
})
})

View File

@@ -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(
&rego.Function{
Name: "ocis.resource.download",
Name: "opencloud.resource.download",
Decl: types.NewFunction(types.Args(types.S), types.A),
Memoize: true,
Nondeterministic: true,

View File

@@ -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())