mirror of
https://github.com/goharbor/harbor
synced 2025-04-22 00:57:38 +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:
|
description:
|
||||||
type: string
|
type: string
|
||||||
description: The description of robot account
|
description: The description of robot account
|
||||||
expiration:
|
expiresat:
|
||||||
type: integer
|
type: integer
|
||||||
description: The expiration of robot account
|
description: The expiration of robot account (in seconds)
|
||||||
project_id:
|
project_id:
|
||||||
type: integer
|
type: integer
|
||||||
description: The project id of robot account
|
description: The project id of robot account
|
||||||
|
@ -3,7 +3,7 @@ CREATE TABLE robot (
|
|||||||
name varchar(255),
|
name varchar(255),
|
||||||
description varchar(1024),
|
description varchar(1024),
|
||||||
project_id int,
|
project_id int,
|
||||||
expiration bigint,
|
expiresat bigint,
|
||||||
disabled boolean DEFAULT false NOT NULL,
|
disabled boolean DEFAULT false NOT NULL,
|
||||||
creation_time timestamp default CURRENT_TIMESTAMP,
|
creation_time timestamp default CURRENT_TIMESTAMP,
|
||||||
update_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_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},
|
{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
|
// 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"
|
DefaultRegistryCtlURL = "http://registryctl:8080"
|
||||||
DefaultClairHealthCheckServerURL = "http://clair:6061"
|
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.
|
// Use this prefix to distinguish harbor user, the prefix contains a special character($), so it cannot be registered as a harbor user.
|
||||||
RobotPrefix = "robot$"
|
RobotPrefix = "robot$"
|
||||||
CoreConfigPath = "/api/internal/configurations"
|
CoreConfigPath = "/api/internal/configurations"
|
||||||
RobotTokenExpiration = "robot_token_expiration"
|
RobotTokenDuration = "robot_token_duration"
|
||||||
)
|
)
|
||||||
|
@ -29,7 +29,7 @@ type Robot struct {
|
|||||||
Name string `orm:"column(name)" json:"name"`
|
Name string `orm:"column(name)" json:"name"`
|
||||||
Description string `orm:"column(description)" json:"description"`
|
Description string `orm:"column(description)" json:"description"`
|
||||||
ProjectID int64 `orm:"column(project_id)" json:"project_id"`
|
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"`
|
Disabled bool `orm:"column(disabled)" json:"disabled"`
|
||||||
CreationTime time.Time `orm:"column(creation_time);auto_now_add" json:"creation_time"`
|
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"`
|
UpdateTime time.Time `orm:"column(update_time);auto_now" json:"update_time"`
|
||||||
|
@ -106,9 +106,9 @@ func (r *RobotAPI) Post() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var robotReq models.RobotReq
|
var robotReq models.RobotReq
|
||||||
// Expiration in minutes
|
// Token duration in minutes
|
||||||
tokenExpiration := time.Duration(config.RobotTokenExpiration()) * time.Minute
|
tokenDuration := time.Duration(config.RobotTokenDuration()) * time.Minute
|
||||||
expiresAt := time.Now().UTC().Add(tokenExpiration).Unix()
|
expiresAt := time.Now().UTC().Add(tokenDuration).Unix()
|
||||||
r.DecodeJSONReq(&robotReq)
|
r.DecodeJSONReq(&robotReq)
|
||||||
createdName := common.RobotPrefix + robotReq.Name
|
createdName := common.RobotPrefix + robotReq.Name
|
||||||
|
|
||||||
@ -117,7 +117,7 @@ func (r *RobotAPI) Post() {
|
|||||||
Name: createdName,
|
Name: createdName,
|
||||||
Description: robotReq.Description,
|
Description: robotReq.Description,
|
||||||
ProjectID: r.project.ProjectID,
|
ProjectID: r.project.ProjectID,
|
||||||
Expiration: expiresAt,
|
ExpiresAt: expiresAt,
|
||||||
}
|
}
|
||||||
id, err := dao.AddRobot(&robot)
|
id, err := dao.AddRobot(&robot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -225,9 +225,9 @@ func TokenExpiration() (int, error) {
|
|||||||
return cfgMgr.Get(common.TokenExpiration).GetInt(), nil
|
return cfgMgr.Get(common.TokenExpiration).GetInt(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// RobotTokenExpiration returns the token expiration time of robot account (in minute)
|
// RobotTokenDuration returns the token expiration time of robot account (in minute)
|
||||||
func RobotTokenExpiration() int {
|
func RobotTokenDuration() int {
|
||||||
return cfgMgr.Get(common.RobotTokenExpiration).GetInt()
|
return cfgMgr.Get(common.RobotTokenDuration).GetInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExtEndpoint returns the external URL of Harbor: protocol://host:port
|
// 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)
|
t.Fatalf("failed to get token expiration: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tkExp := RobotTokenExpiration()
|
tkExp := RobotTokenDuration()
|
||||||
assert.Equal(tkExp, 30)
|
assert.Equal(tkExp, 43200)
|
||||||
|
|
||||||
if _, err := ExtEndpoint(); err != nil {
|
if _, err := ExtEndpoint(); err != nil {
|
||||||
t.Fatalf("failed to get domain name: %v", err)
|
t.Fatalf("failed to get domain name: %v", err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user