-
Notifications
You must be signed in to change notification settings - Fork 124
/
schema.go
48 lines (35 loc) · 1.03 KB
/
schema.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
// Copyright 2021-2024 Zenauth Ltd.
// SPDX-License-Identifier: Apache-2.0
package schema
import (
"fmt"
"github.com/alecthomas/kong"
"github.com/cerbos/cerbos/cmd/cerbosctl/get/internal/flagset"
"github.com/cerbos/cerbos/cmd/cerbosctl/get/internal/schema"
"github.com/cerbos/cerbos/cmd/cerbosctl/internal/client"
)
const help = `# List schemas
cerbosctl get schemas
cerbosctl get schema
cerbosctl get s
# Get schema definition
cerbosctl get schemas principal.json`
type Cmd struct {
flagset.Format
SchemaIDs []string `arg:"" name:"id" optional:"" help:"list of schema ids to retrieve"` //nolint:revive
}
func (c *Cmd) Run(k *kong.Kong, ctx *client.Context) error {
if len(c.SchemaIDs) == 0 {
if err := schema.List(k, ctx.AdminClient, &c.Format); err != nil {
return fmt.Errorf("failed to list schemas: %w", err)
}
return nil
}
if err := schema.Get(k, ctx.AdminClient, &c.Format, c.SchemaIDs...); err != nil {
return fmt.Errorf("failed to get schemas: %w", err)
}
return nil
}
func (c *Cmd) Help() string {
return help
}