Skip to content

Commit 0a97362

Browse files
CR-11767 get isc repo (#435)
* GetSharedConfigRepo * bump * usersV2 * fix interface name * get current
1 parent a8fdc8e commit 0a97362

File tree

4 files changed

+72
-2
lines changed

4 files changed

+72
-2
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.43.10
1+
0.43.11

pkg/codefresh/argo_runtime.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,4 +270,4 @@ func (r *argoRuntime) SetSharedConfigRepo(ctx context.Context, suggestedSharedCo
270270
}
271271

272272
return res.Data.SuggestIscRepo, nil
273-
}
273+
}

pkg/codefresh/codefresh.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type (
3636
}
3737

3838
V2API interface {
39+
UsersV2() IUsersV2API
3940
Runtime() IRuntimeAPI
4041
Cluster() IClusterV2API
4142
GitSource() IGitSourceAPI
@@ -65,6 +66,10 @@ func (c *codefresh) Users() UsersAPI {
6566
return newUsersAPI(c)
6667
}
6768

69+
func (c *codefresh) UsersV2() IUsersV2API {
70+
return newUsersV2API(c)
71+
}
72+
6873
func (c *codefresh) Tokens() ITokenAPI {
6974
return newTokenAPI(c)
7075
}

pkg/codefresh/users_v2.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package codefresh
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
8+
)
9+
10+
type (
11+
IUsersV2API interface {
12+
GetCurrent(ctx context.Context) (*model.User, error)
13+
}
14+
15+
usersV2 struct {
16+
*codefresh
17+
}
18+
19+
graphQlMeResponse struct {
20+
Data struct {
21+
Me model.User
22+
}
23+
Errors []graphqlError
24+
}
25+
)
26+
27+
func newUsersV2API(codefresh *codefresh) IUsersV2API {
28+
return &usersV2{codefresh}
29+
}
30+
31+
func (u *usersV2) GetCurrent(ctx context.Context) (*model.User, error) {
32+
jsonData := map[string]interface{}{
33+
"query": `{
34+
me {
35+
id
36+
name
37+
email
38+
isAdmin
39+
accounts {
40+
id
41+
name
42+
}
43+
activeAccount {
44+
id
45+
name
46+
sharedConfigRepo
47+
}
48+
}
49+
}
50+
`,
51+
}
52+
53+
res := &graphQlMeResponse{}
54+
err := u.codefresh.graphqlAPI(ctx, jsonData, res)
55+
56+
if err != nil {
57+
return nil, fmt.Errorf("failed making a graphql API call while getting user info: %w", err)
58+
}
59+
60+
if len(res.Errors) > 0 {
61+
return nil, graphqlErrorResponse{errors: res.Errors}
62+
}
63+
64+
return &res.Data.Me, nil
65+
}

0 commit comments

Comments
 (0)