Skip to content

Commit

Permalink
chore: Merge branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
mozillazg committed Sep 1, 2024
2 parents b43da33 + 4940ae8 commit b0f30d6
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 156 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
version: v1.41
# - name: golangci-lint
# uses: golangci/golangci-lint-action@v3
# with:
# version: v1.41

releaser-test:
runs-on: ubuntu-latest
Expand Down
16 changes: 8 additions & 8 deletions examples/go-containerregistry-auth/go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
module github.com/mozillazg/docker-credential-acr-helper/examples/go-containerregistry-auth

go 1.17
go 1.18

require (
github.com/google/go-containerregistry v0.9.0
github.com/mozillazg/docker-credential-acr-helper v0.0.0
)

require (
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/alibabacloudsdkgo/helper v0.2.0 // indirect
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider v0.14.0 // indirect
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 // indirect
github.com/alibabacloud-go/cr-20160607 v1.0.1 // indirect
github.com/alibabacloud-go/cr-20181201 v1.0.10 // indirect
Expand All @@ -19,13 +19,13 @@ require (
github.com/alibabacloud-go/tea v1.1.18 // indirect
github.com/alibabacloud-go/tea-utils v1.4.4 // indirect
github.com/alibabacloud-go/tea-xml v1.1.2 // indirect
github.com/aliyun/credentials-go v1.2.3 // indirect
github.com/aliyun/credentials-go v1.3.2 // indirect
github.com/clbanning/mxj/v2 v2.5.6 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.11.4 // indirect
github.com/docker/cli v20.10.16+incompatible // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v20.10.16+incompatible // indirect
github.com/docker/docker-credential-helpers v0.6.4 // indirect
github.com/docker/docker-credential-helpers v0.8.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/klauspost/compress v1.15.4 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
Expand All @@ -34,12 +34,12 @@ require (
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.0.3-0.20220114050600-8b9d41f48198 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
github.com/vbatts/tar-split v0.11.2 // indirect
golang.org/x/net v0.0.0-20220516155154-20f960328961 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.13.0 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
)

Expand Down
144 changes: 36 additions & 108 deletions examples/go-containerregistry-auth/go.sum

Large diffs are not rendered by default.

7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
module github.com/mozillazg/docker-credential-acr-helper

go 1.17
go 1.18

require (
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/alibabacloudsdkgo/helper v0.2.0
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider v0.14.0
github.com/alibabacloud-go/cr-20160607 v1.0.1
github.com/alibabacloud-go/cr-20181201 v1.0.10
github.com/alibabacloud-go/darabonba-openapi v0.1.18
github.com/alibabacloud-go/tea v1.1.18
github.com/alibabacloud-go/tea-utils v1.4.4
github.com/aliyun/credentials-go v1.3.2
github.com/docker/docker-credential-helpers v0.6.4
github.com/docker/docker-credential-helpers v0.8.0
github.com/sirupsen/logrus v1.9.3
)

Expand All @@ -26,6 +26,7 @@ require (
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/tjfoc/gmsm v1.3.2 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.18.0 // indirect
gopkg.in/ini.v1 v1.56.0 // indirect
)
20 changes: 6 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/alibabacloudsdkgo/helper v0.2.0 h1:8+4G8JaejP8Xa6W46PzJEwisNgBXMvFcz78N6zG/ARw=
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/alibabacloudsdkgo/helper v0.2.0/go.mod h1:GgeIE+1be8Ivm7Sh4RgwI42aTtC9qrcj+Y9Y6CjJhJs=
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider v0.14.0 h1:kcnfY4vljxXliXDBrA9K9lwF8IoEZ4Up6Eg9kWTIm28=
github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider v0.14.0/go.mod h1:tlqp9mUGbsP+0z3Q+c0Q5MgSdq/OMwQhm5bffR3Q3ss=
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.2/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4 h1:iC9YFYKDGEy3n/FtqJnOkZsene9olVspKmkX5A2YBEo=
github.com/alibabacloud-go/alibabacloud-gateway-spi v0.0.4/go.mod h1:sCavSAvdzOjul4cEqeVtvlSaSScfNsTQ+46HwlTL1hc=
Expand Down Expand Up @@ -36,17 +36,15 @@ github.com/alibabacloud-go/tea-utils v1.4.4/go.mod h1:KNcT0oXlZZxOXINnZBs6YvgOd5
github.com/alibabacloud-go/tea-xml v1.1.2 h1:oLxa7JUXm2EDFzMg+7oRsYc+kutgCVwm+bZlhhmvW5M=
github.com/alibabacloud-go/tea-xml v1.1.2/go.mod h1:Rq08vgCcCAjHyRi/M7xlHKUykZCEtyBy9+DPF6GgEu8=
github.com/aliyun/credentials-go v1.1.2/go.mod h1:ozcZaMR5kLM7pwtCMEpVmQ242suV6qTJya2bDq4X1Tw=
github.com/aliyun/credentials-go v1.2.3/go.mod h1:/KowD1cfGSLrLsH28Jr8W+xwoId0ywIy5lNzDz6O1vw=
github.com/aliyun/credentials-go v1.3.2 h1:L4WppI9rctC8PdlMgyTkF8bBsy9pyKQEzBD1bHMRl+g=
github.com/aliyun/credentials-go v1.3.2/go.mod h1:tlpz4uys4Rn7Ik4/piGRrTbXy2uLKvePgQJJduE+Y5c=
github.com/clbanning/mxj/v2 v2.5.6 h1:Jm4VaCI/+Ug5Q57IzEoZbwx4iQFA6wkXv72juUSeK+g=
github.com/clbanning/mxj/v2 v2.5.6/go.mod h1:hNiWqW14h+kc+MdF9C6/YoRfjEJoR3ou6tn/Qo+ve2s=
github.com/danieljoos/wincred v1.1.0/go.mod h1:XYlo+eRTsVA9aHGp7NGjFkPla4m+DCL7hqDjlFjiygg=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/docker/docker-credential-helpers v0.6.4 h1:axCks+yV+2MR3/kZhAmy07yC56WZ2Pwu/fKWtKuZB0o=
github.com/docker/docker-credential-helpers v0.6.4/go.mod h1:ofX3UI0Gz1TteYBjtgs07O36Pyasyp66D2uKT7H8W1c=
github.com/docker/docker-credential-helpers v0.8.0 h1:YQFtbBQb4VrpoPxhFuzEBPQ9E16qz5SpHLS+uswaCp8=
github.com/docker/docker-credential-helpers v0.8.0/go.mod h1:UGFXcuoQ5TxPiB54nHOZ32AWRqQdECoh/Mg0AlEYb40=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherjs v0.0.0-20200217142428-fce0ec30dd00 h1:l5lAOZEym3oK3SQ2HBHWsJUfbNBiTXJDeW2QDxw9AQ0=
Expand Down Expand Up @@ -89,8 +87,6 @@ golang.org/x/crypto v0.0.0-20191219195013-becbf705a915/go.mod h1:LzIPMQfyMNhhGPh
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
Expand All @@ -104,45 +100,41 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200509044756-6aff5f38e54f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U=
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
golang.org/x/term v0.18.0/go.mod h1:ILwASektA3OnRv7amZ1xhE/KTR+u50pbXfZ03+6Nx58=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
Expand Down
7 changes: 4 additions & 3 deletions pkg/acr/client.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package acr

import (
"github.com/sirupsen/logrus"
"time"
)

Expand All @@ -12,14 +13,14 @@ type Credentials struct {
ExpireTime time.Time
}

func (c *Client) GetCredentials(serverURL string) (*Credentials, error) {
func (c *Client) GetCredentials(serverURL string, logger *logrus.Logger) (*Credentials, error) {
registry, err := parseServerURL(serverURL)
if err != nil {
return nil, err
}

if registry.IsEE {
client, err := newEEClient(registry.Region)
client, err := newEEClient(registry.Region, logger)
if err != nil {
return nil, err
}
Expand All @@ -33,7 +34,7 @@ func (c *Client) GetCredentials(serverURL string) (*Credentials, error) {
return client.getCredentials(registry.InstanceId)
}

client, err := newPersonClient(registry.Region)
client, err := newPersonClient(registry.Region, logger)
if err != nil {
return nil, err
}
Expand Down
15 changes: 9 additions & 6 deletions pkg/acr/ee.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acr

import (
"fmt"
"github.com/sirupsen/logrus"
"time"

cr2018 "github.com/alibabacloud-go/cr-20181201/client"
Expand All @@ -14,8 +15,8 @@ type eeClient struct {
client *cr2018.Client
}

func newEEClient(region string) (*eeClient, error) {
cred, err := getOpenapiAuth()
func newEEClient(region string, logger *logrus.Logger) (*eeClient, error) {
cred, err := getOpenapiAuth(logger)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -46,11 +47,13 @@ func (c *eeClient) getInstanceId(instanceName string) (string, error) {
return "", fmt.Errorf("get ACR EE instance id for name %q failed: %s", instanceName, resp.Body.String())
}
instances := resp.Body.Instances
if len(instances) == 0 {
return "", fmt.Errorf("get ACR EE instance id for name %q failed: instance name is not found", instanceName)
for _, item := range instances {
if tea.StringValue(item.InstanceName) == instanceName {
return tea.StringValue(item.InstanceId), nil
}
}

return tea.StringValue(instances[0].InstanceId), nil
return "", fmt.Errorf("get ACR EE instance id for name %q failed: instance name is not found", instanceName)
}

func (c *eeClient) getCredentials(instanceId string) (*Credentials, error) {
Expand All @@ -73,7 +76,7 @@ func (c *eeClient) getCredentials(instanceId string) (*Credentials, error) {
cred := &Credentials{
UserName: tea.StringValue(resp.Body.TempUsername),
Password: tea.StringValue(resp.Body.AuthorizationToken),
ExpireTime: expTime,
ExpireTime: expTime.Add(-time.Minute),
}
return cred, nil
}
62 changes: 55 additions & 7 deletions pkg/acr/openapiauth.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
package acr

import (
"github.com/sirupsen/logrus"
"os"
"path/filepath"
"time"

"github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/alibabacloudsdkgo/helper"
"github.com/AliyunContainerService/ack-ram-tool/pkg/credentials/provider"
"github.com/aliyun/credentials-go/credentials"
"github.com/mozillazg/docker-credential-acr-helper/pkg/version"
)

var defaultProfilePath = filepath.Join("~", ".alibabacloud", "credentials")

func getOpenapiAuth() (credentials.Credential, error) {
type credentialForV2SDK struct {
*provider.CredentialForV2SDK
}

type logWrapper struct {
logger *logrus.Logger
}

func getOpenapiAuth(logger *logrus.Logger) (credentials.Credential, error) {
profilePath := defaultProfilePath
if os.Getenv(credentials.ENVCredentialFile) != "" {
profilePath = os.Getenv(credentials.ENVCredentialFile)
Expand All @@ -20,18 +29,57 @@ func getOpenapiAuth() (credentials.Credential, error) {
if err == nil {
if _, err := os.Stat(path); err == nil {
_ = os.Setenv(credentials.ENVCredentialFile, path)
return credentials.NewCredential(nil)
}
}
var conf *credentials.Config

if helper.HaveOidcCredentialRequiredEnv() {
return helper.NewOidcCredential(version.ProjectName)
cp := provider.NewDefaultChainProvider(provider.DefaultChainProviderOptions{
Logger: &logWrapper{logger: logger},
})
cred := &credentialForV2SDK{
CredentialForV2SDK: provider.NewCredentialForV2SDK(cp, provider.CredentialForV2SDKOptions{
CredentialRetrievalTimeout: time.Second * 30,
Logger: &logWrapper{logger: logger},
}),
}

cred, err := credentials.NewCredential(conf)
return cred, err
}

func (c *credentialForV2SDK) GetCredential() (*credentials.CredentialModel, error) {
ak, err := c.GetAccessKeyId()
if err != nil {
return nil, err
}
sk, err := c.GetAccessKeySecret()
if err != nil {
return nil, err
}
token, err := c.GetSecurityToken()
if err != nil {
return nil, err
}
return &credentials.CredentialModel{
AccessKeyId: ak,
AccessKeySecret: sk,
SecurityToken: token,
BearerToken: nil,
Type: c.GetType(),
}, err
}

func (l *logWrapper) Info(msg string) {
l.logger.Debug(msg)
}

func (l *logWrapper) Debug(msg string) {
l.logger.Debug(msg)
}

func (l *logWrapper) Error(err error, msg string) {
l.logger.WithError(err).Error(msg)
}

func expandPath(path string) (string, error) {
if len(path) > 0 && path[0] == '~' {
home, err := os.UserHomeDir()
Expand Down
5 changes: 3 additions & 2 deletions pkg/acr/person.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package acr

import (
"fmt"
"github.com/sirupsen/logrus"
"time"

cr2016 "github.com/alibabacloud-go/cr-20160607/client"
Expand All @@ -15,8 +16,8 @@ type personClient struct {
client *cr2016.Client
}

func newPersonClient(region string) (*personClient, error) {
cred, err := getOpenapiAuth()
func newPersonClient(region string, logger *logrus.Logger) (*personClient, error) {
cred, err := getOpenapiAuth(logger)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/credhelper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (a *ACRHelper) WithLoggerOut(w io.Writer) *ACRHelper {

func (a *ACRHelper) Get(serverURL string) (string, string, error) {
// TODO: add cache
cred, err := a.client.GetCredentials(serverURL)
cred, err := a.client.GetCredentials(serverURL, a.logger)
if err != nil {
a.logger.WithField("name", version.ProjectName).
WithField("serverURL", serverURL).
Expand Down

0 comments on commit b0f30d6

Please sign in to comment.