Skip to content

Commit fff80be

Browse files
authored
Update aztemplate with latest azcore and azidentity (#18202)
* Update aztemplate with latest azcore and azidentity Added version.go per pattern and demonstrated how to create a pipeline. Tweaked APIs to be indicative of real-world APIs. * add templates for pagers and pollers * add tests * make linter happy * drop test coverage
1 parent aafabad commit fff80be

File tree

10 files changed

+217
-81
lines changed

10 files changed

+217
-81
lines changed

eng/config.json

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
"Name": "azidentity",
2121
"CoverageGoal": 0.68
2222
},
23+
{
24+
"Name": "aztemplate",
25+
"CoverageGoal": 0.50
26+
},
2327
{
2428
"Name": "keyvault/azcertificates",
2529
"CoverageGoal": 0.80

sdk/template/aztemplate/client.go

+102-11
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,128 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.
66

77
package aztemplate
88

99
import (
10+
"context"
11+
"net/http"
12+
1013
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
14+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
15+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
1116
"github.com/Azure/azure-sdk-for-go/sdk/template/aztemplate/internal"
1217
)
1318

1419
// ClientOptions contains optional parameters for NewClient
15-
type ClientOptions struct{}
20+
type ClientOptions struct {
21+
azcore.ClientOptions
22+
}
1623

17-
// Client is the client to interact with
24+
// Client is the client to interact with.
25+
// Don't use this type directly, use NewClient() instead.
1826
type Client struct {
1927
client *internal.TemplateClient
28+
pl runtime.Pipeline
2029
}
2130

2231
// NewClient returns a pointer to a Client
2332
func NewClient(cred azcore.TokenCredential, options *ClientOptions) (*Client, error) {
33+
if options == nil {
34+
options = &ClientOptions{}
35+
}
36+
37+
pl := runtime.NewPipeline(moduleName, moduleVersion, runtime.PipelineOptions{
38+
PerRetry: []policy.Policy{
39+
runtime.NewBearerTokenPolicy(cred, []string{"service_scope"}, nil),
40+
},
41+
}, &options.ClientOptions)
2442

25-
//if options == nil {
26-
//options = &ClientOptions{}
27-
//}
28-
tc := internal.NewTemplateClient()
43+
return &Client{client: internal.NewTemplateClient(pl), pl: pl}, nil
2944

30-
return &Client{client: tc}, nil
45+
}
46+
47+
// SomeServiceActionOptions contains the optional values for the Client.SomeServiceAction method.
48+
type SomeServiceActionOptions struct {
49+
// OptionalValue is some optional value to be sent to the service. nil means nothing is sent.
50+
OptionalValue *string
51+
}
3152

53+
// ClientSomeServiceActionResponse contains the response from method Client.SomeServiceAction.
54+
type ClientSomeServiceActionResponse struct {
55+
Value *string
3256
}
3357

3458
// SomeServiceAction does some service action
35-
func (c *Client) SomeServiceAction() {
36-
c.client.PrintInfo()
59+
func (c *Client) SomeServiceAction(ctx context.Context, options *SomeServiceActionOptions) (ClientSomeServiceActionResponse, error) {
60+
resp, err := c.client.SomeAPI(ctx, nil)
61+
if err != nil {
62+
return ClientSomeServiceActionResponse{}, err
63+
}
64+
return ClientSomeServiceActionResponse{Value: resp.Value}, nil
65+
}
66+
67+
// ClientListValuesOptions contains the optional values for the Client.NewListValuesPager method.
68+
type ClientListValuesOptions struct {
69+
// PerPage is the optional number of items to return per page.
70+
PerPage *int32
71+
}
72+
73+
// ClientListValuesResponse contains the response from method Client.ListValues.
74+
type ClientListValuesResponse struct {
75+
// Next might be a URL to fetch the next page or a continuation token.
76+
Next *string
77+
78+
// Values contains the contents of the page.
79+
Values []*string
80+
}
81+
82+
// NewListValuesPager creates a pager to iterate over pages of results.
83+
func (c *Client) NewListValuesPager(options *ClientListValuesOptions) *runtime.Pager[ClientListValuesResponse] {
84+
return runtime.NewPager(runtime.PagingHandler[ClientListValuesResponse]{
85+
More: func(resp ClientListValuesResponse) bool {
86+
// inspect resp to see if there are more pages
87+
return false
88+
},
89+
Fetcher: func(ctx context.Context, resp *ClientListValuesResponse) (ClientListValuesResponse, error) {
90+
// use resp to construct the request to fetch the next page
91+
return ClientListValuesResponse{}, nil
92+
},
93+
})
94+
}
95+
96+
// ClientBeginLongRunningOperationOptions contains the optional values for the Client.BeginLongRunningOperation method.
97+
type ClientBeginLongRunningOperationOptions struct {
98+
// Resumes the LRO from the provided token.
99+
ResumeToken string
100+
}
101+
102+
// ClientLongRunningOperationResponse contains the response from method Client.LongRunningOperation.
103+
type ClientLongRunningOperationResponse struct {
104+
Value *string
105+
}
106+
107+
// BeginLongRunningOperation is a long-running operation that can take several seconds to complete.
108+
func (c *Client) BeginLongRunningOperation(ctx context.Context, options *ClientBeginLongRunningOperationOptions) (*runtime.Poller[ClientLongRunningOperationResponse], error) {
109+
if options == nil {
110+
options = &ClientBeginLongRunningOperationOptions{}
111+
}
112+
113+
if options.ResumeToken != "" {
114+
return runtime.NewPollerFromResumeToken[ClientLongRunningOperationResponse](options.ResumeToken, c.pl, nil)
115+
}
116+
117+
// start the LRO
118+
req, err := runtime.NewRequest(ctx, http.MethodPost, "the LRO URL")
119+
if err != nil {
120+
return nil, err
121+
}
122+
123+
resp, err := c.pl.Do(req)
124+
if err != nil {
125+
return nil, err
126+
}
127+
return runtime.NewPoller[ClientLongRunningOperationResponse](resp, c.pl, nil)
37128
}

sdk/template/aztemplate/client_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
//go:build go1.16
2-
// +build go1.16
1+
//go:build go1.18
2+
// +build go1.18
33

44
// Copyright (c) Microsoft Corporation. All rights reserved.
55
// Licensed under the MIT License.
66

77
package aztemplate
88

99
import (
10+
"context"
1011
"testing"
1112

1213
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
@@ -20,6 +21,9 @@ func TestOutput(t *testing.T) {
2021

2122
client, _ := NewClient(cred, nil)
2223

23-
client.SomeServiceAction()
24+
_, _ = client.SomeServiceAction(context.TODO(), nil)
2425

26+
client.NewListValuesPager(nil)
27+
28+
_, _ = client.BeginLongRunningOperation(context.TODO(), nil)
2529
}

sdk/template/aztemplate/go.mod

+16-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
module github.com/Azure/azure-sdk-for-go/sdk/template/aztemplate
22

3-
go 1.16
3+
go 1.18
44

55
require (
6-
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0
7-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0
6+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0
7+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0
8+
)
9+
10+
require (
11+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect
12+
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 // indirect
13+
github.com/golang-jwt/jwt v3.2.1+incompatible // indirect
14+
github.com/google/uuid v1.1.1 // indirect
15+
github.com/kylelemons/godebug v1.1.0 // indirect
16+
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
17+
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect
18+
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 // indirect
19+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
20+
golang.org/x/text v0.3.7 // indirect
821
)

sdk/template/aztemplate/go.sum

+29-39
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
1-
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0 h1:KQgdWmEOmaJKxaUUZwHAYh12t+b+ZJf8q3friycK1kA=
2-
github.com/Azure/azure-sdk-for-go/sdk/azcore v0.20.0/go.mod h1:ZPW/Z0kLCTdDZaDbYTetxc9Cxl/2lNqxYHYNOF2bti0=
3-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0 h1:VBvHGLJbaY0+c66NZHdS9cgjHVYSH6DDa0XJMyrblsI=
4-
github.com/Azure/azure-sdk-for-go/sdk/azidentity v0.12.0/go.mod h1:GJzjM4SR9T0KyX5gKCVyz1ytD8FeWeUPCwtFCt1AyfE=
5-
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1 h1:BUYIbDf/mMZ8945v3QkG3OuqGVyS4Iek0AOLwdRAYoc=
6-
github.com/Azure/azure-sdk-for-go/sdk/internal v0.8.1/go.mod h1:KLF4gFr6DcKFZwSuH8w8yEK6DpFl3LP5rhdvAb7Yz5I=
7-
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0 h1:sVPhtT2qjO86rTUaWMr4WoES4TkjGnzcioXcnHV9s5k=
2+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.0.0/go.mod h1:uGG2W01BaETf0Ozp+QxxKJdMBNRWPdstHG0Fmdwn1/U=
3+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0 h1:Yoicul8bnVdQrhDMTHxdEckRGX01XvwXDHUT9zYZ3k0=
4+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.0.0/go.mod h1:+6sju8gk8FRmSajX3Oz4G5Gm7P+mbqE9FVaXXFYTkCM=
5+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 h1:jp0dGvZ7ZK0mgqnTSClMxa5xuRL7NZgHameVYF6BurY=
6+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
7+
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0 h1:WVsrXCnHlDDX8ls+tootqRE87/hL9S/g4ewig9RsD/c=
8+
github.com/AzureAD/microsoft-authentication-library-for-go v0.4.0/go.mod h1:Vt9sXTKwMyGcOxSmLDMnGPgqsUg7m8pe215qMLrDXw4=
89
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
9-
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
10-
github.com/dnaeon/go-vcr v1.1.0/go.mod h1:M7tiix8f0r6mKKJ3Yq/kqU1OYf3MnfmBWVbPx/yU9ko=
11-
github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8=
12-
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4 h1:49lOXmGaUpV9Fz3gd7TFZY106KVlPVa5jcYD1gaQf98=
13-
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
10+
github.com/dnaeon/go-vcr v1.1.0 h1:ReYa/UBrRyQdant9B4fNHGoCNKw6qh6P0fsdGmZpR7c=
11+
github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfEP4Q1lOd9Z/+c=
12+
github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
13+
github.com/golang-jwt/jwt/v4 v4.2.0 h1:besgBTC8w8HjP6NzQdxwKH9Z5oQMZ24ThTrHp3cZ8eU=
14+
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
15+
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
16+
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
17+
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
18+
github.com/montanaflynn/stats v0.6.6/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow=
19+
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 h1:Qj1ukM4GlMWXNdMBuXcXfz/Kw9s1qm0CLY32QxuSImI=
20+
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4/go.mod h1:N6UoU20jOqggOuDwUaBQpluzLNDqif3kq9z2wpdYEfQ=
1421
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
15-
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
16-
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
1722
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
18-
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
19-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
20-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
21-
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
22-
golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
23-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
24-
golang.org/x/net v0.0.0-20201010224723-4f7140c49acb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
25-
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b h1:k+E048sYJHyVnsr1GDrRZWQ32D2C7lWs9JRc0bel53A=
26-
golang.org/x/net v0.0.0-20210610132358-84b48f89b13b/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
27-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
28-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
29-
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30-
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31-
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
32-
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
33-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
34-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
35-
golang.org/x/text v0.3.6 h1:aRYxNxv6iGQlyVaZmk6ZgYEDa+Jg18DxebPSrd6bg1M=
36-
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
37-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
38-
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
39-
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
40-
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
41-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
23+
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 h1:Tgea0cVUD0ivh5ADBX4WwuI12DUd2to3nCYe2eayMIw=
24+
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
25+
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4 h1:HVyaeDAYux4pnY+D/SiwmLOR36ewZ4iGQIIrtnuCjFA=
26+
golang.org/x/net v0.0.0-20220425223048-2871e0cb64e4/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
27+
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
28+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
29+
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
30+
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
31+
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
32+
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
4233
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
43-
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

sdk/template/aztemplate/internal/constants.go

-16
This file was deleted.

sdk/template/aztemplate/internal/models.go

+14
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/template/aztemplate/internal/response_types.go

+15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/template/aztemplate/internal/template_client.go

+14-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/template/aztemplate/version.go

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build go1.18
2+
// +build go1.18
3+
4+
// Copyright (c) Microsoft Corporation. All rights reserved.
5+
// Licensed under the MIT License.
6+
7+
package aztemplate
8+
9+
// Constants to identify the module
10+
const (
11+
// moduleName is the module name that shows in telemetry.
12+
moduleName = "aztemplate"
13+
14+
// moduleVersion is the semantic version (see http://semver.org) of this module.
15+
moduleVersion = "v0.1.0"
16+
)

0 commit comments

Comments
 (0)