Skip to content

Commit

Permalink
add missing cors config in the ocdav service
Browse files Browse the repository at this point in the history
  • Loading branch information
micbar committed Mar 31, 2023
1 parent 45bcf92 commit 53528b0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-cors-ocdav.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Fix missing CORS config in ocdav service

The ocdav service is started with a go micro wrapper. We needed to add the cors config.

https://github.com/cs3org/reva/pull/3764
36 changes: 34 additions & 2 deletions pkg/micro/ocdav/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ type Options struct {
MetricsSubsystem string

// ocdav.* is internal so we need to set config options individually
config ocdav.Config
lockSystem ocdav.LockSystem
config ocdav.Config
lockSystem ocdav.LockSystem
AllowCredentials bool
AllowedOrigins []string
AllowedHeaders []string
AllowedMethods []string
}

// newOptions initializes the available default options.
Expand Down Expand Up @@ -275,3 +279,31 @@ func MetricsSubsystem(val string) Option {
o.MetricsSubsystem = val
}
}

// AllowCredentials provides a function to set the AllowCredentials option.
func AllowCredentials(val bool) Option {
return func(o *Options) {
o.AllowCredentials = val
}
}

// AllowedOrigins provides a function to set the AllowedOrigins option.
func AllowedOrigins(val []string) Option {
return func(o *Options) {
o.AllowedOrigins = val
}
}

// AllowedMethods provides a function to set the AllowedMethods option.
func AllowedMethods(val []string) Option {
return func(o *Options) {
o.AllowedMethods = val
}
}

// AllowedHeaders provides a function to set the AllowedHeaders option.
func AllowedHeaders(val []string) Option {
return func(o *Options) {
o.AllowedHeaders = val
}
}
10 changes: 9 additions & 1 deletion pkg/micro/ocdav/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (

"github.com/cs3org/reva/v2/internal/http/interceptors/appctx"
"github.com/cs3org/reva/v2/internal/http/interceptors/auth"
cors2 "github.com/cs3org/reva/v2/internal/http/interceptors/cors"
revaLogMiddleware "github.com/cs3org/reva/v2/internal/http/interceptors/log"
"github.com/cs3org/reva/v2/internal/http/services/owncloud/ocdav"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
Expand Down Expand Up @@ -163,6 +164,13 @@ func useMiddlewares(r *chi.Mux, sopts *Options, svc global.Service, tp trace.Tra
// log
lm := revaLogMiddleware.New()

cors, _, err := cors2.New(map[string]interface{}{
"allow_credentials": sopts.AllowCredentials,
"allowed_methods": sopts.AllowedMethods,
"allowed_headers": sopts.AllowedHeaders,
"allowed_origins": sopts.AllowedOrigins,
})

// tracing
tm := func(h http.Handler) http.Handler { return h }
if sopts.TracingEnabled {
Expand Down Expand Up @@ -201,7 +209,7 @@ func useMiddlewares(r *chi.Mux, sopts *Options, svc global.Service, tp trace.Tra
rm := middleware.RequestID

// actually register
r.Use(pm, tm, lm, authMiddle, rm, cm)
r.Use(pm, tm, lm, authMiddle, rm, cm, cors)
return nil
}

Expand Down

0 comments on commit 53528b0

Please sign in to comment.