Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add missing cors config in the ocdav service #3764

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
13 changes: 12 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,16 @@ 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,
})
if err != nil {
return err
}

// tracing
tm := func(h http.Handler) http.Handler { return h }
if sopts.TracingEnabled {
Expand Down Expand Up @@ -201,7 +212,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