Skip to content

Commit a5dc33e

Browse files
authored
feat(server): add compatibility check API (#128)
1 parent 0032c59 commit a5dc33e

27 files changed

+869
-436
lines changed

cmd/schema.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ func SchemaCmd() *cobra.Command {
4545
$ stencil schema version
4646
$ stencil schema graph
4747
$ stencil schema print
48+
$ stencil schema check
4849
`),
4950
Annotations: map[string]string{
5051
"group:core": "true",
5152
},
5253
}
5354

5455
cmd.AddCommand(createSchemaCmd())
56+
cmd.AddCommand(checkSchemaCmd())
5557
cmd.AddCommand(listSchemaCmd())
5658
cmd.AddCommand(getSchemaCmd())
5759
cmd.AddCommand(updateSchemaCmd())
@@ -197,6 +199,69 @@ func createSchemaCmd() *cobra.Command {
197199
return cmd
198200
}
199201

202+
func checkSchemaCmd() *cobra.Command {
203+
var host, comp, filePath, namespaceID string
204+
var req stencilv1beta1.CheckCompatibilityRequest
205+
206+
cmd := &cobra.Command{
207+
Use: "check",
208+
Short: "Check schema compatibility",
209+
Args: cobra.ExactArgs(1),
210+
Example: heredoc.Doc(`
211+
$ stencil schema check <schema-id> --namespace=<namespace-id> comp=<schema-compatibility> filePath=<schema-filePath>
212+
`),
213+
Annotations: map[string]string{
214+
"group:core": "true",
215+
},
216+
RunE: func(cmd *cobra.Command, args []string) error {
217+
spinner := printer.Spin("")
218+
defer spinner.Stop()
219+
220+
fileData, err := ioutil.ReadFile(filePath)
221+
if err != nil {
222+
return err
223+
}
224+
req.Data = fileData
225+
226+
conn, err := grpc.Dial(host, grpc.WithInsecure())
227+
if err != nil {
228+
return err
229+
}
230+
defer conn.Close()
231+
schemaID := args[0]
232+
233+
req.NamespaceId = namespaceID
234+
req.SchemaId = schemaID
235+
req.Compatibility = stencilv1beta1.Schema_Compatibility(stencilv1beta1.Schema_Compatibility_value[comp])
236+
237+
client := stencilv1beta1.NewStencilServiceClient(conn)
238+
_, err = client.CheckCompatibility(context.Background(), &req)
239+
if err != nil {
240+
errStatus := status.Convert(err)
241+
return errors.New(errStatus.Message())
242+
}
243+
244+
spinner.Stop()
245+
fmt.Println("schema is compatible")
246+
return nil
247+
},
248+
}
249+
250+
cmd.Flags().StringVar(&host, "host", "", "stencil host address eg: localhost:8000")
251+
cmd.MarkFlagRequired("host")
252+
253+
cmd.Flags().StringVarP(&namespaceID, "namespace", "n", "", "parent namespace ID")
254+
cmd.MarkFlagRequired("namespace")
255+
256+
cmd.Flags().StringVarP(&comp, "comp", "c", "", "schema compatibility")
257+
cmd.MarkFlagRequired("comp")
258+
259+
cmd.Flags().StringVarP(&filePath, "filePath", "F", "", "path to the schema file")
260+
cmd.MarkFlagRequired("filePath")
261+
262+
return cmd
263+
}
264+
200265
func updateSchemaCmd() *cobra.Command {
201266
var host, comp, namespaceID string
202267
var req stencilv1beta1.UpdateSchemaMetadataRequest

mocks/CompatibilityFn.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/NamespaceRepository.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/NamespaceService.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/ParsedSchema.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/SchemaProvider.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/SchemaRepository.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/SchemaService.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/SearchRepository.go

Lines changed: 14 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

mocks/SearchService.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)