-
Notifications
You must be signed in to change notification settings - Fork 6
/
generate.go
45 lines (35 loc) · 998 Bytes
/
generate.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
package main
import (
"flag"
"fmt"
"log"
"github.com/tkhq/go-sdk/pkg/apikey"
"github.com/tkhq/go-sdk/pkg/store/local"
)
var (
keyName string
organizationID string
)
func init() {
flag.StringVar(&keyName, "name", "default", "name of API key")
flag.StringVar(&organizationID, "org", "", "organization ID of API key")
}
func main() {
flag.Parse()
if organizationID == "" {
log.Fatalln("organization ID must be set")
}
key, err := apikey.New(organizationID)
if err != nil {
log.Fatalln("failed to generate API key:", err)
}
if err = local.New[*apikey.Key, apikey.Metadata]().Store(keyName, key); err != nil {
log.Fatalln("failed to store new API key:", err)
}
if key, err = local.New[*apikey.Key, apikey.Metadata]().Load(keyName); err != nil {
log.Fatalln("failed to load new API key:", err)
}
fmt.Println("API Key successfully generated!")
fmt.Println("Now log into your Turnkey account and register this API key:")
fmt.Printf("\t%s\n", key.PublicKey)
}