-
Notifications
You must be signed in to change notification settings - Fork 24
/
manifest.go
100 lines (78 loc) · 1.93 KB
/
manifest.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
package cmd
import (
"io"
"os"
"github.com/aserto-dev/topaz/pkg/cli/cc"
"github.com/aserto-dev/topaz/pkg/cli/clients"
"github.com/fatih/color"
)
type ManifestCmd struct {
Get GetManifestCmd `cmd:"" help:"get manifest"`
Set SetManifestCmd `cmd:"" help:"set manifest"`
Delete DeleteManifestCmd `cmd:"" help:"delete manifest"`
}
type GetManifestCmd struct {
Path string `arg:"path" help:"filepath to manifest file" type:"path" optional:""`
Stdout bool `flag:"" help:"output manifest to --stdout"`
clients.Config
}
type SetManifestCmd struct {
Path string `arg:"" help:"filepath to assertions file" type:"path" optional:""`
Stdin bool `flag:"" help:"set manifest from --stdin"`
clients.Config
}
type DeleteManifestCmd struct {
clients.Config
}
func (cmd *GetManifestCmd) Run(c *cc.CommonCtx) error {
if err := CheckRunning(c); err != nil {
return err
}
dirClient, err := clients.NewDirectoryClient(c, &cmd.Config)
if err != nil {
return err
}
color.Green(">>> get manifest to %s", cmd.Path)
r, err := dirClient.V3.GetManifest(c.Context)
if err != nil {
return err
}
w := os.Stdout
if cmd.Path != "" {
w, err = os.Create(cmd.Path)
if err != nil {
return err
}
}
defer w.Close()
if _, err := io.Copy(w, r); err != nil {
return err
}
return nil
}
func (cmd *SetManifestCmd) Run(c *cc.CommonCtx) error {
if err := CheckRunning(c); err != nil {
return err
}
dirClient, err := clients.NewDirectoryClient(c, &cmd.Config)
if err != nil {
return err
}
r := os.Stdin
if cmd.Path != "" {
r, err = os.Open(cmd.Path)
if err != nil {
return err
}
}
color.Green(">>> set manifest from %s", cmd.Path)
return dirClient.V3.SetManifest(c.Context, r)
}
func (cmd *DeleteManifestCmd) Run(c *cc.CommonCtx) error {
dirClient, err := clients.NewDirectoryClient(c, &cmd.Config)
if err != nil {
return err
}
color.Green(">>> delete manifest")
return dirClient.V3.DeleteManifest(c.Context)
}