Skip to content

Commit 6814c61

Browse files
fschadekulmannkobergjmmattel
authored
[full-ci] enhancement: allow ocis to provide custom web applications (owncloud#8523)
* enhancement: allow ocis to provide custom web applications * enhancement: add an option to disable web apps * test: add default logger tests * test: add app loading tests * test: add asset server tests * enhancement: make use of dedicated app conf file and app asset paths * enhancement: adjust asset locations and deprecate WEB_ASSET_PATH * enhancement: get rid of default logger and use the service level logger instead * Apply suggestions from code review Co-authored-by: Benedikt Kulmann <[email protected]> Co-authored-by: kobergj <[email protected]> * enhancement: use basename as app id * Apply suggestions from code review Co-authored-by: Martin <[email protected]> * enhancement: use afero as fs abstraction * enhancement: simplify logo upload * enhancement: make use of introductionVersion field annotations --------- Co-authored-by: Benedikt Kulmann <[email protected]> Co-authored-by: kobergj <[email protected]> Co-authored-by: Martin <[email protected]>
1 parent 6ba9e4a commit 6814c61

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+5834
-129
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Enhancement: Custom WEB App Loading
2+
3+
We've added a new feature which allows the administrator of the environment to provide custom web applications to the
4+
users. This feature is useful for organizations that have specific web applications that they want to provide to their
5+
users.
6+
7+
The users will then be able to access these custom web applications from the web ui.
8+
For a detailed description of the feature, please read the WEB service README.md file.
9+
10+
https://github.com/owncloud/ocis/pull/8523
11+
https://github.com/owncloud/ocis/issues/8392

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module github.com/owncloud/ocis/v2
33
go 1.21
44

55
require (
6+
dario.cat/mergo v1.0.0
67
github.com/CiscoM31/godata v1.0.10
78
github.com/KimMachineGun/automemlimit v0.5.0
89
github.com/Masterminds/semver v1.5.0
@@ -79,6 +80,7 @@ require (
7980
github.com/rs/zerolog v1.32.0
8081
github.com/shamaton/msgpack/v2 v2.1.1
8182
github.com/sirupsen/logrus v1.9.3
83+
github.com/spf13/afero v1.11.0
8284
github.com/spf13/cobra v1.8.0
8385
github.com/stretchr/testify v1.8.4
8486
github.com/thejerf/suture/v4 v4.0.2
@@ -96,6 +98,7 @@ require (
9698
go.opentelemetry.io/otel/sdk v1.24.0
9799
go.opentelemetry.io/otel/trace v1.24.0
98100
golang.org/x/crypto v0.19.0
101+
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3
99102
golang.org/x/image v0.15.0
100103
golang.org/x/net v0.21.0
101104
golang.org/x/oauth2 v0.17.0
@@ -114,7 +117,6 @@ require (
114117

115118
require (
116119
contrib.go.opencensus.io/exporter/prometheus v0.4.2 // indirect
117-
dario.cat/mergo v1.0.0 // indirect
118120
github.com/Azure/go-ntlmssp v0.0.0-20221128193559-754e69321358 // indirect
119121
github.com/BurntSushi/toml v1.3.2 // indirect
120122
github.com/Masterminds/goutils v1.1.1 // indirect
@@ -333,7 +335,6 @@ require (
333335
go.uber.org/atomic v1.11.0 // indirect
334336
go.uber.org/multierr v1.8.0 // indirect
335337
go.uber.org/zap v1.23.0 // indirect
336-
golang.org/x/exp v0.0.0-20240205201215-2c58cdc269a3 // indirect
337338
golang.org/x/mod v0.14.0 // indirect
338339
golang.org/x/sys v0.17.0 // indirect
339340
golang.org/x/time v0.5.0 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,8 @@ github.com/spf13/afero v1.3.3/go.mod h1:5KUK8ByomD5Ti5Artl0RtHeI5pTF7MIDuXL3yY52
19681968
github.com/spf13/afero v1.4.1/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
19691969
github.com/spf13/afero v1.6.0/go.mod h1:Ai8FlHk4v/PARR026UzYexafAt9roJ7LcLMAmO6Z93I=
19701970
github.com/spf13/afero v1.9.2/go.mod h1:iUV7ddyEEZPO5gA3zD4fJt6iStLlL+Lg4m2cihcDf8Y=
1971+
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
1972+
github.com/spf13/afero v1.11.0/go.mod h1:GH9Y3pIexgf1MTIWtNGyogA5MwRIDXGUr+hbWNoBjkY=
19711973
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
19721974
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
19731975
github.com/spf13/cobra v1.1.1/go.mod h1:WnodtKOvamDL/PwE2M4iKs8aMDBZ5Q5klgD3qfVJQMI=

internal/testenv/test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package testenv
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"os/exec"
7+
)
8+
9+
// CMDTest spawns a new independent test environment
10+
type CMDTest struct {
11+
n string
12+
f func()
13+
}
14+
15+
// NewCMDTest creates a new CMDTest instance
16+
func NewCMDTest(name string) CMDTest {
17+
return CMDTest{
18+
n: name,
19+
}
20+
}
21+
22+
// Run runs the cmd subtest
23+
func (t CMDTest) Run(envs ...string) ([]byte, error) {
24+
cmd := exec.Command(os.Args[0], fmt.Sprintf("-test.run=%s", t.n))
25+
cmd.Env = append(os.Environ(), "RUN_CMD_TEST=1")
26+
cmd.Env = append(cmd.Env, envs...)
27+
28+
return cmd.CombinedOutput()
29+
}
30+
31+
// ShouldRun checks if the cmd subtest should run
32+
func (CMDTest) ShouldRun() bool {
33+
return os.Getenv("RUN_CMD_TEST") == "1"
34+
}

internal/testenv/test_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package testenv
2+
3+
import (
4+
"fmt"
5+
"testing"
6+
7+
"github.com/onsi/gomega"
8+
)
9+
10+
func TestNewSubTest(t *testing.T) {
11+
testString := "this is a sub-test"
12+
cmdTest := NewCMDTest(t.Name())
13+
if cmdTest.ShouldRun() {
14+
fmt.Println(testString)
15+
return
16+
}
17+
18+
out, err := cmdTest.Run()
19+
20+
g := gomega.NewWithT(t)
21+
g.Expect(err).ToNot(gomega.HaveOccurred())
22+
g.Expect(string(out)).To(gomega.ContainSubstring(testString))
23+
}

ocis-pkg/assetsfs/assetsfs.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

ocis-pkg/config/helpers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
gofig "github.com/gookit/config/v2"
77
gooyaml "github.com/gookit/config/v2/yaml"
8+
89
"github.com/owncloud/ocis/v2/ocis-pkg/config/defaults"
910
)
1011

@@ -25,8 +26,7 @@ func BindSourcesToStructs(service string, dst interface{}) (*gofig.Config, error
2526
})
2627
cnf.AddDriver(gooyaml.Driver)
2728

28-
cfgFile := path.Join(defaults.BaseConfigPath(), service+".yaml")
29-
_ = cnf.LoadFiles([]string{cfgFile}...)
29+
_ = cnf.LoadFiles(path.Join(defaults.BaseConfigPath(), service+".yaml"))
3030

3131
err := cnf.BindStruct("", &dst)
3232
if err != nil {

ocis-pkg/log/log.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import (
1010

1111
chimiddleware "github.com/go-chi/chi/v5/middleware"
1212
mzlog "github.com/go-micro/plugins/v4/logger/zerolog"
13-
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
1413
"github.com/rs/zerolog"
1514
"github.com/rs/zerolog/log"
1615
"go-micro.dev/v4/logger"
16+
17+
"github.com/owncloud/ocis/v2/ocis-pkg/shared"
1718
)
1819

1920
var (
@@ -148,3 +149,10 @@ func (l Logger) SubloggerWithRequestID(c context.Context) Logger {
148149
l.With().Str(RequestIDString, chimiddleware.GetReqID(c)).Logger(),
149150
}
150151
}
152+
153+
// Deprecation logs a deprecation message,
154+
// it is used to inform the user that a certain feature is deprecated and will be removed in the future.
155+
// Do not use a logger here because the message MUST be visible independent of the log level.
156+
func Deprecation(a ...any) {
157+
fmt.Printf("\033[1;31mDEPRECATION: %s\033[0m\n", a...)
158+
}

ocis-pkg/log/log_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package log_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/onsi/gomega"
7+
8+
"github.com/owncloud/ocis/v2/internal/testenv"
9+
"github.com/owncloud/ocis/v2/ocis-pkg/log"
10+
)
11+
12+
func TestDeprecation(t *testing.T) {
13+
cmdTest := testenv.NewCMDTest(t.Name())
14+
if cmdTest.ShouldRun() {
15+
log.Deprecation("this is a deprecation")
16+
return
17+
}
18+
19+
out, err := cmdTest.Run()
20+
21+
g := gomega.NewWithT(t)
22+
g.Expect(err).ToNot(gomega.HaveOccurred())
23+
g.Expect(string(out)).To(gomega.HavePrefix("\033[1;31mDEPRECATION: this is a deprecation"))
24+
}

ocis-pkg/x/io/fsx/fallback.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fsx
2+
3+
import (
4+
"github.com/spf13/afero"
5+
)
6+
7+
var (
8+
// assert interfaces implemented
9+
_ afero.Fs = (*FallbackFS)(nil)
10+
_ FS = (*FallbackFS)(nil)
11+
)
12+
13+
// FallbackFS is a filesystem that layers a primary filesystem on top of a secondary filesystem.
14+
type FallbackFS struct {
15+
FS
16+
primary *BaseFS
17+
secondary *BaseFS
18+
}
19+
20+
// Primary returns the primary filesystem.
21+
func (d *FallbackFS) Primary() *BaseFS {
22+
return d.primary
23+
}
24+
25+
// Secondary returns the secondary filesystem.
26+
func (d *FallbackFS) Secondary() *BaseFS {
27+
return d.secondary
28+
}
29+
30+
// NewFallbackFS returns a new FallbackFS instance.
31+
func NewFallbackFS(primary, secondary FS) *FallbackFS {
32+
return &FallbackFS{
33+
FS: FromAfero(afero.NewCopyOnWriteFs(secondary, primary)),
34+
primary: &BaseFS{Fs: primary},
35+
secondary: &BaseFS{Fs: secondary},
36+
}
37+
}

0 commit comments

Comments
 (0)