Skip to content

Commit

Permalink
CR-11767 get isc repo (#435)
Browse files Browse the repository at this point in the history
* GetSharedConfigRepo

* bump

* usersV2

* fix interface name

* get current
  • Loading branch information
rotem-codefresh authored Jun 12, 2022
1 parent a8fdc8e commit 0a97362
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 2 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.43.10
0.43.11
2 changes: 1 addition & 1 deletion pkg/codefresh/argo_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,4 +270,4 @@ func (r *argoRuntime) SetSharedConfigRepo(ctx context.Context, suggestedSharedCo
}

return res.Data.SuggestIscRepo, nil
}
}
5 changes: 5 additions & 0 deletions pkg/codefresh/codefresh.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type (
}

V2API interface {
UsersV2() IUsersV2API
Runtime() IRuntimeAPI
Cluster() IClusterV2API
GitSource() IGitSourceAPI
Expand Down Expand Up @@ -65,6 +66,10 @@ func (c *codefresh) Users() UsersAPI {
return newUsersAPI(c)
}

func (c *codefresh) UsersV2() IUsersV2API {
return newUsersV2API(c)
}

func (c *codefresh) Tokens() ITokenAPI {
return newTokenAPI(c)
}
Expand Down
65 changes: 65 additions & 0 deletions pkg/codefresh/users_v2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package codefresh

import (
"context"
"fmt"

"github.com/codefresh-io/go-sdk/pkg/codefresh/model"
)

type (
IUsersV2API interface {
GetCurrent(ctx context.Context) (*model.User, error)
}

usersV2 struct {
*codefresh
}

graphQlMeResponse struct {
Data struct {
Me model.User
}
Errors []graphqlError
}
)

func newUsersV2API(codefresh *codefresh) IUsersV2API {
return &usersV2{codefresh}
}

func (u *usersV2) GetCurrent(ctx context.Context) (*model.User, error) {
jsonData := map[string]interface{}{
"query": `{
me {
id
name
email
isAdmin
accounts {
id
name
}
activeAccount {
id
name
sharedConfigRepo
}
}
}
`,
}

res := &graphQlMeResponse{}
err := u.codefresh.graphqlAPI(ctx, jsonData, res)

if err != nil {
return nil, fmt.Errorf("failed making a graphql API call while getting user info: %w", err)
}

if len(res.Errors) > 0 {
return nil, graphqlErrorResponse{errors: res.Errors}
}

return &res.Data.Me, nil
}

0 comments on commit 0a97362

Please sign in to comment.