Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PROD-1156 Feat: added Team() function #16

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,3 +311,32 @@ func (*Sdk) Log(message string) error {
_, err := fmt.Printf(message)
return err
}

// TeamInfo contains user info returned by daemon.
type TeamInfo struct {
ID string `json:"id"`
Name string `json:"name"`
}

// Team returns the team info for the current user running the Op.
func (*Sdk) Team() (TeamInfo, error) {
var body interface{}
method := "GET"
result, err := daemon.SyncRequest("team", body, method)

if err != nil {
return TeamInfo{}, fmt.Errorf("error getting team information: %w", err)
}

// map results to TeamInfo
mapValue := result.(map[string]interface{})
teamInfo := TeamInfo{}
if id, ok := mapValue["id"].(string); ok {
teamInfo.ID = id
}
if name, ok := mapValue["name"].(string); ok {
teamInfo.Name = name
}

return teamInfo, nil
}