Add autoprovision accounts flag

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2020-10-05 11:25:02 +02:00
parent 9a17287f73
commit 60c319faed
6 changed files with 44 additions and 15 deletions

View File

@@ -104,7 +104,7 @@ func AccountUUID(opts ...Option) func(next http.Handler) http.Handler {
w.WriteHeader(http.StatusInternalServerError)
}
if status != 0 || account == nil {
if status == http.StatusNotFound {
if opt.AutoprovisionAccounts && status == http.StatusNotFound {
account, status = createAccount(l, claims, opt.AccountsClient)
if status != 0 {
w.WriteHeader(status)

View File

@@ -1,9 +1,10 @@
package middleware
import (
settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
"net/http"
settings "github.com/owncloud/ocis/settings/pkg/proto/v0"
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
acc "github.com/owncloud/ocis/accounts/pkg/proto/v0"
"github.com/owncloud/ocis/ocis-pkg/log"
@@ -36,6 +37,8 @@ type Options struct {
Store storepb.StoreService
// PreSignedURLConfig to configure the middleware
PreSignedURLConfig config.PreSignedURL
// AutoprovisionAccounts when an account does not exist.
AutoprovisionAccounts bool
}
// newOptions initializes the available default options.
@@ -118,3 +121,10 @@ func PreSignedURLConfig(cfg config.PreSignedURL) Option {
o.PreSignedURLConfig = cfg
}
}
// AutoprovisionAccounts provides a function to set the AutoprovisionAccounts config
func AutoprovisionAccounts(val bool) Option {
return func(o *Options) {
o.AutoprovisionAccounts = val
}
}