-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathcheck.go
More file actions
74 lines (60 loc) · 1.87 KB
/
check.go
File metadata and controls
74 lines (60 loc) · 1.87 KB
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
package cmd
import (
"context"
"errors"
"fmt"
"os"
"github.com/MakeNowJust/heredoc"
"github.com/raystack/salt/cli/printer"
stencilv1beta1 "github.com/raystack/stencil/proto/raystack/stencil/v1beta1"
"github.com/spf13/cobra"
"google.golang.org/grpc/status"
)
func checkSchemaCmd(cdk *CDK) *cobra.Command {
var comp, file, namespaceID string
var req stencilv1beta1.CheckCompatibilityRequest
cmd := &cobra.Command{
Use: "check <id>",
Args: cobra.ExactArgs(1),
Short: "Check schema compatibility",
Long: heredoc.Doc(`
Check schema compatibility of a local schema
against a remote schema(against) on stencil server.`),
Example: heredoc.Doc(`
$ stencil schema check <id> -n raystack -c COMPATIBILITY_BACKWARD -F ./booking.desc
`),
RunE: func(cmd *cobra.Command, args []string) error {
spinner := printer.Spin("")
defer spinner.Stop()
fileData, err := os.ReadFile(file)
if err != nil {
return err
}
client, cancel, err := createClient(cmd, cdk)
if err != nil {
return err
}
defer cancel()
schemaID := args[0]
req.Data = fileData
req.NamespaceId = namespaceID
req.SchemaId = schemaID
req.Compatibility = stencilv1beta1.Schema_Compatibility(stencilv1beta1.Schema_Compatibility_value[comp])
_, err = client.CheckCompatibility(context.Background(), &req)
if err != nil {
errStatus := status.Convert(err)
return errors.New(errStatus.Message())
}
spinner.Stop()
fmt.Printf("\n%s Schema is compatible.\n", printer.Green(printer.Icon("success")))
return nil
},
}
cmd.Flags().StringVarP(&namespaceID, "namespace", "n", "", "Parent namespace ID")
cmd.MarkFlagRequired("namespace")
cmd.Flags().StringVarP(&comp, "comp", "c", "", "Schema compatibility")
cmd.MarkFlagRequired("comp")
cmd.Flags().StringVarP(&file, "file", "F", "", "Path to the schema file")
cmd.MarkFlagRequired("file")
return cmd
}