From 2559cefb64aa85be511aa4681737e99af64cbfdf Mon Sep 17 00:00:00 2001
From: jkoberg <jkoberg@owncloud.com>
Date: Wed, 4 May 2022 10:55:43 +0200
Subject: [PATCH 1/3] replace MetadataUserID with SystemUserID

Signed-off-by: jkoberg <jkoberg@owncloud.com>
---
 extensions/settings/pkg/config/defaults/defaultconfig.go  | 4 ++--
 extensions/sharing/pkg/config/defaults/defaultconfig.go   | 8 ++++----
 extensions/sharing/pkg/config/parser/parse.go             | 4 ++--
 extensions/storage-metadata/pkg/config/config.go          | 2 +-
 .../storage-metadata/pkg/config/defaults/defaultconfig.go | 4 ++--
 extensions/storage-metadata/pkg/config/parser/parse.go    | 4 ++--
 extensions/storage-metadata/pkg/revaconfig/config.go      | 2 +-
 ocis-pkg/config/config.go                                 | 2 +-
 ocis-pkg/config/parser/parse.go                           | 8 ++++----
 ocis-pkg/shared/errors.go                                 | 2 +-
 ocis-pkg/shared/shared_types.go                           | 2 +-
 ocis/pkg/init/init.go                                     | 6 +++---
 12 files changed, 24 insertions(+), 24 deletions(-)

diff --git a/extensions/settings/pkg/config/defaults/defaultconfig.go b/extensions/settings/pkg/config/defaults/defaultconfig.go
index 5e87d0702bc..6fee017caaa 100644
--- a/extensions/settings/pkg/config/defaults/defaultconfig.go
+++ b/extensions/settings/pkg/config/defaults/defaultconfig.go
@@ -93,8 +93,8 @@ func EnsureDefaults(cfg *config.Config) {
 		cfg.Metadata.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
 	}
 
-	if cfg.Metadata.ServiceUserID == "" && cfg.Commons != nil && cfg.Commons.MetadataUserID != "" {
-		cfg.Metadata.ServiceUserID = cfg.Commons.MetadataUserID
+	if cfg.Metadata.ServiceUserID == "" && cfg.Commons != nil && cfg.Commons.SystemUserID != "" {
+		cfg.Metadata.ServiceUserID = cfg.Commons.SystemUserID
 	}
 }
 
diff --git a/extensions/sharing/pkg/config/defaults/defaultconfig.go b/extensions/sharing/pkg/config/defaults/defaultconfig.go
index d4538c42047..518c0ae58ea 100644
--- a/extensions/sharing/pkg/config/defaults/defaultconfig.go
+++ b/extensions/sharing/pkg/config/defaults/defaultconfig.go
@@ -104,16 +104,16 @@ func EnsureDefaults(cfg *config.Config) {
 		cfg.UserSharingDrivers.CS3.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
 	}
 
-	if cfg.UserSharingDrivers.CS3.ServiceUserID == "" && cfg.Commons != nil && cfg.Commons.MetadataUserID != "" {
-		cfg.UserSharingDrivers.CS3.ServiceUserID = cfg.Commons.MetadataUserID
+	if cfg.UserSharingDrivers.CS3.ServiceUserID == "" && cfg.Commons != nil && cfg.Commons.SystemUserID != "" {
+		cfg.UserSharingDrivers.CS3.ServiceUserID = cfg.Commons.SystemUserID
 	}
 
 	if cfg.PublicSharingDrivers.CS3.MachineAuthAPIKey == "" && cfg.Commons != nil && cfg.Commons.MachineAuthAPIKey != "" {
 		cfg.PublicSharingDrivers.CS3.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
 	}
 
-	if cfg.PublicSharingDrivers.CS3.ServiceUserID == "" && cfg.Commons != nil && cfg.Commons.MetadataUserID != "" {
-		cfg.PublicSharingDrivers.CS3.ServiceUserID = cfg.Commons.MetadataUserID
+	if cfg.PublicSharingDrivers.CS3.ServiceUserID == "" && cfg.Commons != nil && cfg.Commons.SystemUserID != "" {
+		cfg.PublicSharingDrivers.CS3.ServiceUserID = cfg.Commons.SystemUserID
 	}
 }
 
diff --git a/extensions/sharing/pkg/config/parser/parse.go b/extensions/sharing/pkg/config/parser/parse.go
index afc4d88b8ec..df63239c292 100644
--- a/extensions/sharing/pkg/config/parser/parse.go
+++ b/extensions/sharing/pkg/config/parser/parse.go
@@ -43,7 +43,7 @@ func Validate(cfg *config.Config) error {
 	}
 
 	if cfg.PublicSharingDriver == "cs3" && cfg.PublicSharingDrivers.CS3.ServiceUserID == "" {
-		return shared.MissingMetadataUserID(cfg.Service.Name)
+		return shared.MissingSystemUserID(cfg.Service.Name)
 	}
 
 	if cfg.UserSharingDriver == "cs3" && cfg.UserSharingDrivers.CS3.MachineAuthAPIKey == "" {
@@ -51,7 +51,7 @@ func Validate(cfg *config.Config) error {
 	}
 
 	if cfg.UserSharingDriver == "cs3" && cfg.UserSharingDrivers.CS3.ServiceUserID == "" {
-		return shared.MissingMetadataUserID(cfg.Service.Name)
+		return shared.MissingSystemUserID(cfg.Service.Name)
 	}
 
 	return nil
diff --git a/extensions/storage-metadata/pkg/config/config.go b/extensions/storage-metadata/pkg/config/config.go
index b6a285c41f2..3d60a42c489 100644
--- a/extensions/storage-metadata/pkg/config/config.go
+++ b/extensions/storage-metadata/pkg/config/config.go
@@ -19,7 +19,7 @@ type Config struct {
 	TokenManager      *TokenManager `yaml:"token_manager"`
 	Reva              *Reva         `yaml:"reva"`
 	MachineAuthAPIKey string        `yaml:"machine_auth_api_key" env:"STORAGE_METADATA_MACHINE_AUTH_API_KEY"`
-	MetadataUserID    string        `yaml:"metadata_user_id"`
+	SystemUserID      string        `yaml:"system_user_id"`
 
 	SkipUserGroupsInToken bool `yaml:"skip_user_groups_in_token" env:"STORAGE_METADATA_SKIP_USER_GROUPS_IN_TOKEN"`
 
diff --git a/extensions/storage-metadata/pkg/config/defaults/defaultconfig.go b/extensions/storage-metadata/pkg/config/defaults/defaultconfig.go
index 0b9c1d2a509..799c9342688 100644
--- a/extensions/storage-metadata/pkg/config/defaults/defaultconfig.go
+++ b/extensions/storage-metadata/pkg/config/defaults/defaultconfig.go
@@ -93,8 +93,8 @@ func EnsureDefaults(cfg *config.Config) {
 		cfg.MachineAuthAPIKey = cfg.Commons.MachineAuthAPIKey
 	}
 
-	if cfg.MetadataUserID == "" && cfg.Commons != nil && cfg.Commons.MetadataUserID != "" {
-		cfg.MetadataUserID = cfg.Commons.MetadataUserID
+	if cfg.SystemUserID == "" && cfg.Commons != nil && cfg.Commons.SystemUserID != "" {
+		cfg.SystemUserID = cfg.Commons.SystemUserID
 	}
 
 }
diff --git a/extensions/storage-metadata/pkg/config/parser/parse.go b/extensions/storage-metadata/pkg/config/parser/parse.go
index 413bbd52c55..0e1ec683ff4 100644
--- a/extensions/storage-metadata/pkg/config/parser/parse.go
+++ b/extensions/storage-metadata/pkg/config/parser/parse.go
@@ -42,8 +42,8 @@ func Validate(cfg *config.Config) error {
 		return shared.MissingMachineAuthApiKeyError(cfg.Service.Name)
 	}
 
-	if cfg.MetadataUserID == "" {
-		return shared.MissingMetadataUserID(cfg.Service.Name)
+	if cfg.SystemUserID == "" {
+		return shared.MissingSystemUserID(cfg.Service.Name)
 	}
 	return nil
 }
diff --git a/extensions/storage-metadata/pkg/revaconfig/config.go b/extensions/storage-metadata/pkg/revaconfig/config.go
index 70b5056dbc9..3d745a86f46 100644
--- a/extensions/storage-metadata/pkg/revaconfig/config.go
+++ b/extensions/storage-metadata/pkg/revaconfig/config.go
@@ -42,7 +42,7 @@ func StorageMetadataFromStruct(cfg *config.Config) map[string]interface{} {
 							"users": map[string]interface{}{
 								"serviceuser": map[string]interface{}{
 									"id": map[string]interface{}{
-										"opaqueId": cfg.MetadataUserID,
+										"opaqueId": cfg.SystemUserID,
 										"idp":      "internal",
 										"type":     userpb.UserType_USER_TYPE_PRIMARY,
 									},
diff --git a/ocis-pkg/config/config.go b/ocis-pkg/config/config.go
index 3ace931c413..73e93ee4d89 100644
--- a/ocis-pkg/config/config.go
+++ b/ocis-pkg/config/config.go
@@ -69,7 +69,7 @@ type Config struct {
 	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" env:"METADATA_USER_ID"`
+	SystemUserID      string               `yaml:"system_user_id" env:"OCIS_SYSTEM_USER_ID"`
 	Runtime           Runtime              `yaml:"runtime"`
 
 	Accounts          *accounts.Config        `yaml:"accounts"`
diff --git a/ocis-pkg/config/parser/parse.go b/ocis-pkg/config/parser/parse.go
index cd5f8ab32b8..9df81ab3890 100644
--- a/ocis-pkg/config/parser/parse.go
+++ b/ocis-pkg/config/parser/parse.go
@@ -95,8 +95,8 @@ func EnsureCommons(cfg *config.Config) {
 	}
 
 	// copy metadata user id to the commons part if set
-	if cfg.MetadataUserID != "" {
-		cfg.Commons.MetadataUserID = cfg.MetadataUserID
+	if cfg.SystemUserID != "" {
+		cfg.Commons.SystemUserID = cfg.SystemUserID
 	}
 }
 
@@ -113,8 +113,8 @@ func Validate(cfg *config.Config) error {
 		return shared.MissingMachineAuthApiKeyError("ocis")
 	}
 
-	if cfg.MetadataUserID == "" {
-		return shared.MissingMetadataUserID("ocis")
+	if cfg.SystemUserID == "" {
+		return shared.MissingSystemUserID("ocis")
 	}
 
 	return nil
diff --git a/ocis-pkg/shared/errors.go b/ocis-pkg/shared/errors.go
index de1ed5a8256..c0815c35cc4 100644
--- a/ocis-pkg/shared/errors.go
+++ b/ocis-pkg/shared/errors.go
@@ -46,7 +46,7 @@ func MissingServiceUserPassword(service, serviceUser string) error {
 		serviceUser, service, defaults.BaseConfigPath())
 }
 
-func MissingMetadataUserID(service string) error {
+func MissingSystemUserID(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 "+
diff --git a/ocis-pkg/shared/shared_types.go b/ocis-pkg/shared/shared_types.go
index 3497bed6114..a92f0f4c9af 100644
--- a/ocis-pkg/shared/shared_types.go
+++ b/ocis-pkg/shared/shared_types.go
@@ -44,5 +44,5 @@ type Commons struct {
 	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"`
+	SystemUserID      string        `yaml:"system_user_id" env:"OCIS_SYSTEM_USER_ID"`
 }
diff --git a/ocis/pkg/init/init.go b/ocis/pkg/init/init.go
index 3fc566f0e5f..ca8501d8181 100644
--- a/ocis/pkg/init/init.go
+++ b/ocis/pkg/init/init.go
@@ -99,7 +99,7 @@ type OcisConfig struct {
 	TokenManager      TokenManager `yaml:"token_manager"`
 	MachineAuthApiKey string       `yaml:"machine_auth_api_key"`
 	TransferSecret    string       `yaml:"transfer_secret"`
-	MetadataUserID    string       `yaml:"metadata_user_id"`
+	SystemUserID      string       `yaml:"system_user_id"`
 	Graph             GraphExtension
 	Idp               LdapBasedExtension
 	Idm               IdmExtension
@@ -161,7 +161,7 @@ func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword strin
 		return err
 	}
 
-	metadataUserID := uuid.Must(uuid.NewV4()).String()
+	systemUserID := uuid.Must(uuid.NewV4()).String()
 
 	idmServicePassword, err := generators.GenerateRandomPassword(passwordLength)
 	if err != nil {
@@ -202,7 +202,7 @@ func CreateConfig(insecure, forceOverwrite bool, configPath, adminPassword strin
 		},
 		MachineAuthApiKey: machineAuthApiKey,
 		TransferSecret:    revaTransferSecret,
-		MetadataUserID:    metadataUserID,
+		SystemUserID:      systemUserID,
 		Idm: IdmExtension{
 			ServiceUserPasswords: ServiceUserPasswordsSettings{
 				AdminPassword: ocisAdminServicePassword,

From 4ddbbdc7161533ae264842068b3947028879e483 Mon Sep 17 00:00:00 2001
From: jkoberg <jkoberg@owncloud.com>
Date: Wed, 4 May 2022 10:59:56 +0200
Subject: [PATCH 2/3] the missing change

Signed-off-by: jkoberg <jkoberg@owncloud.com>
---
 extensions/storage-system/pkg/config/config.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/extensions/storage-system/pkg/config/config.go b/extensions/storage-system/pkg/config/config.go
index 45ad647aaea..7939194666a 100644
--- a/extensions/storage-system/pkg/config/config.go
+++ b/extensions/storage-system/pkg/config/config.go
@@ -19,7 +19,7 @@ type Config struct {
 	TokenManager      *TokenManager `yaml:"token_manager"`
 	Reva              *Reva         `yaml:"reva"`
 	MachineAuthAPIKey string        `yaml:"machine_auth_api_key" env:"STORAGE_SYSTEM_MACHINE_AUTH_API_KEY"`
-	MetadataUserID    string        `yaml:"metadata_user_id"`
+	SystemUserID      string        `yaml:"system_user_id"`
 
 	SkipUserGroupsInToken bool `yaml:"skip_user_groups_in_token" env:"STORAGE_SYSTEM_SKIP_USER_GROUPS_IN_TOKEN"`
 

From 8ef7b82c78d7751bdec7608ed6956c6f735a7e03 Mon Sep 17 00:00:00 2001
From: jkoberg <jkoberg@owncloud.com>
Date: Wed, 4 May 2022 11:02:48 +0200
Subject: [PATCH 3/3] changelog

Signed-off-by: jkoberg <jkoberg@owncloud.com>
---
 changelog/unreleased/metadatauserid-systemuserid.md | 5 +++++
 1 file changed, 5 insertions(+)
 create mode 100644 changelog/unreleased/metadatauserid-systemuserid.md

diff --git a/changelog/unreleased/metadatauserid-systemuserid.md b/changelog/unreleased/metadatauserid-systemuserid.md
new file mode 100644
index 00000000000..aa1ef3c0de9
--- /dev/null
+++ b/changelog/unreleased/metadatauserid-systemuserid.md
@@ -0,0 +1,5 @@
+Change: rename MetadataUserID
+
+MetadataUserID is renamed to SystemUserID including yaml tags and env vars
+
+https://github.com/owncloud/ocis/pull/3671