-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* GetSharedConfigRepo * bump * usersV2 * fix interface name * get current
- Loading branch information
1 parent
a8fdc8e
commit 0a97362
Showing
4 changed files
with
72 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.43.10 | ||
0.43.11 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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 | ||
} |