Adapt naming in ocis init

This commit is contained in:
André Duffeck
2025-01-15 16:11:35 +01:00
parent d07cc2fdcb
commit 44bd472588
4 changed files with 31 additions and 31 deletions

View File

@@ -7,7 +7,7 @@ import (
"os"
"strings"
ocisinit "github.com/opencloud-eu/opencloud/opencloud/pkg/init"
ocinit "github.com/opencloud-eu/opencloud/opencloud/pkg/init"
"github.com/opencloud-eu/opencloud/opencloud/pkg/register"
"github.com/opencloud-eu/opencloud/pkg/config"
"github.com/opencloud-eu/opencloud/pkg/config/defaults"
@@ -18,13 +18,13 @@ import (
func InitCommand(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "init",
Usage: "initialise an ocis config",
Usage: "initialise an opencloud config",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "insecure",
EnvVars: []string{"OC_INSECURE"},
Value: "ask",
Usage: "Allow insecure oCIS config",
Usage: "Allow insecure opencloud config",
},
&cli.BoolFlag{
Name: "diff",
@@ -42,7 +42,7 @@ func InitCommand(cfg *config.Config) *cli.Command {
&cli.StringFlag{
Name: "config-path",
Value: defaults.BaseConfigPath(),
Usage: "Config path for the ocis runtime",
Usage: "Config path for the opencloud runtime",
EnvVars: []string{"OC_CONFIG_DIR", "OC_BASE_DATA_PATH"},
},
&cli.StringFlag{
@@ -63,7 +63,7 @@ func InitCommand(cfg *config.Config) *cli.Command {
} else if insecureFlag == strings.ToLower("true") || insecureFlag == strings.ToLower("yes") || insecureFlag == strings.ToLower("y") {
insecure = true
}
err := ocisinit.CreateConfig(insecure, c.Bool("force-overwrite"), c.Bool("diff"), c.String("config-path"), c.String("admin-password"))
err := ocinit.CreateConfig(insecure, c.Bool("force-overwrite"), c.Bool("diff"), c.String("config-path"), c.String("admin-password"))
if err != nil {
log.Fatalf("Could not create config: %s", err)
}

View File

@@ -26,7 +26,7 @@ func configExists(configPath string) bool {
return false
}
func backupOcisConfigFile(configPath string) (string, error) {
func backupOpenCloudConfigFile(configPath string) (string, error) {
sourceConfig := path.Join(configPath, configFilename)
targetBackupConfig := path.Join(configPath, configFilename+"."+time.Now().Format("2006-01-02-15-04-05")+".backup")
source, err := os.Open(sourceConfig)
@@ -46,16 +46,16 @@ func backupOcisConfigFile(configPath string) (string, error) {
return targetBackupConfig, nil
}
// printBanner prints the generated OCIS config banner.
func printBanner(targetPath, ocisAdminServicePassword, targetBackupConfig string) {
// printBanner prints the generated opencloud config banner.
func printBanner(targetPath, ocAdminServicePassword, targetBackupConfig string) {
fmt.Printf(
"\n=========================================\n"+
" generated OCIS Config\n"+
" generated OpenCloud Config\n"+
"=========================================\n"+
" configpath : %s\n"+
" user : admin\n"+
" password : %s\n\n",
targetPath, ocisAdminServicePassword)
targetPath, ocAdminServicePassword)
if targetBackupConfig != "" {
fmt.Printf("\n=========================================\n"+
"An older config file has been backuped to\n %s\n\n",
@@ -64,13 +64,13 @@ func printBanner(targetPath, ocisAdminServicePassword, targetBackupConfig string
}
// writeConfig writes the config to the target path and prints a banner
func writeConfig(configPath, ocisAdminServicePassword, targetBackupConfig string, yamlOutput []byte) error {
func writeConfig(configPath, ocAdminServicePassword, targetBackupConfig string, yamlOutput []byte) error {
targetPath := path.Join(configPath, configFilename)
err := os.WriteFile(targetPath, yamlOutput, 0600)
if err != nil {
return err
}
printBanner(targetPath, ocisAdminServicePassword, targetBackupConfig)
printBanner(targetPath, ocAdminServicePassword, targetBackupConfig)
return nil
}
@@ -98,7 +98,7 @@ func writePatch(configPath string, yamlOutput []byte) error {
if err != nil {
return err
}
patchPath := path.Join(configPath, "ocis.config.patch")
patchPath := path.Join(configPath, "opencloud.config.patch")
err = os.WriteFile(patchPath, stdout, 0600)
if err != nil {
return err

View File

@@ -41,7 +41,7 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
}
targetBackupConfig := ""
if err != nil {
targetBackupConfig, err = backupOcisConfigFile(configPath)
targetBackupConfig, err = backupOpenCloudConfigFile(configPath)
if err != nil {
return err
}
@@ -52,7 +52,7 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
}
// Load old config
var oldCfg OcisConfig
var oldCfg OpenCloudConfig
if diff {
fp, err := os.ReadFile(path.Join(configPath, configFilename))
if err != nil {
@@ -65,10 +65,10 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
}
var (
systemUserID, adminUserID, graphApplicationID, storageUsersMountID, serviceAccountID string
idmServicePassword, idpServicePassword, ocisAdminServicePassword, revaServicePassword string
tokenManagerJwtSecret, collaborationWOPISecret, machineAuthAPIKey, systemUserAPIKey string
revaTransferSecret, thumbnailsTransferSecret, serviceAccountSecret string
systemUserID, adminUserID, graphApplicationID, storageUsersMountID, serviceAccountID string
idmServicePassword, idpServicePassword, ocAdminServicePassword, revaServicePassword string
tokenManagerJwtSecret, collaborationWOPISecret, machineAuthAPIKey, systemUserAPIKey string
revaTransferSecret, thumbnailsTransferSecret, serviceAccountSecret string
)
if diff {
@@ -80,7 +80,7 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
idmServicePassword = oldCfg.Idm.ServiceUserPasswords.IdmPassword
idpServicePassword = oldCfg.Idm.ServiceUserPasswords.IdpPassword
ocisAdminServicePassword = oldCfg.Idm.ServiceUserPasswords.AdminPassword
ocAdminServicePassword = oldCfg.Idm.ServiceUserPasswords.AdminPassword
revaServicePassword = oldCfg.Idm.ServiceUserPasswords.RevaPassword
tokenManagerJwtSecret = oldCfg.TokenManager.JWTSecret
collaborationWOPISecret = oldCfg.Collaboration.WopiApp.Secret
@@ -110,11 +110,11 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
if err != nil {
return fmt.Errorf("could not generate random password for idp: %s", err)
}
ocisAdminServicePassword = adminPassword
if ocisAdminServicePassword == "" {
ocisAdminServicePassword, err = generators.GenerateRandomPassword(passwordLength)
ocAdminServicePassword = adminPassword
if ocAdminServicePassword == "" {
ocAdminServicePassword, 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 opencloud admin: %s", err)
}
}
@@ -157,7 +157,7 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
ServiceAccountSecret: serviceAccountSecret,
}
cfg := OcisConfig{
cfg := OpenCloudConfig{
TokenManager: TokenManager{
JWTSecret: tokenManagerJwtSecret,
},
@@ -168,7 +168,7 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
AdminUserID: adminUserID,
Idm: IdmService{
ServiceUserPasswords: ServiceUserPasswordsSettings{
AdminPassword: ocisAdminServicePassword,
AdminPassword: ocAdminServicePassword,
IdpPassword: idpServicePassword,
RevaPassword: revaServicePassword,
IdmPassword: idmServicePassword,
@@ -296,5 +296,5 @@ func CreateConfig(insecure, forceOverwrite, diff bool, configPath, adminPassword
if diff {
return writePatch(configPath, yamlOutput)
}
return writeConfig(configPath, ocisAdminServicePassword, targetBackupConfig, yamlOutput)
return writeConfig(configPath, ocAdminServicePassword, targetBackupConfig, yamlOutput)
}

View File

@@ -1,20 +1,20 @@
package init
// TODO: use the oCIS config struct instead of this custom struct
// TODO: use the opencloud config struct instead of this custom struct
// We can't use it right now, because it would need "omitempty" on
// all elements, in order to produce a slim config file with `opencloud init`.
// We can't just add these "omitempty" tags, since we want to generate
// full example configuration files with that struct, too.
// Proposed solution to get rid of this temporary solution:
// - use the oCIS config struct
// - use the opencloud config struct
// - set the needed values like below
// - marshal it to yaml
// - unmarshal it into yaml.Node
// - recurse through the nodes and delete empty / default ones
// - marshal it to yaml
// OcisConfig is the configuration for the OpenCloud services
type OcisConfig struct {
// OpenCloudConfig is the configuration for the OpenCloud services
type OpenCloudConfig struct {
TokenManager TokenManager `yaml:"token_manager"`
MachineAuthAPIKey string `yaml:"machine_auth_api_key"`
SystemUserAPIKey string `yaml:"system_user_api_key"`