Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(server): add compatibility check API #128

Merged
merged 1 commit into from
Apr 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions cmd/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,15 @@ func SchemaCmd() *cobra.Command {
$ stencil schema version
$ stencil schema graph
$ stencil schema print
$ stencil schema check
`),
Annotations: map[string]string{
"group:core": "true",
},
}

cmd.AddCommand(createSchemaCmd())
cmd.AddCommand(checkSchemaCmd())
cmd.AddCommand(listSchemaCmd())
cmd.AddCommand(getSchemaCmd())
cmd.AddCommand(updateSchemaCmd())
Expand Down Expand Up @@ -197,6 +199,69 @@ func createSchemaCmd() *cobra.Command {
return cmd
}

func checkSchemaCmd() *cobra.Command {
var host, comp, filePath, namespaceID string
var req stencilv1beta1.CheckCompatibilityRequest

cmd := &cobra.Command{
Use: "check",
Short: "Check schema compatibility",
Args: cobra.ExactArgs(1),
Example: heredoc.Doc(`
$ stencil schema check <schema-id> --namespace=<namespace-id> comp=<schema-compatibility> filePath=<schema-filePath>
`),
Annotations: map[string]string{
"group:core": "true",
},
RunE: func(cmd *cobra.Command, args []string) error {
spinner := printer.Spin("")
defer spinner.Stop()

fileData, err := ioutil.ReadFile(filePath)
if err != nil {
return err
}
req.Data = fileData

conn, err := grpc.Dial(host, grpc.WithInsecure())
if err != nil {
return err
}
defer conn.Close()
schemaID := args[0]

req.NamespaceId = namespaceID
req.SchemaId = schemaID
req.Compatibility = stencilv1beta1.Schema_Compatibility(stencilv1beta1.Schema_Compatibility_value[comp])

client := stencilv1beta1.NewStencilServiceClient(conn)
_, err = client.CheckCompatibility(context.Background(), &req)
if err != nil {
errStatus := status.Convert(err)
return errors.New(errStatus.Message())
}

spinner.Stop()
fmt.Println("schema is compatible")
return nil
},
}

cmd.Flags().StringVar(&host, "host", "", "stencil host address eg: localhost:8000")
cmd.MarkFlagRequired("host")

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(&filePath, "filePath", "F", "", "path to the schema file")
cmd.MarkFlagRequired("filePath")

return cmd
}

func updateSchemaCmd() *cobra.Command {
var host, comp, namespaceID string
var req stencilv1beta1.UpdateSchemaMetadataRequest
Expand Down
2 changes: 1 addition & 1 deletion mocks/CompatibilityFn.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/NamespaceRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/NamespaceService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/ParsedSchema.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/SchemaProvider.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/SchemaRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion mocks/SchemaService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 14 additions & 12 deletions mocks/SearchRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/SearchService.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 61 additions & 1 deletion mocks/StencilServiceClient.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 47 additions & 1 deletion mocks/StencilServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/Store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/UnsafeStencilServiceServer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/ValidationStrategy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/errHandleFunc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mocks/getSchemaData.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions mocks/isSearchRequest_Version.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading