add robot name prefix

The system admin can set the prefix in configuration UI.

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
Wang Yan 2020-11-02 22:09:06 -08:00 committed by wy65701436
parent dd3ffd4147
commit 5a22019e3d
6 changed files with 11 additions and 0 deletions

View File

@ -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},

View File

@ -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"

View File

@ -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.

View File

@ -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$",
}
}

View File

@ -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()
}

View File

@ -190,6 +190,7 @@ func TestConfig(t *testing.T) {
assert.True(NotificationEnable())
assert.Equal(int64(0), GetGCTimeWindow())
assert.Equal("robot$", RobotPrefix())
}