mirror of
https://github.com/goharbor/harbor
synced 2025-04-15 17:24:01 +00:00
Update expiration variable name to expiresat/tokenduration
Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
parent
36a778b482
commit
91aa67a541
|
@ -4734,9 +4734,9 @@ definitions:
|
|||
description:
|
||||
type: string
|
||||
description: The description of robot account
|
||||
expiration:
|
||||
expiresat:
|
||||
type: integer
|
||||
description: The expiration of robot account
|
||||
description: The expiration of robot account (in seconds)
|
||||
project_id:
|
||||
type: integer
|
||||
description: The project id of robot account
|
||||
|
|
|
@ -3,7 +3,7 @@ CREATE TABLE robot (
|
|||
name varchar(255),
|
||||
description varchar(1024),
|
||||
project_id int,
|
||||
expiration bigint,
|
||||
expiresat bigint,
|
||||
disabled boolean DEFAULT false NOT NULL,
|
||||
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||
update_time timestamp default CURRENT_TIMESTAMP,
|
||||
|
|
|
@ -131,6 +131,6 @@ var (
|
|||
{Name: "with_clair", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_CLAIR", DefaultValue: "false", ItemType: &BoolType{}, Editable: true},
|
||||
{Name: "with_notary", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_NOTARY", DefaultValue: "false", ItemType: &BoolType{}, Editable: true},
|
||||
// the unit of expiration is minute, 43200 minutes = 30 days
|
||||
{Name: "robot_token_expiration", Scope: UserScope, Group: BasicGroup, EnvKey: "ROBOT_TOKEN_EXPIRATION", DefaultValue: "43200", ItemType: &IntType{}, Editable: true},
|
||||
{Name: "robot_token_duration", Scope: UserScope, Group: BasicGroup, EnvKey: "ROBOT_TOKEN_DURATION", DefaultValue: "43200", ItemType: &IntType{}, Editable: true},
|
||||
}
|
||||
)
|
||||
|
|
|
@ -117,7 +117,7 @@ const (
|
|||
DefaultRegistryCtlURL = "http://registryctl:8080"
|
||||
DefaultClairHealthCheckServerURL = "http://clair:6061"
|
||||
// Use this prefix to distinguish harbor user, the prefix contains a special character($), so it cannot be registered as a harbor user.
|
||||
RobotPrefix = "robot$"
|
||||
CoreConfigPath = "/api/internal/configurations"
|
||||
RobotTokenExpiration = "robot_token_expiration"
|
||||
RobotPrefix = "robot$"
|
||||
CoreConfigPath = "/api/internal/configurations"
|
||||
RobotTokenDuration = "robot_token_duration"
|
||||
)
|
||||
|
|
|
@ -29,7 +29,7 @@ type Robot struct {
|
|||
Name string `orm:"column(name)" json:"name"`
|
||||
Description string `orm:"column(description)" json:"description"`
|
||||
ProjectID int64 `orm:"column(project_id)" json:"project_id"`
|
||||
Expiration int64 `orm:"column(expiration)" json:"expiration"`
|
||||
ExpiresAt int64 `orm:"column(expiresat)" json:"expiresat"`
|
||||
Disabled bool `orm:"column(disabled)" json:"disabled"`
|
||||
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
|
||||
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
|
||||
|
|
|
@ -106,9 +106,9 @@ func (r *RobotAPI) Post() {
|
|||
}
|
||||
|
||||
var robotReq models.RobotReq
|
||||
// Expiration in minutes
|
||||
tokenExpiration := time.Duration(config.RobotTokenExpiration()) * time.Minute
|
||||
expiresAt := time.Now().UTC().Add(tokenExpiration).Unix()
|
||||
// Token duration in minutes
|
||||
tokenDuration := time.Duration(config.RobotTokenDuration()) * time.Minute
|
||||
expiresAt := time.Now().UTC().Add(tokenDuration).Unix()
|
||||
r.DecodeJSONReq(&robotReq)
|
||||
createdName := common.RobotPrefix + robotReq.Name
|
||||
|
||||
|
@ -117,7 +117,7 @@ func (r *RobotAPI) Post() {
|
|||
Name: createdName,
|
||||
Description: robotReq.Description,
|
||||
ProjectID: r.project.ProjectID,
|
||||
Expiration: expiresAt,
|
||||
ExpiresAt: expiresAt,
|
||||
}
|
||||
id, err := dao.AddRobot(&robot)
|
||||
if err != nil {
|
||||
|
|
|
@ -225,9 +225,9 @@ func TokenExpiration() (int, error) {
|
|||
return cfgMgr.Get(common.TokenExpiration).GetInt(), nil
|
||||
}
|
||||
|
||||
// RobotTokenExpiration returns the token expiration time of robot account (in minute)
|
||||
func RobotTokenExpiration() int {
|
||||
return cfgMgr.Get(common.RobotTokenExpiration).GetInt()
|
||||
// RobotTokenDuration returns the token expiration time of robot account (in minute)
|
||||
func RobotTokenDuration() int {
|
||||
return cfgMgr.Get(common.RobotTokenDuration).GetInt()
|
||||
}
|
||||
|
||||
// ExtEndpoint returns the external URL of Harbor: protocol://host:port
|
||||
|
|
|
@ -97,8 +97,8 @@ func TestConfig(t *testing.T) {
|
|||
t.Fatalf("failed to get token expiration: %v", err)
|
||||
}
|
||||
|
||||
tkExp := RobotTokenExpiration()
|
||||
assert.Equal(tkExp, 30)
|
||||
tkExp := RobotTokenDuration()
|
||||
assert.Equal(tkExp, 43200)
|
||||
|
||||
if _, err := ExtEndpoint(); err != nil {
|
||||
t.Fatalf("failed to get domain name: %v", err)
|
||||
|
|
Loading…
Reference in New Issue
Block a user