Skip to content

Commit 01bd83c

Browse files
authored
feat: enrich list namespace and schema (#154)
* feat: enrich list namespace and schema * chore: cleanup dead code * test: fix test * chore: go mo tidy
1 parent cb601b5 commit 01bd83c

25 files changed

Lines changed: 4910 additions & 572 deletions

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
NAME="github.com/odpf/stencil"
22
VERSION=$(shell git describe --always --tags 2>/dev/null)
3-
PROTON_COMMIT := "d08a4916075438ed9c3a4510989bda2273e0a4e4"
3+
PROTON_COMMIT := "a6c7056fa80128145d00d5ee72f216c28578ec43"
44

55
.PHONY: all build test clean dist vet proto install
66

cmd/cdk.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package cmd
22

33
var dict = map[string]string{
4-
"COMPATIBILITY_BACKWARD": "backward",
5-
"COMPATIBILITY_FORWARD": "forward",
6-
"COMPATIBILITY_FULL": "full",
7-
"FORMAT_PROTOBUF": "protobuf",
8-
"FORMAT_JSON": "json",
9-
"FORMAT_AVRO": "avro",
4+
"COMPATIBILITY_BACKWARD": "backward",
5+
"COMPATIBILITY_FORWARD": "forward",
6+
"COMPATIBILITY_FULL": "full",
7+
"COMPATIBILITY_UNSPECIFIED": "-",
8+
"FORMAT_PROTOBUF": "protobuf",
9+
"FORMAT_JSON": "json",
10+
"FORMAT_AVRO": "avro",
1011
}
1112

1213
var (

cmd/list.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ func listSchemaCmd(cdk *CDK) *cobra.Command {
4141
if err != nil {
4242
return err
4343
}
44-
4544
schemas := res.GetSchemas()
4645

4746
// TODO(Ravi): List schemas should also handle namespace not found
@@ -61,15 +60,14 @@ func listSchemaCmd(cdk *CDK) *cobra.Command {
6160
term.Bold("AUTHORITY"),
6261
})
6362
for _, s := range schemas {
64-
meta, _ := fetchMeta(client, namespace, s)
65-
c := meta.GetCompatibility().String()
66-
f := meta.GetFormat().String()
67-
a := meta.GetAuthority()
63+
c := s.GetCompatibility().String()
64+
f := s.GetFormat().String()
65+
a := s.GetAuthority()
6866

6967
if a == "" {
7068
a = "-"
7169
}
72-
report = append(report, []string{term.Greenf("#%d", index), s, dict[f], dict[c], a})
70+
report = append(report, []string{term.Greenf("#%d", index), s.GetName(), dict[f], dict[c], a})
7371
index++
7472
}
7573

cmd/namespace.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ func listNamespaceCmd(cdk *CDK) *cobra.Command {
7575
fmt.Printf("\nShowing %[1]d of %[1]d namespaces \n \n", len(namespaces))
7676
report := [][]string{}
7777
index := 1
78-
report = append(report, []string{"INDEX", "NAMESPACE", "FORMAT", "COMPATIBILITY", "DESCRIPTION"})
78+
report = append(report, []string{"INDEX", "NAMESPACE", "FORMAT", "COMPATIBILITY"})
7979
for _, n := range namespaces {
80-
report = append(report, []string{term.Greenf("#%d", index), n, "-", "-", "-"})
80+
report = append(report,
81+
[]string{term.Greenf("#%d", index),
82+
n.Id,
83+
dict[n.GetFormat().String()],
84+
dict[n.GetCompatibility().String()],
85+
})
8186
index++
8287
}
8388
printer.Table(os.Stdout, report)

cmd/schema.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,3 @@ func fetchSchemaAndMeta(client stencilv1beta1.StencilServiceClient, version int3
7272

7373
return data, meta, nil
7474
}
75-
76-
func fetchMeta(client stencilv1beta1.StencilServiceClient, namespace string, schema string) (*stencilv1beta1.GetSchemaMetadataResponse, error) {
77-
req := stencilv1beta1.GetSchemaMetadataRequest{
78-
NamespaceId: namespace,
79-
SchemaId: schema,
80-
}
81-
return client.GetSchemaMetadata(context.Background(), &req)
82-
}

core/namespace/namespace.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type Namespace struct {
1717
type Repository interface {
1818
Create(context.Context, Namespace) (Namespace, error)
1919
Update(context.Context, Namespace) (Namespace, error)
20-
List(context.Context) ([]string, error)
20+
List(context.Context) ([]Namespace, error)
2121
Get(context.Context, string) (Namespace, error)
2222
Delete(context.Context, string) error
2323
}

core/namespace/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (s Service) Update(ctx context.Context, ns Namespace) (Namespace, error) {
2222
return s.repo.Update(ctx, ns)
2323
}
2424

25-
func (s Service) List(ctx context.Context) ([]string, error) {
25+
func (s Service) List(ctx context.Context) ([]Namespace, error) {
2626
return s.repo.List(ctx)
2727
}
2828

core/schema/mocks/schema_repository.go

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

core/schema/schema.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type SchemaFile struct {
2323

2424
type Repository interface {
2525
Create(ctx context.Context, namespace string, schema string, metadata *Metadata, versionID string, schemaFile *SchemaFile) (version int32, err error)
26-
List(context.Context, string) ([]string, error)
26+
List(context.Context, string) ([]Schema, error)
2727
ListVersions(context.Context, string, string) ([]int32, error)
2828
Get(context.Context, string, string, int32) ([]byte, error)
2929
GetLatestVersion(context.Context, string, string) (int32, error)
@@ -49,3 +49,10 @@ type Cache interface {
4949
Get(interface{}) (interface{}, bool)
5050
Set(interface{}, interface{}, int64) bool
5151
}
52+
53+
type Schema struct {
54+
Name string
55+
Format string
56+
Compatibility string
57+
Authority string
58+
}

core/schema/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (s *Service) UpdateMetadata(ctx context.Context, namespace, schemaName stri
142142
return s.repo.UpdateMetadata(ctx, namespace, schemaName, meta)
143143
}
144144

145-
func (s *Service) List(ctx context.Context, namespaceID string) ([]string, error) {
145+
func (s *Service) List(ctx context.Context, namespaceID string) ([]Schema, error) {
146146
return s.repo.List(ctx, namespaceID)
147147
}
148148

0 commit comments

Comments
 (0)