diff --git a/make/migrations/postgresql/0004_add_robot_account.up.sql b/make/migrations/postgresql/0004_add_robot_account.up.sql index 4c2579a3d..200268bae 100644 --- a/make/migrations/postgresql/0004_add_robot_account.up.sql +++ b/make/migrations/postgresql/0004_add_robot_account.up.sql @@ -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, diff --git a/src/common/config/metadata/metadatalist.go b/src/common/config/metadata/metadatalist.go index 7e253f50d..f2034d4bf 100644 --- a/src/common/config/metadata/metadatalist.go +++ b/src/common/config/metadata/metadatalist.go @@ -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}, } ) diff --git a/src/core/api/robot.go b/src/core/api/robot.go index 2cf5f28e0..066c928be 100644 --- a/src/core/api/robot.go +++ b/src/core/api/robot.go @@ -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 diff --git a/src/core/config/config.go b/src/core/config/config.go index e693d06c1..9966f7cc9 100644 --- a/src/core/config/config.go +++ b/src/core/config/config.go @@ -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() }