-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathmain.go
138 lines (117 loc) · 3.39 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 2023-2024 Deepgram SDK contributors. All Rights Reserved.
// Use of this source code is governed by a MIT license that can be found in the LICENSE file.
// SPDX-License-Identifier: MIT
package main
import (
"context"
"fmt"
"os"
api "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1"
interfaces "github.com/deepgram/deepgram-go-sdk/pkg/api/manage/v1/interfaces"
client "github.com/deepgram/deepgram-go-sdk/pkg/client/manage"
)
const (
TestAccountName = "[email protected]"
)
func main() {
// init library
client.InitWithDefault()
// context
ctx := context.Background()
//client
dg := client.NewWithDefaults()
mgClient := api.New(dg)
// list projects
respList, err := mgClient.ListProjects(ctx)
if err != nil {
fmt.Printf("ListProjects failed. Err: %v\n", err)
os.Exit(1)
}
var projectID string
for _, item := range respList.Projects {
projectID = item.ProjectID
name := item.Name
fmt.Printf("ListProjects() - Name: %s, ID: %s\n", name, projectID)
break
}
// list members
respGet, err := mgClient.ListMembers(ctx, projectID)
if err != nil {
fmt.Printf("ListMembers failed. Err: %v\n", err)
os.Exit(1)
}
var updateID string
for _, item := range respGet.Members {
memberID := item.MemberID
email := item.Email
fmt.Printf("ListMembers() - ID: %s, Scope: %s\n", memberID, email)
for _, scope := range item.Scopes {
fmt.Printf("Scope: %s\n", scope)
}
if email == TestAccountName {
updateID = memberID
}
}
if updateID == "" {
fmt.Printf("This example requires a member who already email is %s.\n", TestAccountName)
fmt.Printf("This is required to exercise the RemoveMember function.\n")
fmt.Printf("In the absence of this, this example will exit early.\n")
os.Exit(0)
}
// get scope
respScope, err := mgClient.GetMemberScopes(ctx, projectID, updateID)
if err != nil {
fmt.Printf("GetMemberScopes failed. Err: %v\n", err)
os.Exit(1)
}
scope := respScope.Scopes
for _, item := range scope {
fmt.Printf("GetMemberScopes() - Scope: %s\n", item)
}
// update scope
respMessage, err := mgClient.UpdateMemberScopes(ctx, projectID, updateID, &interfaces.ScopeUpdateRequest{
Scope: "admin",
})
if err != nil {
fmt.Printf("UpdateMemberScopes failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("UpdateMemberScopes() - Name: %s\n", respMessage.Message)
// list members
respGet, err = mgClient.ListMembers(ctx, projectID)
if err != nil {
fmt.Printf("ListMembers failed. Err: %v\n", err)
os.Exit(1)
}
for _, item := range respGet.Members {
memberID := item.MemberID
email := item.Email
fmt.Printf("ListMembers() - ID: %s, Scope: %s\n", memberID, email)
for _, scope := range item.Scopes {
fmt.Printf("Scope: %s\n", scope)
}
}
// update scope
respMessage, err = mgClient.UpdateMemberScopes(ctx, projectID, updateID, &interfaces.ScopeUpdateRequest{
Scope: "member",
})
if err != nil {
fmt.Printf("UpdateMemberScopes failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("UpdateMemberScopes() - Name: %s\n", respMessage.Message)
// list members
respGet, err = mgClient.ListMembers(ctx, projectID)
if err != nil {
fmt.Printf("ListMembers failed. Err: %v\n", err)
os.Exit(1)
}
for _, item := range respGet.Members {
memberID := item.MemberID
email := item.Email
fmt.Printf("ListMembers() - ID: %s, Scope: %s\n", memberID, email)
for _, scope := range item.Scopes {
fmt.Printf("Scope: %s\n", scope)
}
}
}