Skip to content

Commit ea67e9c

Browse files
azcontainerregistry: move method to function (#23270)
The Go documentation strongly discourages structs from having methods with both pointer recievers and non-pointer recievers. For the auth policy, `getChallengeRequest` presumably did not have a pointer reciever since it did not make use of the struct at all. We can simply move this to a function. Signed-off-by: Steve Kuznetsov <[email protected]>
1 parent 40dad0a commit ea67e9c

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

‎sdk/containers/azcontainerregistry/authentication_policy.go‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import (
1111
"encoding/json"
1212
"errors"
1313
"fmt"
14-
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
1514
"net/http"
1615
"strings"
1716
"sync/atomic"
1817
"time"
1918

2019
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
2120
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
21+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
2222
"github.com/Azure/azure-sdk-for-go/sdk/internal/temporal"
2323
)
2424

@@ -77,7 +77,7 @@ func (p *authenticationPolicy) Do(req *policy.Request) (*http.Response, error) {
7777
} else {
7878
// do challenge process for the initial request
7979
var challengeReq *policy.Request
80-
challengeReq, err = p.getChallengeRequest(*req)
80+
challengeReq, err = getChallengeRequest(*req)
8181
if err != nil {
8282
return nil, err
8383
}
@@ -167,7 +167,7 @@ func findServiceAndScope(resp *http.Response) (string, string, error) {
167167
return valuesMap["service"], valuesMap["scope"], nil
168168
}
169169

170-
func (p authenticationPolicy) getChallengeRequest(oriReq policy.Request) (*policy.Request, error) {
170+
func getChallengeRequest(oriReq policy.Request) (*policy.Request, error) {
171171
copied := oriReq.Clone(oriReq.Raw().Context())
172172
err := copied.SetBody(nil, "")
173173
if err != nil {

‎sdk/containers/azcontainerregistry/authentication_policy_test.go‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,14 +217,13 @@ func Test_authenticationPolicy_anonymousAccess(t *testing.T) {
217217
require.Error(t, err)
218218
}
219219

220-
func Test_authenticationPolicy_getChallengeRequest(t *testing.T) {
220+
func Test_getChallengeRequest(t *testing.T) {
221221
oriReq, err := runtime.NewRequest(context.Background(), http.MethodPost, "https://test.com")
222222
require.NoError(t, err)
223223
testBody := []byte("test")
224224
err = oriReq.SetBody(streaming.NopCloser(bytes.NewReader(testBody)), "text/plain")
225225
require.NoError(t, err)
226-
p := &authenticationPolicy{}
227-
challengeReq, err := p.getChallengeRequest(*oriReq)
226+
challengeReq, err := getChallengeRequest(*oriReq)
228227
require.NoError(t, err)
229228
require.Equal(t, fmt.Sprintf("%d", len(testBody)), oriReq.Raw().Header.Get("Content-Length"))
230229
require.Equal(t, "", challengeReq.Raw().Header.Get("Content-Length"))

0 commit comments

Comments
 (0)