Skip to content

Commit 4519113

Browse files
authored
Merge pull request #16 from cto-ai/feat/sdk-team
PROD-1156 Feat: added Team() function
2 parents 0d97776 + d004b53 commit 4519113

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

sdk.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,32 @@ func (*Sdk) Log(message string) error {
311311
_, err := fmt.Printf(message)
312312
return err
313313
}
314+
315+
// TeamInfo contains user info returned by daemon.
316+
type TeamInfo struct {
317+
ID string `json:"id"`
318+
Name string `json:"name"`
319+
}
320+
321+
// Team returns the team info for the current user running the Op.
322+
func (*Sdk) Team() (TeamInfo, error) {
323+
var body interface{}
324+
method := "GET"
325+
result, err := daemon.SyncRequest("team", body, method)
326+
327+
if err != nil {
328+
return TeamInfo{}, fmt.Errorf("error getting team information: %w", err)
329+
}
330+
331+
// map results to TeamInfo
332+
mapValue := result.(map[string]interface{})
333+
teamInfo := TeamInfo{}
334+
if id, ok := mapValue["id"].(string); ok {
335+
teamInfo.ID = id
336+
}
337+
if name, ok := mapValue["name"].(string); ok {
338+
teamInfo.Name = name
339+
}
340+
341+
return teamInfo, nil
342+
}

0 commit comments

Comments
 (0)