-
Notifications
You must be signed in to change notification settings - Fork 31
/
main.go
108 lines (91 loc) · 2.66 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
// 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"
)
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 keys
respGet, err := mgClient.ListKeys(ctx, projectID)
if err != nil {
fmt.Printf("ListKeys failed. Err: %v\n", err)
os.Exit(1)
}
for _, item := range respGet.APIKeys {
id := item.APIKey.APIKeyID
comment := item.APIKey.Comment
fmt.Printf("ListKeys() - ID: %s, Comment: %s\n", id, comment)
}
// create key
respCreate, err := mgClient.CreateKey(ctx, projectID, &interfaces.KeyCreateRequest{
Comment: "My Test",
Scopes: []string{"onprem:products"},
})
if err != nil {
fmt.Printf("CreateKey failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("CreateKey() - Name: %s\n", respCreate.Comment)
// list keys
respGet, err = mgClient.ListKeys(ctx, projectID)
if err != nil {
fmt.Printf("ListKeys failed. Err: %v\n", err)
os.Exit(1)
}
for _, item := range respGet.APIKeys {
id := item.APIKey.APIKeyID
comment := item.APIKey.Comment
fmt.Printf("ListKeys() - ID: %s, Comment: %s\n", id, comment)
}
// get key
respKey, err := mgClient.GetKey(ctx, projectID, respCreate.APIKeyID)
if err != nil {
fmt.Printf("GetKey failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("GetKey() - ID: %s, Comment: %s\n", respKey.APIKey.APIKeyID, respKey.APIKey.Comment)
// delete key
respMessage, err := mgClient.DeleteKey(ctx, projectID, respKey.APIKey.APIKeyID)
if err != nil {
fmt.Printf("DeleteKey failed. Err: %v\n", err)
os.Exit(1)
}
fmt.Printf("DeleteKey() - Name: %s\n", respMessage.Message)
// list keys
respGet, err = mgClient.ListKeys(ctx, projectID)
if err != nil {
fmt.Printf("ListKeys failed. Err: %v\n", err)
os.Exit(1)
}
for _, item := range respGet.APIKeys {
id := item.APIKey.APIKeyID
comment := item.APIKey.Comment
fmt.Printf("ListKeys() - ID: %s, Comment: %s\n", id, comment)
}
}