load reva gateway and token manager from common config

This commit is contained in:
Willy Kloucek
2022-04-27 13:58:59 +02:00
parent 48a6978e24
commit 9095b11d6c
86 changed files with 1209 additions and 250 deletions
+40 -58
View File
@@ -10,39 +10,22 @@ import (
"strings"
"github.com/owncloud/ocis/ocis-pkg/config"
"github.com/owncloud/ocis/ocis-pkg/config/defaults"
"github.com/owncloud/ocis/ocis-pkg/generators"
"github.com/owncloud/ocis/ocis-pkg/shared"
"github.com/owncloud/ocis/ocis/pkg/register"
cli "github.com/urfave/cli/v2"
"gopkg.in/yaml.v3"
appprovider "github.com/owncloud/ocis/extensions/appprovider/pkg/config"
authbasic "github.com/owncloud/ocis/extensions/auth-basic/pkg/config"
authbearer "github.com/owncloud/ocis/extensions/auth-bearer/pkg/config"
authmachine "github.com/owncloud/ocis/extensions/auth-machine/pkg/config"
gateway "github.com/owncloud/ocis/extensions/gateway/pkg/config"
group "github.com/owncloud/ocis/extensions/group/pkg/config"
idm "github.com/owncloud/ocis/extensions/idm/pkg/config"
ocdav "github.com/owncloud/ocis/extensions/ocdav/pkg/config"
proxy "github.com/owncloud/ocis/extensions/proxy/pkg/config"
sharing "github.com/owncloud/ocis/extensions/sharing/pkg/config"
storagemetadata "github.com/owncloud/ocis/extensions/storage-metadata/pkg/config"
storagepublic "github.com/owncloud/ocis/extensions/storage-publiclink/pkg/config"
storageshares "github.com/owncloud/ocis/extensions/storage-shares/pkg/config"
storageusers "github.com/owncloud/ocis/extensions/storage-users/pkg/config"
user "github.com/owncloud/ocis/extensions/user/pkg/config"
)
const configFilename string = "ocis.yaml"
const configFilename string = "ocis.yaml" // TODO: use also a constant for reading this file
const passwordLength int = 32
// InitCommand is the entrypoint for the init command
func InitCommand(cfg *config.Config) *cli.Command {
// TODO: remove homedir get
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatalf("could not get homedir")
}
return &cli.Command{
Name: "init",
Usage: "initialise an ocis config",
@@ -59,11 +42,9 @@ func InitCommand(cfg *config.Config) *cli.Command {
Value: false,
},
&cli.StringFlag{
Name: "config-path",
//Value: cfg.ConfigPath, // TODO: as soon as PR 3480 is merged, remove quotes
Value: path.Join(homeDir, ".ocis/config"), // TODO: this is temporary for experimenting, line above is relevant
Name: "config-path",
Value: defaults.BaseConfigPath(),
Usage: "config path for the ocis runtime",
// Destination: &cfg.ConfigFile, // TODO: same as above
},
},
Action: func(c *cli.Context) error {
@@ -93,7 +74,7 @@ func init() {
func checkConfigPath(configPath string) error {
targetPath := path.Join(configPath, configFilename)
if _, err := os.Stat(targetPath); err == nil {
return fmt.Errorf("Config in %s already exists", targetPath)
return fmt.Errorf("config in %s already exists", targetPath)
}
return nil
}
@@ -122,19 +103,19 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
//OCS: &ocs.Config{},
//Settings: &settings.Config{},
// TODO: fix storage
AuthBasic: &authbasic.Config{},
AuthBearer: &authbearer.Config{},
AppProvider: &appprovider.Config{},
AuthMachine: &authmachine.Config{},
Gateway: &gateway.Config{},
Group: &group.Config{},
Sharing: &sharing.Config{},
StorageMetadata: &storagemetadata.Config{},
StorageUsers: &storageusers.Config{},
StorageShares: &storageshares.Config{},
StoragePublicLink: &storagepublic.Config{},
User: &user.Config{},
OCDav: &ocdav.Config{},
//AuthBasic: &authbasic.Config{},
//AuthBearer: &authbearer.Config{},
//AppProvider: &appprovider.Config{},
//AuthMachine: &authmachine.Config{},
//Gateway: &gateway.Config{},
//Group: &group.Config{},
//Sharing: &sharing.Config{},
//StorageMetadata: &storagemetadata.Config{},
//StorageUsers: &storageusers.Config{},
//StorageShares: &storageshares.Config{},
//StoragePublicLink: &storagepublic.Config{},
//User: &user.Config{},
//OCDav: &ocdav.Config{},
//Thumbnails: &thumbnails.Config{},
//Web: &web.Config{},
//WebDAV: &webdav.Config{},
@@ -147,31 +128,31 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
idmServicePassword, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for idm: %s", err)
return fmt.Errorf("could not generate random password for idm: %s", err)
}
idpServicePassword, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for idp: %s", err)
return fmt.Errorf("could not generate random password for idp: %s", err)
}
ocisAdminServicePassword, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for ocis admin: %s", err)
return fmt.Errorf("could not generate random password for ocis admin: %s", err)
}
revaServicePassword, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for reva: %s", err)
return fmt.Errorf("could not generate random password for reva: %s", err)
}
tokenManagerJwtSecret, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for tokenmanager: %s", err)
return fmt.Errorf("could not generate random password for tokenmanager: %s", err)
}
machineAuthApiKey, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for machineauthsecret: %s", err)
return fmt.Errorf("could not generate random password for machineauthsecret: %s", err)
}
revaTransferTokenSecret, err := generators.GenerateRandomPassword(passwordLength)
if err != nil {
return fmt.Errorf("Could not generate random password for machineauthsecret: %s", err)
return fmt.Errorf("could not generate random password for machineauthsecret: %s", err)
}
// TODO: IDP config is missing (LDAP + GROUP provider)
@@ -199,26 +180,27 @@ func createConfig(insecure, forceOverwrite bool, configPath string) error {
//cfg.Settings.TokenManager.JWTSecret = tokenManagerJwtSecret
//TODO: move all jwt secrets to shared.common
cfg.AppProvider.JWTSecret = tokenManagerJwtSecret
cfg.AuthBasic.JWTSecret = tokenManagerJwtSecret
cfg.AuthBearer.JWTSecret = tokenManagerJwtSecret
cfg.AuthMachine.JWTSecret = tokenManagerJwtSecret
cfg.Gateway.JWTSecret = tokenManagerJwtSecret
//cfg.AppProvider.JWTSecret = tokenManagerJwtSecret
//cfg.AuthBasic.JWTSecret = tokenManagerJwtSecret
//cfg.AuthBearer.JWTSecret = tokenManagerJwtSecret
//cfg.AuthMachine.JWTSecret = tokenManagerJwtSecret
//cfg.Gateway.JWTSecret = tokenManagerJwtSecret
//cfg.Group.JWTSecret = tokenManagerJwtSecret
//cfg.Sharing.JWTSecret = tokenManagerJwtSecret
//cfg.StorageMetadata.JWTSecret = tokenManagerJwtSecret
//cfg.StoragePublicLink.JWTSecret = tokenManagerJwtSecret
//cfg.StorageShares.JWTSecret = tokenManagerJwtSecret
//cfg.StorageUsers.JWTSecret = tokenManagerJwtSecret
//cfg.User.JWTSecret = tokenManagerJwtSecret
//cfg.OCDav.JWTSecret = tokenManagerJwtSecret
//TODO: following line is defunc, figure out why
//cfg.Gateway.MachineAuthAPIKey = machineAuthApiKey
cfg.Group.JWTSecret = tokenManagerJwtSecret
cfg.Sharing.JWTSecret = tokenManagerJwtSecret
cfg.StorageMetadata.JWTSecret = tokenManagerJwtSecret
cfg.StoragePublicLink.JWTSecret = tokenManagerJwtSecret
cfg.StorageShares.JWTSecret = tokenManagerJwtSecret
cfg.StorageUsers.JWTSecret = tokenManagerJwtSecret
cfg.User.JWTSecret = tokenManagerJwtSecret
cfg.OCDav.JWTSecret = tokenManagerJwtSecret
//cfg.Thumbnails.Thumbnail.TransferSecret = revaTransferTokenSecret
yamlOutput, err := yaml.Marshal(cfg)
if err != nil {
return fmt.Errorf("Could not marshall config into yaml: %s", err)
return fmt.Errorf("could not marshall config into yaml: %s", err)
}
targetPath := path.Join(configPath, configFilename)
err = ioutil.WriteFile(targetPath, yamlOutput, 0600)