diff --git a/src/common/config/metadata/metadatalist.go b/src/common/config/metadata/metadatalist.go index 694cb1ae1..7e0ae941f 100644 --- a/src/common/config/metadata/metadatalist.go +++ b/src/common/config/metadata/metadatalist.go @@ -151,6 +151,7 @@ var ( {Name: common.WithNotary, Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_NOTARY", DefaultValue: "false", ItemType: &BoolType{}, Editable: true}, // the unit of expiration is minute, 43200 minutes = 30 days {Name: common.RobotTokenDuration, Scope: UserScope, Group: BasicGroup, EnvKey: "ROBOT_TOKEN_DURATION", DefaultValue: "43200", ItemType: &IntType{}, Editable: true}, + {Name: common.RobotNamePrefix, Scope: UserScope, Group: BasicGroup, EnvKey: "ROBOT_NAME_PREFIX", DefaultValue: "robot$", ItemType: &StringType{}, Editable: true}, {Name: common.NotificationEnable, Scope: UserScope, Group: BasicGroup, EnvKey: "NOTIFICATION_ENABLE", DefaultValue: "true", ItemType: &BoolType{}, Editable: true}, {Name: common.QuotaPerProjectEnable, Scope: UserScope, Group: QuotaGroup, EnvKey: "QUOTA_PER_PROJECT_ENABLE", DefaultValue: "true", ItemType: &BoolType{}, Editable: true}, diff --git a/src/common/const.go b/src/common/const.go index 47b17ba8d..7181f45d1 100755 --- a/src/common/const.go +++ b/src/common/const.go @@ -136,6 +136,8 @@ const ( DefaultRegistryCtlURL = "http://registryctl:8080" // Use this prefix to distinguish harbor user, the prefix contains a special character($), so it cannot be registered as a harbor user. RobotPrefix = "robot$" + // System admin defined the robot name prefix. + RobotNamePrefix = "robot_name_prefix" // Use this prefix to index user who tries to login with web hook token. AuthProxyUserNamePrefix = "tokenreview$" CoreConfigPath = "/api/internal/configurations" diff --git a/src/common/utils/test/config.go b/src/common/utils/test/config.go index 294d119a1..42f9bd207 100644 --- a/src/common/utils/test/config.go +++ b/src/common/utils/test/config.go @@ -64,6 +64,7 @@ var defaultConfig = map[string]interface{}{ common.JobServiceURL: "http://myjob:8888/", common.ReadOnly: false, common.NotaryURL: "http://notary-server:4443", + common.RobotNamePrefix: "robot$", } // GetDefaultConfigMap returns the defailt config map for easier modification. diff --git a/src/common/utils/test/test.go b/src/common/utils/test/test.go index 950475cc0..4519235d9 100644 --- a/src/common/utils/test/test.go +++ b/src/common/utils/test/test.go @@ -128,6 +128,7 @@ func GetUnitTestConfig() map[string]interface{} { common.TokenServiceURL: "http://core:8080/service/token", common.RegistryURL: fmt.Sprintf("http://%s:5000", ipAddress), common.ReadOnly: false, + common.RobotNamePrefix: "robot$", } } diff --git a/src/core/config/config.go b/src/core/config/config.go index 6cdc8c53e..1ad9f0b20 100755 --- a/src/core/config/config.go +++ b/src/core/config/config.go @@ -487,3 +487,8 @@ func GetGCTimeWindow() int64 { } return common.DefaultGCTimeWindowHours } + +// RobotPrefix user defined robot name prefix. +func RobotPrefix() string { + return cfgMgr.Get(common.RobotNamePrefix).GetString() +} diff --git a/src/core/config/config_test.go b/src/core/config/config_test.go index 4521cdec0..e3f138cf2 100644 --- a/src/core/config/config_test.go +++ b/src/core/config/config_test.go @@ -190,6 +190,7 @@ func TestConfig(t *testing.T) { assert.True(NotificationEnable()) assert.Equal(int64(0), GetGCTimeWindow()) + assert.Equal("robot$", RobotPrefix()) }