Files
ocis/services/storage-users/pkg/revaconfig/config.go
LarsJurgensenandFiras Frikha cc8c1c883f ci: [k6-test] [OCISDEV-900] Extract upload coordinator out of decomposedfs (#12913)
* chore(OCISDEV-900): bump reva to pr7-switchover, add upload_directory and mount_id to revaconfig

* chore(OCISDEV-900): bump reva to the switchover rebased on the upload write fix

* chore(OCISDEV-900): bump reva to main with the upload coordinator switchover

---------

Co-authored-by: Firas Frikha <firas.frikha@kiteworks.com>
2026-10-07 18:28:34 +02:00

149 lines
5.6 KiB
Go

// Package revaconfig contains the config for the reva service
package revaconfig
import (
"strconv"
"strings"
"github.com/owncloud/ocis/v2/ocis-pkg/cors"
"github.com/owncloud/ocis/v2/ocis-pkg/generators"
"github.com/owncloud/ocis/v2/services/storage-users/pkg/config"
)
// StorageUsersConfigFromStruct will adapt an oCIS config struct into a reva mapstructure to start a reva service.
func StorageUsersConfigFromStruct(cfg *config.Config) map[string]interface{} {
// Credentials must not be combined with a wildcard origin.
corsAllowCredentials := cfg.HTTP.CORS.AllowCredentials
if corsAllowCredentials && cors.AllowsAnyOrigin(cfg.HTTP.CORS.AllowedOrigins) {
corsAllowCredentials = false
}
rcfg := map[string]interface{}{
"core": map[string]interface{}{
"graceful_shutdown_timeout": cfg.GracefulShutdownTimeout,
},
"shared": map[string]interface{}{
"jwt_secret": cfg.TokenManager.JWTSecret,
"gatewaysvc": cfg.Reva.Address,
"skip_user_groups_in_token": cfg.SkipUserGroupsInToken,
"grpc_client_options": cfg.Reva.GetGRPCClientConfig(),
},
"grpc": map[string]interface{}{
"network": cfg.GRPC.Protocol,
"address": cfg.GRPC.Addr,
"tls_settings": map[string]interface{}{
"enabled": cfg.GRPC.TLS.Enabled,
"certificate": cfg.GRPC.TLS.Cert,
"key": cfg.GRPC.TLS.Key,
},
// TODO build services dynamically
"services": map[string]interface{}{
"storageprovider": map[string]interface{}{
"driver": cfg.Driver,
"drivers": StorageProviderDrivers(cfg),
"mount_id": cfg.MountID,
"expose_data_server": cfg.ExposeDataServer,
"data_server_url": cfg.DataServerURL,
"upload_expiration": cfg.UploadExpiration,
"events": map[string]interface{}{
"nats_address": cfg.Events.Addr,
"nats_clusterid": cfg.Events.ClusterID,
"tls_insecure": cfg.Events.TLSInsecure,
"tls_root_ca_cert": cfg.Events.TLSRootCaCertPath,
"nats_enable_tls": cfg.Events.EnableTLS,
"nats_username": cfg.Events.AuthUsername,
"nats_password": cfg.Events.AuthPassword,
},
},
},
"interceptors": map[string]interface{}{
"eventsmiddleware": map[string]interface{}{
"group": "sharing",
"type": "nats",
"address": cfg.Events.Addr,
"clusterID": cfg.Events.ClusterID,
"tls-insecure": cfg.Events.TLSInsecure,
"tls-root-ca-cert": cfg.Events.TLSRootCaCertPath,
"enable-tls": cfg.Events.EnableTLS,
"name": generators.GenerateConnectionName(cfg.Service.Name, generators.NTypeBus),
"username": cfg.Events.AuthUsername,
"password": cfg.Events.AuthPassword,
},
"prometheus": map[string]interface{}{
"namespace": "ocis",
"subsystem": "storage_users",
},
},
},
"http": map[string]interface{}{
"network": cfg.HTTP.Protocol,
"address": cfg.HTTP.Addr,
"middlewares": map[string]interface{}{
"requestid": map[string]interface{}{},
},
// TODO build services dynamically
"services": map[string]interface{}{
"dataprovider": map[string]interface{}{
"prefix": cfg.HTTP.Prefix,
"driver": cfg.Driver,
"drivers": DataProviderDrivers(cfg),
"mount_id": cfg.MountID,
"nats_address": cfg.Events.Addr,
"nats_clusterID": cfg.Events.ClusterID,
"nats_tls_insecure": cfg.Events.TLSInsecure,
"nats_root_ca_cert_path": cfg.Events.TLSRootCaCertPath,
"nats_enable_tls": cfg.Events.EnableTLS,
"nats_username": cfg.Events.AuthUsername,
"nats_password": cfg.Events.AuthPassword,
"data_txs": map[string]interface{}{
"simple": map[string]interface{}{
"cache_store": "noop",
"cache_database": "system",
"cache_table": "stat",
},
"spaces": map[string]interface{}{
"cache_store": "noop",
"cache_database": "system",
"cache_table": "stat",
},
"tus": map[string]interface{}{
"cache_store": "noop",
"cache_database": "system",
"cache_table": "stat",
"cors_enabled": true,
// allow_origin is configured as a regex in tusd, so we concatenate the configured values into a regex
"cors_allow_origin": "(" + strings.ReplaceAll(strings.Join(cfg.HTTP.CORS.AllowedOrigins, "|"), "*", ".*") + ")",
"cors_allow_credentials": corsAllowCredentials,
"cors_allow_methods": strings.Join(cfg.HTTP.CORS.AllowedMethods, ","),
"cors_allow_headers": strings.Join(cfg.HTTP.CORS.AllowedHeaders, ","),
"cors_max_age": strconv.FormatUint(uint64(cfg.HTTP.CORS.MaxAge), 10),
"cors_expose_headers": strings.Join(cfg.HTTP.CORS.ExposedHeaders, ","),
},
},
},
},
},
}
gcfg := rcfg["grpc"].(map[string]interface{})
if cfg.ReadOnly {
// Replace all interceptors with readonly when the storage is read-only.
// eventsmiddleware and prometheus are intentionally dropped in this mode.
gcfg["interceptors"] = map[string]interface{}{
"readonly": map[string]interface{}{},
}
}
if cfg.EnableVaultMode {
// Set mfa_enabled inside the auth interceptor config so that all gRPC
// calls to this vault storage-users instance require MFA authentication.
interceptors := gcfg["interceptors"].(map[string]interface{})
if authCfg, ok := interceptors["auth"].(map[string]interface{}); ok {
authCfg["mfa_enabled"] = true
} else {
interceptors["auth"] = map[string]interface{}{
"mfa_enabled": true,
}
}
}
return rcfg
}