Skip to content

Commit bf1e3fe

Browse files
authored
Renamed pager APIs per new guidelines (Azure#17677)
* Renamed pager APIs per new guidelines Removed duplicated pager creation code. * remove empty path param check * fix doc comments
1 parent a32caab commit bf1e3fe

File tree

8 files changed

+136
-183
lines changed

8 files changed

+136
-183
lines changed

sdk/keyvault/azcertificates/CHANGELOG.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# Release History
22

3-
## 0.3.1 (Unreleased)
4-
5-
### Features Added
3+
## 0.4.0 (2022-04-21)
64

75
### Breaking Changes
8-
9-
### Bugs Fixed
6+
* Renamed the following methods
7+
* `Client.ListPropertiesOfCertificates` to `Client.NewListPropertiesOfCertificatesPager`
8+
* `Client.ListPropertiesOfCertificateVersions` to `Client.NewListPropertiesOfCertificateVersionsPager`
9+
* `Client.ListPropertiesOfIssuers` to `Client.NewListPropertiesOfIssuersPager`
10+
* `Client.ListDeletedCertificates` to `Client.NewListDeletedCertificatesPager`
1011

1112
### Other Changes
13+
* Regenerated code with latest code generator (no visible changes).
1214

1315
## 0.3.0 (2022-04-06)
1416

sdk/keyvault/azcertificates/autorest.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,24 @@ input-file:
1010
license-header: MICROSOFT_MIT_NO_VERSION
1111
clear-output-folder: true
1212
output-folder: internal/generated
13-
module: azcertificates
1413
openapi-type: "data-plane"
1514
security: "AADToken"
1615
security-scopes: "https://vault.azure.net/.default"
17-
use: "@autorest/go@4.0.0-preview.38"
18-
module-version: 0.3.0
16+
use: "@autorest/go@4.0.0-preview.40"
17+
module-version: 0.4.0
1918
export-clients: true
19+
20+
# remove the empty certificateVersion path param check. it's legal for KV but can't be described in OpenAPI
21+
directive:
22+
- from: constants.go
23+
where: $
24+
transform: >-
25+
return $.
26+
replace(/moduleName\s+=\s+"generated"/, `ModuleName = "azcertificates"`).
27+
replace(/moduleVersion\s+=/, `ModuleVersion =`);
28+
- from: keyvault_client.go
29+
where: $
30+
transform: >-
31+
return $.
32+
replaceAll(/\sif certificateVersion == "" \{\s+return nil, errors\.New\("parameter certificateVersion cannot be empty"\)\s+\}\s/g, ``);
2033
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//go:build go1.18
2+
// +build go1.18
3+
4+
//go:generate autorest ./autorest.md
5+
6+
// Copyright (c) Microsoft Corporation. All rights reserved.
7+
// Licensed under the MIT License. See License.txt in the project root for license information.
8+
9+
package azcertificates

sdk/keyvault/azcertificates/client.go

Lines changed: 28 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -632,38 +632,22 @@ func listCertsPageFromGenerated(i generated.KeyVaultClientGetCertificatesRespons
632632
}
633633
}
634634

635-
// ListPropertiesOfCertificates retrieves a list of the certificates in the Key Vault as JSON Web Key structures that contain the
635+
// NewListPropertiesOfCertificatesPager retrieves a list of the certificates in the Key Vault as JSON Web Key structures that contain the
636636
// public part of a stored certificate. The LIST operation is applicable to all certificate types, however only the
637637
// base certificate identifier, attributes, and tags are provided in the response. Individual versions of a
638638
// certificate are not listed in the response. This operation requires the certificates/list permission.
639-
func (c *Client) ListPropertiesOfCertificates(options *ListCertificatesOptions) *runtime.Pager[ListPropertiesOfCertificatesResponse] {
639+
func (c *Client) NewListPropertiesOfCertificatesPager(options *ListCertificatesOptions) *runtime.Pager[ListPropertiesOfCertificatesResponse] {
640+
pager := c.genClient.NewGetCertificatesPager(c.vaultURL, nil)
640641
return runtime.NewPager(runtime.PageProcessor[ListPropertiesOfCertificatesResponse]{
641642
More: func(page ListPropertiesOfCertificatesResponse) bool {
642-
return page.NextLink != nil && len(*page.NextLink) > 0
643+
return pager.More()
643644
},
644-
Fetcher: func(ctx context.Context, page *ListPropertiesOfCertificatesResponse) (ListPropertiesOfCertificatesResponse, error) {
645-
var req *policy.Request
646-
var err error
647-
if page == nil {
648-
req, err = c.genClient.GetCertificatesCreateRequest(ctx, c.vaultURL, &generated.KeyVaultClientGetCertificatesOptions{})
649-
} else {
650-
req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink)
651-
}
652-
if err != nil {
653-
return ListPropertiesOfCertificatesResponse{}, err
654-
}
655-
resp, err := c.genClient.Pl.Do(req)
656-
if err != nil {
657-
return ListPropertiesOfCertificatesResponse{}, err
658-
}
659-
if !runtime.HasStatusCode(resp, http.StatusOK) {
660-
return ListPropertiesOfCertificatesResponse{}, runtime.NewResponseError(resp)
661-
}
662-
genResp, err := c.genClient.GetCertificatesHandleResponse(resp)
645+
Fetcher: func(ctx context.Context, cur *ListPropertiesOfCertificatesResponse) (ListPropertiesOfCertificatesResponse, error) {
646+
page, err := pager.NextPage(ctx)
663647
if err != nil {
664648
return ListPropertiesOfCertificatesResponse{}, err
665649
}
666-
return listCertsPageFromGenerated(genResp), nil
650+
return listCertsPageFromGenerated(page), nil
667651
},
668652
})
669653
}
@@ -698,37 +682,21 @@ func listCertificateVersionsPageFromGenerated(i generated.KeyVaultClientGetCerti
698682
}
699683
}
700684

701-
// ListPropertiesOfCertificateVersions lists all versions of the specified certificate. The full certificate identifer and
685+
// NewListPropertiesOfCertificateVersionsPager lists all versions of the specified certificate. The full certificate identifer and
702686
// attributes are provided in the response. No values are returned for the certificates. This operation
703687
// requires the certificates/list permission.
704-
func (c *Client) ListPropertiesOfCertificateVersions(certificateName string, options *ListCertificateVersionsOptions) *runtime.Pager[ListPropertiesOfCertificateVersionsResponse] {
688+
func (c *Client) NewListPropertiesOfCertificateVersionsPager(certificateName string, options *ListCertificateVersionsOptions) *runtime.Pager[ListPropertiesOfCertificateVersionsResponse] {
689+
pager := c.genClient.NewGetCertificateVersionsPager(c.vaultURL, certificateName, nil)
705690
return runtime.NewPager(runtime.PageProcessor[ListPropertiesOfCertificateVersionsResponse]{
706691
More: func(page ListPropertiesOfCertificateVersionsResponse) bool {
707-
return page.NextLink != nil && len(*page.NextLink) > 0
692+
return pager.More()
708693
},
709-
Fetcher: func(ctx context.Context, page *ListPropertiesOfCertificateVersionsResponse) (ListPropertiesOfCertificateVersionsResponse, error) {
710-
var req *policy.Request
711-
var err error
712-
if page == nil {
713-
req, err = c.genClient.GetCertificateVersionsCreateRequest(ctx, c.vaultURL, certificateName, &generated.KeyVaultClientGetCertificateVersionsOptions{})
714-
} else {
715-
req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink)
716-
}
717-
if err != nil {
718-
return ListPropertiesOfCertificateVersionsResponse{}, err
719-
}
720-
resp, err := c.genClient.Pl.Do(req)
721-
if err != nil {
722-
return ListPropertiesOfCertificateVersionsResponse{}, err
723-
}
724-
if !runtime.HasStatusCode(resp, http.StatusOK) {
725-
return ListPropertiesOfCertificateVersionsResponse{}, runtime.NewResponseError(resp)
726-
}
727-
genResp, err := c.genClient.GetCertificateVersionsHandleResponse(resp)
694+
Fetcher: func(ctx context.Context, cur *ListPropertiesOfCertificateVersionsResponse) (ListPropertiesOfCertificateVersionsResponse, error) {
695+
page, err := pager.NextPage(ctx)
728696
if err != nil {
729697
return ListPropertiesOfCertificateVersionsResponse{}, err
730698
}
731-
return listCertificateVersionsPageFromGenerated(genResp), nil
699+
return listCertificateVersionsPageFromGenerated(page), nil
732700
},
733701
})
734702
}
@@ -916,36 +884,20 @@ func listIssuersPageFromGenerated(i generated.KeyVaultClientGetCertificateIssuer
916884
return ListIssuersPropertiesOfIssuersResponse{Issuers: vals, NextLink: i.NextLink}
917885
}
918886

919-
// ListPropertiesOfIssuers returns a pager that can be used to get the set of certificate issuer resources in the specified key vault. This operation
887+
// NewListPropertiesOfIssuersPager returns a pager that can be used to get the set of certificate issuer resources in the specified key vault. This operation
920888
// requires the certificates/manageissuers/getissuers permission.
921-
func (c *Client) ListPropertiesOfIssuers(options *ListPropertiesOfIssuersOptions) *runtime.Pager[ListIssuersPropertiesOfIssuersResponse] {
889+
func (c *Client) NewListPropertiesOfIssuersPager(options *ListPropertiesOfIssuersOptions) *runtime.Pager[ListIssuersPropertiesOfIssuersResponse] {
890+
pager := c.genClient.NewGetCertificateIssuersPager(c.vaultURL, nil)
922891
return runtime.NewPager(runtime.PageProcessor[ListIssuersPropertiesOfIssuersResponse]{
923892
More: func(page ListIssuersPropertiesOfIssuersResponse) bool {
924-
return page.NextLink != nil && len(*page.NextLink) > 0
893+
return pager.More()
925894
},
926-
Fetcher: func(ctx context.Context, page *ListIssuersPropertiesOfIssuersResponse) (ListIssuersPropertiesOfIssuersResponse, error) {
927-
var req *policy.Request
928-
var err error
929-
if page == nil {
930-
req, err = c.genClient.GetCertificateIssuersCreateRequest(ctx, c.vaultURL, &generated.KeyVaultClientGetCertificateIssuersOptions{})
931-
} else {
932-
req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink)
933-
}
934-
if err != nil {
935-
return ListIssuersPropertiesOfIssuersResponse{}, err
936-
}
937-
resp, err := c.genClient.Pl.Do(req)
938-
if err != nil {
939-
return ListIssuersPropertiesOfIssuersResponse{}, err
940-
}
941-
if !runtime.HasStatusCode(resp, http.StatusOK) {
942-
return ListIssuersPropertiesOfIssuersResponse{}, runtime.NewResponseError(resp)
943-
}
944-
genResp, err := c.genClient.GetCertificateIssuersHandleResponse(resp)
895+
Fetcher: func(ctx context.Context, cur *ListIssuersPropertiesOfIssuersResponse) (ListIssuersPropertiesOfIssuersResponse, error) {
896+
page, err := pager.NextPage(ctx)
945897
if err != nil {
946898
return ListIssuersPropertiesOfIssuersResponse{}, err
947899
}
948-
return listIssuersPageFromGenerated(genResp), nil
900+
return listIssuersPageFromGenerated(page), nil
949901
},
950902
})
951903
}
@@ -1577,37 +1529,21 @@ type ListDeletedCertificatesOptions struct {
15771529
// placeholder for future optional parameters
15781530
}
15791531

1580-
// ListDeletedCertificates retrieves the certificates in the current vault which are in a deleted state and ready for recovery or purging.
1532+
// NewListDeletedCertificatesPager retrieves the certificates in the current vault which are in a deleted state and ready for recovery or purging.
15811533
// This operation includes deletion-specific information. This operation requires the certificates/get/list permission. This operation can
15821534
// only be enabled on soft-delete enabled vaults.
1583-
func (c *Client) ListDeletedCertificates(options *ListDeletedCertificatesOptions) *runtime.Pager[ListDeletedCertificatesResponse] {
1535+
func (c *Client) NewListDeletedCertificatesPager(options *ListDeletedCertificatesOptions) *runtime.Pager[ListDeletedCertificatesResponse] {
1536+
pager := c.genClient.NewGetDeletedCertificatesPager(c.vaultURL, nil)
15841537
return runtime.NewPager(runtime.PageProcessor[ListDeletedCertificatesResponse]{
15851538
More: func(page ListDeletedCertificatesResponse) bool {
1586-
return page.NextLink != nil && len(*page.NextLink) > 0
1539+
return pager.More()
15871540
},
1588-
Fetcher: func(ctx context.Context, page *ListDeletedCertificatesResponse) (ListDeletedCertificatesResponse, error) {
1589-
var req *policy.Request
1590-
var err error
1591-
if page == nil {
1592-
req, err = c.genClient.GetDeletedCertificatesCreateRequest(ctx, c.vaultURL, &generated.KeyVaultClientGetDeletedCertificatesOptions{})
1593-
} else {
1594-
req, err = runtime.NewRequest(ctx, http.MethodGet, *page.NextLink)
1595-
}
1596-
if err != nil {
1597-
return ListDeletedCertificatesResponse{}, err
1598-
}
1599-
resp, err := c.genClient.Pl.Do(req)
1600-
if err != nil {
1601-
return ListDeletedCertificatesResponse{}, err
1602-
}
1603-
if !runtime.HasStatusCode(resp, http.StatusOK) {
1604-
return ListDeletedCertificatesResponse{}, runtime.NewResponseError(resp)
1605-
}
1606-
genResp, err := c.genClient.GetDeletedCertificatesHandleResponse(resp)
1541+
Fetcher: func(ctx context.Context, cur *ListDeletedCertificatesResponse) (ListDeletedCertificatesResponse, error) {
1542+
page, err := pager.NextPage(ctx)
16071543
if err != nil {
16081544
return ListDeletedCertificatesResponse{}, err
16091545
}
1610-
return listDeletedCertsPageFromGenerated(genResp), nil
1546+
return listDeletedCertsPageFromGenerated(page), nil
16111547
},
16121548
})
16131549
}

sdk/keyvault/azcertificates/client_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func TestClient_ListCertificates(t *testing.T) {
275275

276276
time.Sleep(10 * delay())
277277

278-
pager := client.ListPropertiesOfCertificates(nil)
278+
pager := client.NewListPropertiesOfCertificatesPager(nil)
279279
for pager.More() {
280280
page, err := pager.NextPage(context.Background())
281281
require.NoError(t, err)
@@ -301,7 +301,7 @@ func TestClient_ListCertificateVersions(t *testing.T) {
301301
time.Sleep(10 * delay())
302302
defer cleanUp(t, client, name)
303303

304-
pager := client.ListPropertiesOfCertificateVersions(name, nil)
304+
pager := client.NewListPropertiesOfCertificateVersionsPager(name, nil)
305305
count := 0
306306
for pager.More() {
307307
resp, err := pager.NextPage(context.Background())
@@ -315,7 +315,7 @@ func TestClient_ListCertificateVersions(t *testing.T) {
315315
createCert(t, client, name)
316316
time.Sleep(10 * delay())
317317

318-
pager = client.ListPropertiesOfCertificateVersions(name, nil)
318+
pager = client.NewListPropertiesOfCertificateVersionsPager(name, nil)
319319
count = 0
320320
for pager.More() {
321321
resp, err := pager.NextPage(context.Background())
@@ -329,7 +329,7 @@ func TestClient_ListCertificateVersions(t *testing.T) {
329329
createCert(t, client, name)
330330
time.Sleep(10 * delay())
331331

332-
pager = client.ListPropertiesOfCertificateVersions(name, nil)
332+
pager = client.NewListPropertiesOfCertificateVersionsPager(name, nil)
333333
count = 0
334334
for pager.More() {
335335
resp, err := pager.NextPage(context.Background())
@@ -414,7 +414,7 @@ func TestClient_IssuerCRUD(t *testing.T) {
414414
require.Equal(t, issuerName2, *createResp.Issuer.Name)
415415

416416
// List operation
417-
pager := client.ListPropertiesOfIssuers(nil)
417+
pager := client.NewListPropertiesOfIssuersPager(nil)
418418
count := 0
419419
for pager.More() {
420420
page, err := pager.NextPage(context.Background())
@@ -886,7 +886,7 @@ func TestClient_ListDeletedCertificates(t *testing.T) {
886886

887887
time.Sleep(10 * delay())
888888

889-
pager := client.ListDeletedCertificates(nil)
889+
pager := client.NewListDeletedCertificatesPager(nil)
890890
deletedCount := 0
891891
for pager.More() {
892892
page, err := pager.NextPage(ctx)

sdk/keyvault/azcertificates/example_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ func ExampleClient_UpdateCertificateProperties() {
133133
fmt.Println(resp.Properties.Tags)
134134
}
135135

136-
func ExampleClient_ListPropertiesOfCertificates() {
136+
func ExampleClient_NewListPropertiesOfCertificatesPager() {
137137
cred, err := azidentity.NewDefaultAzureCredential(nil)
138138
if err != nil {
139139
panic(err)
@@ -149,7 +149,7 @@ func ExampleClient_ListPropertiesOfCertificates() {
149149
panic(err)
150150
}
151151

152-
pager := client.ListPropertiesOfCertificates(nil)
152+
pager := client.NewListPropertiesOfCertificatesPager(nil)
153153
for pager.More() {
154154
page, err := pager.NextPage(context.TODO())
155155
if err != nil {

sdk/keyvault/azcertificates/internal/generated/constants.go

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

0 commit comments

Comments
 (0)