-
Notifications
You must be signed in to change notification settings - Fork 1
/
id.go
55 lines (47 loc) · 1.04 KB
/
id.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
package main
import (
"fmt"
"io"
"log/slog"
"os"
"github.com/RealImage/bifrost"
"github.com/google/uuid"
"github.com/urfave/cli/v2"
)
var idCmd = &cli.Command{
Name: "identity",
Aliases: []string{"id"},
Flags: []cli.Flag{
nsFlag,
},
Action: func(cliCtx *cli.Context) error {
filename := cliCtx.Args().First()
var data []byte
var err error
switch filename {
case "", "-":
data, err = io.ReadAll(os.Stdin)
default:
data, err = os.ReadFile(filename)
}
if err != nil {
return err
}
id, err := bifrost.ParseIdentity(data)
if err != nil {
return cli.Exit(fmt.Sprintf("Error parsing file: %s", err), 1)
}
if id.Namespace == uuid.Nil && namespace == uuid.Nil {
return cli.Exit("Error: Namespace is required", 1)
}
if id.Namespace != uuid.Nil && namespace != uuid.Nil && id.Namespace != namespace {
return cli.Exit("Error: Namespace mismatch", 1)
}
if namespace != uuid.Nil {
id.Namespace = namespace
}
slog.Debug("using", "namespace", id.Namespace)
fmt.Println(id.UUID())
return nil
},
}