-
Notifications
You must be signed in to change notification settings - Fork 1
/
namespaceDelete.go
69 lines (55 loc) · 1.44 KB
/
namespaceDelete.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
package namespace
import (
"context"
"fmt"
"strings"
"github.com/clintjedwards/gofer/internal/cli/cl"
proto "github.com/clintjedwards/gofer/proto/go"
"github.com/spf13/cobra"
"google.golang.org/grpc/metadata"
)
var cmdNamespaceDelete = &cobra.Command{
Use: "delete <id>",
Short: "Delete namespace",
Long: `Delete namespace.`,
Example: `$ gofer namespace delete my_namespace`,
RunE: namespaceDelete,
Args: cobra.ExactArgs(1),
}
func init() {
CmdNamespace.AddCommand(cmdNamespaceDelete)
}
func namespaceDelete(_ *cobra.Command, args []string) error {
id := args[0]
cl.State.Fmt.Print("Deleting namespace")
cl.State.Fmt.Finish()
var input string
for {
fmt.Print("Please type the ID of the namespace to confirm: ")
fmt.Scanln(&input)
if strings.EqualFold(input, id) {
break
}
}
cl.State.NewFormatter()
conn, err := cl.State.Connect()
if err != nil {
cl.State.Fmt.PrintErr(err)
cl.State.Fmt.Finish()
return err
}
client := proto.NewGoferClient(conn)
md := metadata.Pairs("Authorization", "Bearer "+cl.State.Config.Token)
ctx := metadata.NewOutgoingContext(context.Background(), md)
_, err = client.DeleteNamespace(ctx, &proto.DeleteNamespaceRequest{
Id: id,
})
if err != nil {
cl.State.Fmt.PrintErr(fmt.Sprintf("could not delete namespace: %v", err))
cl.State.Fmt.Finish()
return err
}
cl.State.Fmt.PrintSuccess(fmt.Sprintf("Deleted namespace %q", id))
cl.State.Fmt.Finish()
return nil
}