Merge branch 'master' into search
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
+17
-19
@@ -36,11 +36,6 @@ import (
|
||||
webdav "github.com/owncloud/ocis/extensions/webdav/pkg/config"
|
||||
)
|
||||
|
||||
// TokenManager is the config for using the reva token manager
|
||||
type TokenManager struct {
|
||||
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET"`
|
||||
}
|
||||
|
||||
const (
|
||||
// SUPERVISED sets the runtime mode as supervised threads.
|
||||
SUPERVISED = iota
|
||||
@@ -62,22 +57,25 @@ type Runtime struct {
|
||||
type Config struct {
|
||||
*shared.Commons `yaml:"shared"`
|
||||
|
||||
Tracing shared.Tracing `yaml:"tracing"`
|
||||
Log *shared.Log `yaml:"log"`
|
||||
Tracing *shared.Tracing `yaml:"tracing"`
|
||||
Log *shared.Log `yaml:"log"`
|
||||
|
||||
Mode Mode // DEPRECATED
|
||||
File string
|
||||
OcisURL string `yaml:"ocis_url"`
|
||||
|
||||
Registry string `yaml:"registry"`
|
||||
TokenManager TokenManager `yaml:"token_manager"`
|
||||
Runtime Runtime `yaml:"runtime"`
|
||||
Registry string `yaml:"registry"`
|
||||
TokenManager *shared.TokenManager `yaml:"token_manager"`
|
||||
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY"`
|
||||
TransferSecret string `yaml:"transfer_secret" env:"STORAGE_TRANSFER_SECRET"`
|
||||
MetadataUserID string `yaml:"metadata_user_id"`
|
||||
Runtime Runtime `yaml:"runtime"`
|
||||
|
||||
Audit *audit.Config `yaml:"audit"`
|
||||
Accounts *accounts.Config `yaml:"accounts"`
|
||||
GLAuth *glauth.Config `yaml:"glauth"`
|
||||
Graph *graph.Config `yaml:"graph"`
|
||||
GraphExplorer *graphExplorer.Config `yaml:"graph_explorer"`
|
||||
GraphExplorer *graphExplorer.Config `yaml:"graph-explorer"`
|
||||
IDP *idp.Config `yaml:"idp"`
|
||||
IDM *idm.Config `yaml:"idm"`
|
||||
Nats *nats.Config `yaml:"nats"`
|
||||
@@ -88,17 +86,17 @@ type Config struct {
|
||||
Settings *settings.Config `yaml:"settings"`
|
||||
Gateway *gateway.Config `yaml:"gateway"`
|
||||
Frontend *frontend.Config `yaml:"frontend"`
|
||||
AuthBasic *authbasic.Config `yaml:"auth_basic"`
|
||||
AuthBearer *authbearer.Config `yaml:"auth_bearer"`
|
||||
AuthMachine *authmachine.Config `yaml:"auth_machine"`
|
||||
AuthBasic *authbasic.Config `yaml:"auth-basic"`
|
||||
AuthBearer *authbearer.Config `yaml:"auth-bearer"`
|
||||
AuthMachine *authmachine.Config `yaml:"auth-machine"`
|
||||
User *user.Config `yaml:"user"`
|
||||
Group *group.Config `yaml:"group"`
|
||||
AppProvider *appprovider.Config `yaml:"app_provider"`
|
||||
AppProvider *appprovider.Config `yaml:"appprovider"`
|
||||
Sharing *sharing.Config `yaml:"sharing"`
|
||||
StorageMetadata *storagemetadata.Config `yaml:"storage_metadata"`
|
||||
StoragePublicLink *storagepublic.Config `yaml:"storage_public"`
|
||||
StorageUsers *storageusers.Config `yaml:"storage_users"`
|
||||
StorageShares *storageshares.Config `yaml:"storage_shares"`
|
||||
StorageMetadata *storagemetadata.Config `yaml:"storage-metadata"`
|
||||
StoragePublicLink *storagepublic.Config `yaml:"storage-public"`
|
||||
StorageUsers *storageusers.Config `yaml:"storage-users"`
|
||||
StorageShares *storageshares.Config `yaml:"storage-shares"`
|
||||
OCDav *ocdav.Config `yaml:"ocdav"`
|
||||
Store *store.Config `yaml:"store"`
|
||||
Thumbnails *thumbnails.Config `yaml:"thumbnails"`
|
||||
|
||||
@@ -36,43 +36,40 @@ import (
|
||||
|
||||
func DefaultConfig() *Config {
|
||||
return &Config{
|
||||
TokenManager: TokenManager{
|
||||
JWTSecret: "Pive-Fumkiu4",
|
||||
},
|
||||
Runtime: Runtime{
|
||||
Port: "9250",
|
||||
Host: "localhost",
|
||||
},
|
||||
Audit: audit.DefaultConfig(),
|
||||
Accounts: accounts.DefaultConfig(),
|
||||
AppProvider: appprovider.DefaultConfig(),
|
||||
Audit: audit.DefaultConfig(),
|
||||
AuthBasic: authbasic.DefaultConfig(),
|
||||
AuthBearer: authbearer.DefaultConfig(),
|
||||
AuthMachine: authmachine.DefaultConfig(),
|
||||
Frontend: frontend.DefaultConfig(),
|
||||
Gateway: gateway.DefaultConfig(),
|
||||
GLAuth: glauth.DefaultConfig(),
|
||||
Graph: graph.DefaultConfig(),
|
||||
IDP: idp.DefaultConfig(),
|
||||
GraphExplorer: graphExplorer.DefaultConfig(),
|
||||
Group: group.DefaultConfig(),
|
||||
IDM: idm.DefaultConfig(),
|
||||
IDP: idp.DefaultConfig(),
|
||||
Nats: nats.DefaultConfig(),
|
||||
Notifications: notifications.DefaultConfig(),
|
||||
Proxy: proxy.DefaultConfig(),
|
||||
GraphExplorer: graphExplorer.DefaultConfig(),
|
||||
OCDav: ocdav.DefaultConfig(),
|
||||
OCS: ocs.DefaultConfig(),
|
||||
Proxy: proxy.DefaultConfig(),
|
||||
Search: search.FullDefaultConfig(),
|
||||
Settings: settings.DefaultConfig(),
|
||||
Web: web.DefaultConfig(),
|
||||
Sharing: sharing.DefaultConfig(),
|
||||
StorageMetadata: storagemetadata.DefaultConfig(),
|
||||
StoragePublicLink: storagepublic.DefaultConfig(),
|
||||
StorageShares: storageshares.DefaultConfig(),
|
||||
StorageUsers: storageusers.DefaultConfig(),
|
||||
Store: store.DefaultConfig(),
|
||||
Thumbnails: thumbnails.DefaultConfig(),
|
||||
User: user.DefaultConfig(),
|
||||
Web: web.DefaultConfig(),
|
||||
WebDAV: webdav.DefaultConfig(),
|
||||
Gateway: gateway.FullDefaultConfig(),
|
||||
AuthBasic: authbasic.FullDefaultConfig(),
|
||||
AuthBearer: authbearer.FullDefaultConfig(),
|
||||
AuthMachine: authmachine.FullDefaultConfig(),
|
||||
User: user.FullDefaultConfig(),
|
||||
Group: group.FullDefaultConfig(),
|
||||
Sharing: sharing.FullDefaultConfig(),
|
||||
StorageMetadata: storagemetadata.FullDefaultConfig(),
|
||||
StoragePublicLink: storagepublic.FullDefaultConfig(),
|
||||
StorageUsers: storageusers.FullDefaultConfig(),
|
||||
StorageShares: storageshares.FullDefaultConfig(),
|
||||
AppProvider: appprovider.FullDefaultConfig(),
|
||||
Frontend: frontend.FullDefaultConfig(),
|
||||
OCDav: ocdav.FullDefaultConfig(),
|
||||
Search: search.FullDefaultConfig(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,24 +8,16 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/shared"
|
||||
)
|
||||
|
||||
// ParseConfig loads ocis configuration.
|
||||
// ParseConfig loads the ocis configuration and
|
||||
// copies applicable parts into the commons part, from
|
||||
// where the extensions can copy it into their own config
|
||||
func ParseConfig(cfg *config.Config) error {
|
||||
_, err := config.BindSourcesToStructs("ocis", cfg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// provide with defaults for shared logging, since we need a valid destination address for BindEnv.
|
||||
if cfg.Log == nil && cfg.Commons != nil && cfg.Commons.Log != nil {
|
||||
cfg.Log = &shared.Log{
|
||||
Level: cfg.Commons.Log.Level,
|
||||
Pretty: cfg.Commons.Log.Pretty,
|
||||
Color: cfg.Commons.Log.Color,
|
||||
File: cfg.Commons.Log.File,
|
||||
}
|
||||
} else if cfg.Log == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
}
|
||||
EnsureDefaults(cfg)
|
||||
|
||||
// load all env variables relevant to the config in the current context.
|
||||
if err := envdecode.Decode(cfg); err != nil {
|
||||
@@ -35,5 +27,95 @@ func ParseConfig(cfg *config.Config) error {
|
||||
}
|
||||
}
|
||||
|
||||
EnsureCommons(cfg)
|
||||
|
||||
return Validate(cfg)
|
||||
}
|
||||
|
||||
// EnsureDefaults, ensures that all pointers in the
|
||||
// oCIS config (not the extensions configs) are initialized
|
||||
func EnsureDefaults(cfg *config.Config) {
|
||||
if cfg.Tracing == nil {
|
||||
cfg.Tracing = &shared.Tracing{}
|
||||
}
|
||||
if cfg.Log == nil {
|
||||
cfg.Log = &shared.Log{}
|
||||
}
|
||||
if cfg.TokenManager == nil {
|
||||
cfg.TokenManager = &shared.TokenManager{}
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureCommons copies applicable parts of the oCIS config into the commons part
|
||||
func EnsureCommons(cfg *config.Config) {
|
||||
// ensure the commons part is initialized
|
||||
if cfg.Commons == nil {
|
||||
cfg.Commons = &shared.Commons{}
|
||||
}
|
||||
|
||||
// copy config to the commons part if set
|
||||
if cfg.Log != nil {
|
||||
cfg.Commons.Log = &shared.Log{
|
||||
Level: cfg.Log.Level,
|
||||
Pretty: cfg.Log.Pretty,
|
||||
Color: cfg.Log.Color,
|
||||
File: cfg.File,
|
||||
}
|
||||
} else {
|
||||
cfg.Commons.Log = &shared.Log{}
|
||||
}
|
||||
|
||||
// copy tracing to the commons part if set
|
||||
if cfg.Tracing != nil {
|
||||
cfg.Commons.Tracing = &shared.Tracing{
|
||||
Enabled: cfg.Tracing.Enabled,
|
||||
Type: cfg.Tracing.Type,
|
||||
Endpoint: cfg.Tracing.Endpoint,
|
||||
Collector: cfg.Tracing.Collector,
|
||||
}
|
||||
} else {
|
||||
cfg.Commons.Tracing = &shared.Tracing{}
|
||||
}
|
||||
|
||||
// copy token manager to the commons part if set
|
||||
if cfg.TokenManager != nil {
|
||||
cfg.Commons.TokenManager = cfg.TokenManager
|
||||
} else {
|
||||
cfg.Commons.TokenManager = &shared.TokenManager{}
|
||||
}
|
||||
|
||||
// copy machine auth api key to the commons part if set
|
||||
if cfg.MachineAuthAPIKey != "" {
|
||||
cfg.Commons.MachineAuthAPIKey = cfg.MachineAuthAPIKey
|
||||
}
|
||||
|
||||
// copy transfer secret to the commons part if set
|
||||
if cfg.TransferSecret != "" {
|
||||
cfg.Commons.TransferSecret = cfg.TransferSecret
|
||||
}
|
||||
|
||||
// copy metadata user id to the commons part if set
|
||||
if cfg.MetadataUserID != "" {
|
||||
cfg.Commons.MetadataUserID = cfg.MetadataUserID
|
||||
}
|
||||
}
|
||||
|
||||
func Validate(cfg *config.Config) error {
|
||||
if cfg.TokenManager.JWTSecret == "" {
|
||||
return shared.MissingJWTTokenError("ocis")
|
||||
}
|
||||
|
||||
if cfg.TransferSecret == "" {
|
||||
return shared.MissingRevaTransferSecretError("ocis")
|
||||
}
|
||||
|
||||
if cfg.MachineAuthAPIKey == "" {
|
||||
return shared.MissingMachineAuthApiKeyError("ocis")
|
||||
}
|
||||
|
||||
if cfg.MetadataUserID == "" {
|
||||
return shared.MissingMetadataUserID("ocis")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package crypto_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
. "github.com/onsi/gomega"
|
||||
)
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"github.com/owncloud/ocis/ocis-pkg/crypto"
|
||||
"github.com/owncloud/ocis/ocis-pkg/log"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
cfg "github.com/owncloud/ocis/ocis-pkg/config"
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package generators
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
func GenerateRandomPassword(length int) (string, error) {
|
||||
const chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-=+!@#$%^&*."
|
||||
ret := make([]byte, length)
|
||||
for i := 0; i < length; i++ {
|
||||
num, err := rand.Int(rand.Reader, big.NewInt(int64(len(chars))))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ret[i] = chars[num.Int64()]
|
||||
}
|
||||
|
||||
return string(ret), nil
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package shared
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
|
||||
)
|
||||
|
||||
func MissingMachineAuthApiKeyError(service string) error {
|
||||
return fmt.Errorf("The Machineauth API key has not been configured for %s. "+
|
||||
"Make sure your %s config contains the proper values "+
|
||||
"(e.g. by running ocis init or setting it manually in "+
|
||||
"the config/corresponding environment variable).",
|
||||
service, defaults.BaseConfigPath())
|
||||
}
|
||||
|
||||
func MissingJWTTokenError(service string) error {
|
||||
return fmt.Errorf("jwt_secret has not been set properly in your config for %s. "+
|
||||
"Make sure your %s config contains the proper values "+
|
||||
"(e.g. by running ocis init or setting it manually in "+
|
||||
"the config/corresponding environment variable).",
|
||||
service, defaults.BaseConfigPath())
|
||||
}
|
||||
|
||||
func MissingRevaTransferSecretError(service string) error {
|
||||
return fmt.Errorf("transfer_secret has not been set properly in your config for %s. "+
|
||||
"Make sure your %s config contains the proper values "+
|
||||
"(e.g. by running ocis init or setting it manually in "+
|
||||
"the config/corresponding environment variable).",
|
||||
service, defaults.BaseConfigPath())
|
||||
}
|
||||
|
||||
func MissingLDAPBindPassword(service string) error {
|
||||
return fmt.Errorf("bind_password has not been set properly in your config for %s. "+
|
||||
"Make sure your %s config contains the proper values "+
|
||||
"(e.g. by running ocis init or setting it manually in "+
|
||||
"the config/corresponding environment variable).",
|
||||
service, defaults.BaseConfigPath())
|
||||
}
|
||||
|
||||
func MissingServiceUserPassword(service, serviceUser string) error {
|
||||
return fmt.Errorf("password of service user %s has not been set properly in your config for %s. "+
|
||||
"Make sure your %s config contains the proper values "+
|
||||
"(e.g. by running ocis init or setting it manually in "+
|
||||
"the config/corresponding environment variable).",
|
||||
serviceUser, service, defaults.BaseConfigPath())
|
||||
}
|
||||
|
||||
func MissingMetadataUserID(service string) error {
|
||||
return fmt.Errorf("The metadata user ID has not been configured for %s. "+
|
||||
"Make sure your %s config contains the proper values "+
|
||||
"(e.g. by running ocis init or setting it manually in "+
|
||||
"the config/corresponding environment variable).",
|
||||
service, defaults.BaseConfigPath())
|
||||
}
|
||||
@@ -24,10 +24,25 @@ type Tracing struct {
|
||||
Collector string `yaml:"collector" env:"OCIS_TRACING_COLLECTOR"`
|
||||
}
|
||||
|
||||
// TokenManager is the config for using the reva token manager
|
||||
type TokenManager struct {
|
||||
JWTSecret string `yaml:"jwt_secret" env:"OCIS_JWT_SECRET" desc:"The secret to mint jwt tokens."`
|
||||
}
|
||||
|
||||
// Reva defines all available REVA configuration.
|
||||
type Reva struct {
|
||||
Address string `yaml:"address" env:"REVA_GATEWAY"`
|
||||
}
|
||||
|
||||
// Commons holds configuration that are common to all extensions. Each extension can then decide whether
|
||||
// to overwrite its values.
|
||||
type Commons struct {
|
||||
Log *Log `yaml:"log"`
|
||||
Tracing *Tracing `yaml:"tracing"`
|
||||
OcisURL string `yaml:"ocis_url" env:"OCIS_URL"`
|
||||
Log *Log `yaml:"log"`
|
||||
Tracing *Tracing `yaml:"tracing"`
|
||||
OcisURL string `yaml:"ocis_url" env:"OCIS_URL"`
|
||||
TokenManager *TokenManager `yaml:"token_manager"`
|
||||
Reva *Reva `yaml:"reva"`
|
||||
MachineAuthAPIKey string `yaml:"machine_auth_api_key" env:"OCIS_MACHINE_AUTH_API_KEY"`
|
||||
TransferSecret string `yaml:"transfer_secret,omitempty" env:"REVA_TRANSFER_SECRET"`
|
||||
MetadataUserID string `yaml:"metadata_user_id" env:"METADATA_USER_ID"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user