Skip to content

Commit

Permalink
Merge pull request #917 from ripienaar/registry
Browse files Browse the repository at this point in the history
Adds a basic schema registry to be used to assist client developers
  • Loading branch information
ripienaar authored Nov 6, 2023
2 parents 2802493 + 965f985 commit 953c2a4
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 18 deletions.
1 change: 1 addition & 0 deletions cli/schema_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func configureSchemaCommand(app commandHost) {
configureSchemaInfoCommand(schema)
configureSchemaValidateCommand(schema)
configureSchemaReqCommand(schema)
configureSchemaRegistryCommand(schema)
}

func init() {
Expand Down
63 changes: 63 additions & 0 deletions cli/schema_registry_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright 2023 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cli

import (
"fmt"
"os"

"github.com/choria-io/fisk"
"github.com/nats-io/jsm.go/registry"
"github.com/nats-io/nats.go"
)

type schemaRegistryCmd struct {
nc *nats.Conn
prefix string
}

func configureSchemaRegistryCommand(schema *fisk.CmdClause) {
c := &schemaRegistryCmd{}

reg := schema.Command("registry", "Starts a Schema Registry Service").Hidden().Action(c.registryAction)
reg.Flag("prefix", "Subject prefix to host the service on").Default("nats.schema.registry").StringVar(&c.prefix)
}

func (c *schemaRegistryCmd) registryAction(_ *fisk.ParseContext) error {
var err error
c.nc, _, err = prepareHelper("", natsOpts()...)
if err != nil {
return fmt.Errorf("setup failed: %v", err)
}

reg, err := registry.New(c.nc, c.prefix, new(SchemaValidator), nil)
if err != nil {
return err
}

cols := newColumns("NATS CLI Schema Registry waiting for requests on %s", c.nc.ConnectedUrlRedacted())
cols.AddSectionTitle("Listening Subjects")
cols.AddRow(fmt.Sprintf("%s.validate", c.prefix), "Schema Validation")
cols.AddRow(fmt.Sprintf("%s.lookup", c.prefix), "Schema Lookup")
cols.AddRow(fmt.Sprintf("%s.jetstream", c.prefix), "JetStream Proxy")
cols.AddSectionTitle("Requests Log")
cols.Frender(os.Stdout)

err = reg.Start(ctx)
if err != nil {
return err
}

return nil
}
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/klauspost/compress v1.17.2
github.com/mattn/go-isatty v0.0.20
github.com/nats-io/jsm.go v0.1.1-0.20231031093634-09b45b142881
github.com/nats-io/jwt/v2 v2.5.2
github.com/nats-io/nats-server/v2 v2.10.4-0.20231030221728-5c3ddf3ca0e2
github.com/nats-io/jsm.go v0.1.1-0.20231106122128-a65f417ea9e5
github.com/nats-io/jwt/v2 v2.5.3
github.com/nats-io/nats-server/v2 v2.10.4-0.20231105183438-0b5d9c636cab
github.com/nats-io/nats.go v1.31.0
github.com/nats-io/nkeys v0.4.6
github.com/nats-io/nuid v1.0.1
Expand All @@ -47,9 +47,9 @@ require (
github.com/prometheus/procfs v0.12.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.4.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
24 changes: 12 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQ
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
github.com/minio/highwayhash v1.0.2 h1:Aak5U0nElisjDCfPSG79Tgzkn2gl66NxOMspRrKnA/g=
github.com/minio/highwayhash v1.0.2/go.mod h1:BQskDq+xkJ12lmlUUi7U0M5Swg3EWR+dLTk+kldvVxY=
github.com/nats-io/jsm.go v0.1.1-0.20231031093634-09b45b142881 h1:Km1JFmGI96Q3uxITk/OvgXQd5G9N6rfqlwuoiF1xT/I=
github.com/nats-io/jsm.go v0.1.1-0.20231031093634-09b45b142881/go.mod h1:qeMkf2tPESn1B4LxskvQKRZjvKhAs/MhTGdyCV1fWwA=
github.com/nats-io/jwt/v2 v2.5.2 h1:DhGH+nKt+wIkDxM6qnVSKjokq5t59AZV5HRcFW0zJwU=
github.com/nats-io/jwt/v2 v2.5.2/go.mod h1:24BeQtRwxRV8ruvC4CojXlx/WQ/VjuwlYiH+vu/+ibI=
github.com/nats-io/nats-server/v2 v2.10.4-0.20231030221728-5c3ddf3ca0e2 h1:x/XQH6e/OQXBTiGsUyHe4g5TC/KYB/4Ib3f04YT3PL0=
github.com/nats-io/nats-server/v2 v2.10.4-0.20231030221728-5c3ddf3ca0e2/go.mod h1:eWm2JmHP9Lqm2oemB6/XGi0/GwsZwtWf8HIPUsh+9ns=
github.com/nats-io/jsm.go v0.1.1-0.20231106122128-a65f417ea9e5 h1:AECOlfMkmjaNKiVPj2c/a/aBjwg3sa7Q2W/OfHGouws=
github.com/nats-io/jsm.go v0.1.1-0.20231106122128-a65f417ea9e5/go.mod h1:wI5mFrR5Wa1ggI09Zo5qfyrvpqcBuzVp7THC2KX1lI4=
github.com/nats-io/jwt/v2 v2.5.3 h1:/9SWvzc6hTfamcgXJ3uYRpgj+QuY2aLNqRiqrKcrpEo=
github.com/nats-io/jwt/v2 v2.5.3/go.mod h1:iysuPemFcc7p4IoYots3IuELSI4EDe9Y0bQMe+I3Bf4=
github.com/nats-io/nats-server/v2 v2.10.4-0.20231105183438-0b5d9c636cab h1:EMmEyTqqr1ba5f5DEeFPhdbcF41ZYcqEAVlOJ0/kDKc=
github.com/nats-io/nats-server/v2 v2.10.4-0.20231105183438-0b5d9c636cab/go.mod h1:eWm2JmHP9Lqm2oemB6/XGi0/GwsZwtWf8HIPUsh+9ns=
github.com/nats-io/nats.go v1.31.0 h1:/WFBHEc/dOKBF6qf1TZhrdEfTmOZ5JzdJ+Y3m6Y/p7E=
github.com/nats-io/nats.go v1.31.0/go.mod h1:di3Bm5MLsoB4Bx61CBTsxuarI36WbhAwOm8QrW39+i8=
github.com/nats-io/nkeys v0.4.6 h1:IzVe95ru2CT6ta874rt9saQRkWfe2nFj1NtvYSLqMzY=
Expand Down Expand Up @@ -154,8 +154,8 @@ golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek=
Expand All @@ -164,10 +164,10 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/time v0.3.0 h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.4.0 h1:Z81tqI5ddIoXDPvVQ7/7CC9TnLM7ubaFG2qXYd5BbYY=
golang.org/x/time v0.4.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down

0 comments on commit 953c2a4

Please sign in to comment.