Skip to content

Commit 741b3c2

Browse files
Cr 15125 (#618)
* fix requested scopes msg * bump * move retry msg to debug * resolve comments * patch ut * fix msg * wip * wip * fix ut
1 parent 47fc700 commit 741b3c2

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.558
1+
VERSION=v0.0.559
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.558/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.559/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.558/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.559/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 2.1.1
8-
version: 0.0.558
8+
version: 0.0.559
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/git/provider_bitbucket.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ var (
5656
{"team", "team:write"},
5757
{"webhook"},
5858
}
59+
60+
scopesApiMap = map[string]string{
61+
"account:read account:write": "account:read",
62+
"repository:admin repository:write": "repository:write",
63+
"repository:admin": "repository:admin",
64+
"team team:write": "workspace membership:write (team:write)",
65+
"webhook": "webhook:read and write",
66+
}
5967
)
6068

6169
func NewBitbucketProvider(baseURL string, client *http.Client) (Provider, error) {
@@ -107,6 +115,7 @@ func (bb *bitbucket) verifyToken(ctx context.Context, token string, username str
107115
if err != nil {
108116
return fmt.Errorf("failed checking token scope permission: %w", err)
109117
}
118+
110119
for _, requiredScope := range requiredScopes {
111120
isScopeIncluded := false
112121
for _, scopeOpt := range requiredScope {
@@ -115,7 +124,8 @@ func (bb *bitbucket) verifyToken(ctx context.Context, token string, username str
115124
}
116125
}
117126
if !isScopeIncluded {
118-
return fmt.Errorf("the provided token is missing required token scopes, got: %s required: %v", scopes, requiredScopes)
127+
var requestedScopes = bb.getRequestedScopes(requiredScopes)
128+
return fmt.Errorf("the provided token is missing required token scopes, got: %s \nrequired: %v", scopes, requestedScopes)
119129
}
120130
}
121131

@@ -154,3 +164,29 @@ func (bb *bitbucket) request(ctx context.Context, username, token, method, urlPa
154164

155165
return bb.c.Do(req)
156166
}
167+
168+
func (bb *bitbucket) getRequestedScopes(requiredScopes [][]string) string {
169+
var requestedScopes string = ""
170+
171+
for _, requiredScopeOpts := range requiredScopes {
172+
var scopeOpts = ""
173+
for _, requiredScope := range requiredScopeOpts {
174+
if len(scopeOpts) > 0 {
175+
scopeOpts += " "
176+
}
177+
scopeOpts += requiredScope
178+
}
179+
180+
if len(requestedScopes) > 0 {
181+
requestedScopes += ", "
182+
}
183+
184+
if len(scopesApiMap[scopeOpts]) > 0 {
185+
requestedScopes += scopesApiMap[scopeOpts]
186+
} else {
187+
requestedScopes += scopeOpts
188+
}
189+
}
190+
191+
return requestedScopes
192+
}

pkg/git/provider_bitbucket_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func Test_bitbucket_verifyToken(t *testing.T) {
5757
},
5858
"Should fail if required scope is not in res header": {
5959
requiredScopes: [][]string{{"scope 3"}},
60-
wantErr: "the provided token is missing required token scopes, got: scope 1, scope 2 required: [[scope 3]]",
60+
wantErr: "the provided token is missing required token scopes, got: scope 1, scope 2 \nrequired: scope 3",
6161
beforeFn: func(t *testing.T, c *mocks.MockRoundTripper) {
6262
c.EXPECT().RoundTrip(gomock.AssignableToTypeOf(&http.Request{})).Times(1).DoAndReturn(func(_ *http.Request) (*http.Response, error) {
6363
header := http.Header{}

pkg/util/util.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,7 @@ func Retry(ctx context.Context, opts *RetryOptions) error {
365365
break
366366
}
367367

368-
log.G(ctx).WithFields(log.Fields{
369-
"retry": try,
370-
"err": err.Error(),
371-
}).Warn("Function call failed, trying again")
368+
log.G(ctx).Debug("retry: %s \n err: %s\n Function call failed, trying again", try, err.Error())
372369

373370
if opts.Sleep != 0 {
374371
time.Sleep(opts.Sleep)

0 commit comments

Comments
 (0)