Skip to content

Commit 560b162

Browse files
cyberm8Cyberm8
authored andcommitted
feat: add token_expiration option for config system
Signed-off-by: Cyberm8 <cyberm8>
1 parent f00c48f commit 560b162

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

client/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ func GetConfigSystem(d *schema.ResourceData) models.ConfigBodySystemPost {
3232
ReadOnly: d.Get("read_only").(bool),
3333
ScannerSkipUpdatePulltime: d.Get("scanner_skip_update_pulltime").(bool),
3434
RobotTokenDuration: d.Get("robot_token_expiration").(int),
35+
TokenExpiration: d.Get("token_expiration").(int),
3536
SessionTimeout: d.Get("session_timeout").(int),
3637
QuotaPerProjectEnable: true,
3738
RobotNamePrefix: d.Get("robot_name_prefix").(string),

docs/resources/config_system.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ description: |-
1616
resource "harbor_config_system" "main" {
1717
project_creation_restriction = "adminonly"
1818
session_timeout = 60
19+
token_expiration = 30
1920
robot_token_expiration = 30
2021
robot_name_prefix = "harbor@"
2122
storage_per_project = 100
@@ -33,6 +34,7 @@ resource "harbor_config_system" "main" {
3334
- `robot_name_prefix` (String) Robot account prefix.
3435
- `robot_token_expiration` (Number) The amount of time in days a robot account will expire.
3536
- `session_timeout` (Number) The session timeout for Harbor UI, in minutes. Defaults to 60.
37+
- `token_expiration` (Number) The expiration time of a token created by the token service, in minutes. Defaults to 30.
3638
- `scanner_skip_update_pulltime` (Boolean) Whether or not to skip update pull time for scanner.
3739
- `storage_per_project` (Number) Default quota space per project in GIB. Default is -1 (unlimited).
3840
- `audit_log_forward_endpoint` (String) The endpoint to forward audit logs to.

models/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ type ConfigBodyAuthPost struct {
3636
OidcGroupFilter string `json:"oidc_group_filter,omitempty"`
3737
OidcGroupsClaim string `json:"oidc_groups_claim,omitempty"`
3838
LdapScope int `json:"ldap_scope"`
39-
TokenExpiration int `json:"token_expiration,omitempty"`
4039
LdapGroupSearchScope int `json:"ldap_group_search_scope"`
4140
LdapVerifyCert bool `json:"ldap_verify_cert"`
4241
LdapGroupGID string `json:"ldap_group_gid,omitempty"`
@@ -47,6 +46,7 @@ type ConfigBodySystemPost struct {
4746
ProjectCreationRestriction string `json:"project_creation_restriction,omitempty"`
4847
ReadOnly bool `json:"read_only"`
4948
RobotTokenDuration int `json:"robot_token_duration,omitempty"`
49+
TokenExpiration int `json:"token_expiration,omitempty"`
5050
SessionTimeout int `json:"session_timeout,omitempty"`
5151
QuotaPerProjectEnable bool `json:"quota_per_project_enable"`
5252
RobotNamePrefix string `json:"robot_name_prefix,omitempty"`
@@ -186,10 +186,6 @@ type ConfigBodyResponse struct {
186186
Editable bool `json:"editable,omitempty"`
187187
Value int `json:"value,omitempty"`
188188
} `json:"ldap_scope,omitempty"`
189-
TokenExpiration struct {
190-
Editable bool `json:"editable,omitempty"`
191-
Value int `json:"value,omitempty"`
192-
} `json:"token_expiration,omitempty"`
193189
LdapGroupSearchScope struct {
194190
Editable bool `json:"editable,omitempty"`
195191
Value int `json:"value,omitempty"`
@@ -210,6 +206,10 @@ type ConfigBodyResponse struct {
210206
Editable bool `json:"editable,omitempty"`
211207
Value int `json:"value,omitempty"`
212208
} `json:"robot_token_duration,omitempty"`
209+
TokenExpiration struct {
210+
Editable bool `json:"editable,omitempty"`
211+
Value int `json:"value,omitempty"`
212+
} `json:"token_expiration,omitempty"`
213213
SessionTimeout struct {
214214
Editable bool `json:"editable,omitempty"`
215215
Value int `json:"value,omitempty"`

provider/resource_config_system.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func resourceConfigSystem() *schema.Resource {
2828
Optional: true,
2929
Default: 30,
3030
},
31+
"token_expiration": {
32+
Type: schema.TypeInt,
33+
Optional: true,
34+
Default: 30,
35+
},
3136
"session_timeout": {
3237
Type: schema.TypeInt,
3338
Optional: true,
@@ -182,6 +187,7 @@ func resourceConfigSystemRead(d *schema.ResourceData, m interface{}) error {
182187
d.Set("project_creation_restriction", jsonData.ProjectCreationRestriction.Value)
183188
d.Set("read_only", jsonData.ReadOnly.Value)
184189
d.Set("robot_token_expiration", jsonData.RobotTokenDuration.Value)
190+
d.Set("token_expiration", jsonData.TokenExpiration.Value)
185191
d.Set("session_timeout", jsonData.SessionTimeout.Value)
186192
d.Set("robot_name_prefix", jsonData.RobotNamePrefix.Value)
187193
d.Set("scanner_skip_update_pulltime", jsonData.ScannerSkipUpdatePulltime.Value)

provider/resource_config_system_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ func TestAccConfigSystem(t *testing.T) {
4545
resourceConfigSystemMain, "read_only", "false"),
4646
resource.TestCheckResourceAttr(
4747
resourceConfigSystemMain, "robot_token_expiration", "30"),
48+
resource.TestCheckResourceAttr(
49+
resourceConfigSystemMain, "token_expiration", "30"),
4850
resource.TestCheckResourceAttr(
4951
resourceConfigSystemMain, "session_timeout", "60"),
5052
resource.TestCheckResourceAttr(
@@ -65,6 +67,7 @@ func testAccCheckConfigSystem() string {
6567
project_creation_restriction = "adminonly"
6668
read_only = false
6769
robot_token_expiration = 30
70+
token_expiration = 30
6871
session_timeout = 60
6972
robot_name_prefix = "robot$"
7073
scanner_skip_update_pulltime = false

0 commit comments

Comments
 (0)