Update expiration schema to bigint and default unit to minute

Signed-off-by: wang yan <wangyan@vmware.com>
This commit is contained in:
wang yan 2019-02-22 18:20:03 +08:00
parent 47a09b5891
commit 36a778b482
4 changed files with 6 additions and 5 deletions

View File

@ -3,7 +3,7 @@ CREATE TABLE robot (
name varchar(255),
description varchar(1024),
project_id int,
expiration int,
expiration bigint,
disabled boolean DEFAULT false NOT NULL,
creation_time timestamp default CURRENT_TIMESTAMP,
update_time timestamp default CURRENT_TIMESTAMP,

View File

@ -130,6 +130,7 @@ var (
{Name: "with_chartmuseum", Scope: SystemScope, Group: BasicGroup, EnvKey: "WITH_CHARTMUSEUM", 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: "robot_token_expiration", Scope: UserScope, Group: BasicGroup, EnvKey: "ROBOT_TOKEN_EXPIRATION", DefaultValue: "30", ItemType: &IntType{}, 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},
}
)

View File

@ -106,8 +106,8 @@ func (r *RobotAPI) Post() {
}
var robotReq models.RobotReq
// Expiration in days
tokenExpiration := time.Duration(config.RobotTokenExpiration()) * 24 * time.Hour
// Expiration in minutes
tokenExpiration := time.Duration(config.RobotTokenExpiration()) * time.Minute
expiresAt := time.Now().UTC().Add(tokenExpiration).Unix()
r.DecodeJSONReq(&robotReq)
createdName := common.RobotPrefix + robotReq.Name

View File

@ -225,7 +225,7 @@ func TokenExpiration() (int, error) {
return cfgMgr.Get(common.TokenExpiration).GetInt(), nil
}
// RobotTokenExpiration returns the token expiration time of robot account (in day)
// RobotTokenExpiration returns the token expiration time of robot account (in minute)
func RobotTokenExpiration() int {
return cfgMgr.Get(common.RobotTokenExpiration).GetInt()
}