Skip to content

Commit 6383059

Browse files
author
mikatong
committed
support reset_password
1 parent e3318ff commit 6383059

File tree

11 files changed

+2172
-2192
lines changed

11 files changed

+2172
-2192
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ require (
8686
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tat v1.0.634
8787
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcaplusdb v1.0.199
8888
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547
89-
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.696
89+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.1142
9090
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533
9191
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdmq v1.0.955
9292
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tem v1.0.578

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,8 @@ github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547 h1:6bukohy
10851085
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcm v1.0.547/go.mod h1:C7b++Lr8Xh+2KtTUMBjbb+/BrBhfFhAxDMjXzT2GLhY=
10861086
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.696 h1:hTfJtxk5WDj84SfOFKg5Mk+DVtSmjVtkyj3gvVKAYkk=
10871087
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.696/go.mod h1:DgY9Kgh9093fBl2M/vEFGJZwytDIrPQlYoxoT4rE7O0=
1088+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.1142 h1:X5eKYvyDNA69jXB2AtsLIoa8lwZ3haUZymSHHk4JUiI=
1089+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcr v1.0.1142/go.mod h1:GLR0nyoKy8qfcWpfDeA8wgRDY+pqq5UE/SLbB2l9NzU=
10881090
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcss v1.0.1031 h1:3OgSLiQAfgjQ3kH+lu5WBXRtE6JaZ+FY1Yr+LUv1JEw=
10891091
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tcss v1.0.1031/go.mod h1:e5FteF6ukTKsD6wergqmPn/jww3oPwi/QJYtTfYbFuY=
10901092
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/tdcpg v1.0.533 h1:r6HQhmHzPp1oSGhwkNzUzIRlpnpb8Jhtcn1yKhg9ml4=

tencentcloud/services/tcr/resource_tc_tcr_service_account.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@ func ResourceTencentCloudTcrServiceAccount() *schema.Resource {
9292
Description: "Password of the service account.",
9393
},
9494

95+
"reset_password": {
96+
Optional: true,
97+
Type: schema.TypeBool,
98+
Description: "Reset password.",
99+
},
100+
95101
"tags": {
96102
Type: schema.TypeMap,
97103
Optional: true,
@@ -277,6 +283,8 @@ func resourceTencentCloudTcrServiceAccountUpdate(d *schema.ResourceData, meta in
277283
defer tccommon.InconsistentCheck(d, meta)()
278284

279285
logId := tccommon.GetLogId(tccommon.ContextNil)
286+
ctx := context.WithValue(context.TODO(), tccommon.LogIdKey, logId)
287+
service := TCRService{client: meta.(tccommon.ProviderMeta).GetAPIV3Conn()}
280288

281289
request := tcr.NewModifyServiceAccountRequest()
282290

@@ -370,6 +378,15 @@ func resourceTencentCloudTcrServiceAccountUpdate(d *schema.ResourceData, meta in
370378
}
371379
}
372380

381+
if d.HasChange("reset_password") {
382+
if v, ok := d.GetOkExists("reset_password"); ok && v.(bool) {
383+
password, err := service.ModifyServiceAccountPassword(ctx, registryId, name)
384+
if err != nil {
385+
return err
386+
}
387+
_ = d.Set("password", password)
388+
}
389+
}
373390
return resourceTencentCloudTcrServiceAccountRead(d, meta)
374391
}
375392

tencentcloud/services/tcr/resource_tc_tcr_service_account_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ func TestAccTencentCloudTcrServiceAccountResource_basic(t *testing.T) {
5555
// resource.TestCheckResourceAttr("tencentcloud_tcr_service_account.example", "disable", "true"),
5656
),
5757
},
58+
{
59+
Config: fmt.Sprintf(testAccTcrServiceAccount_resetPassword, expireTime),
60+
PreConfig: func() {
61+
tcacctest.AccStepSetRegion(t, "ap-shanghai")
62+
tcacctest.AccPreCheckCommon(t, tcacctest.ACCOUNT_TYPE_COMMON)
63+
},
64+
Check: resource.ComposeTestCheckFunc(
65+
resource.TestCheckResourceAttrSet("tencentcloud_tcr_service_account.example", "id"),
66+
resource.TestCheckResourceAttrSet("tencentcloud_tcr_service_account.example", "password"),
67+
),
68+
},
5869
{
5970
ResourceName: "tencentcloud_tcr_service_account.example",
6071
ImportState: true,
@@ -144,3 +155,44 @@ resource "tencentcloud_tcr_instance" "example" {
144155
}
145156
146157
`
158+
159+
const testAccTcrServiceAccount_resetPassword = `
160+
161+
resource "tencentcloud_tcr_instance" "example" {
162+
name = "tf-example-tcr-instance"
163+
instance_type = "premium"
164+
delete_bucket = true
165+
tags = {
166+
"createdBy" = "terraform"
167+
}
168+
}
169+
170+
resource "tencentcloud_tcr_namespace" "example" {
171+
instance_id = tencentcloud_tcr_instance.example.id
172+
name = "tf_test_tcr_namespace"
173+
is_public = true
174+
is_auto_scan = true
175+
is_prevent_vul = true
176+
severity = "medium"
177+
cve_whitelist_items {
178+
cve_id = "tf_example_cve_id"
179+
}
180+
}
181+
182+
resource "tencentcloud_tcr_service_account" "example" {
183+
registry_id = tencentcloud_tcr_instance.example.id
184+
name = "tf_example_account"
185+
permissions {
186+
resource = tencentcloud_tcr_namespace.example.name
187+
actions = ["tcr:PushRepository"]
188+
}
189+
description = "CHANGED tf example for tcr service account"
190+
expires_at = %d
191+
disable = false
192+
tags = {
193+
"createdBy" = "terraform"
194+
}
195+
reset_password = true
196+
}
197+
198+
`

tencentcloud/services/tcr/service_tencentcloud_tcr.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,3 +1801,32 @@ func (me *TCRService) DeleteTcrServiceAccountById(ctx context.Context, registryI
18011801

18021802
return
18031803
}
1804+
1805+
func (me *TCRService) ModifyServiceAccountPassword(ctx context.Context, registryId string, name string) (password string, errRet error) {
1806+
logId := tccommon.GetLogId(ctx)
1807+
1808+
request := tcr.NewModifyServiceAccountPasswordRequest()
1809+
request.RegistryId = &registryId
1810+
request.Name = &name
1811+
request.Random = helper.Bool(true)
1812+
1813+
defer func() {
1814+
if errRet != nil {
1815+
log.Printf("[CRITAL]%s api[%s] fail, request body [%s], reason[%s]\n", logId, request.GetAction(), request.ToJsonString(), errRet.Error())
1816+
}
1817+
}()
1818+
1819+
ratelimit.Check(request.GetAction())
1820+
1821+
response, err := me.client.UseTCRClient().ModifyServiceAccountPassword(request)
1822+
if err != nil {
1823+
errRet = err
1824+
return
1825+
}
1826+
log.Printf("[DEBUG]%s api[%s] success, request body [%s], response body [%s]\n", logId, request.GetAction(), request.ToJsonString(), response.ToJsonString())
1827+
1828+
if response.Response.Password != nil {
1829+
password = *response.Response.Password
1830+
}
1831+
return
1832+
}

vendor/github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/http/request.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)