Skip to content

Commit

Permalink
feat: add secrets / config to a verbs metadata
Browse files Browse the repository at this point in the history
fixes: #1083
  • Loading branch information
stuartwdouglas committed Oct 7, 2024
1 parent 3f355e4 commit 8e83519
Show file tree
Hide file tree
Showing 18 changed files with 1,150 additions and 617 deletions.
1,404 changes: 803 additions & 601 deletions backend/protos/xyz/block/ftl/v1/schema/schema.pb.go

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions backend/protos/xyz/block/ftl/v1/schema/schema.proto
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// THIS FILE IS GENERATED; DO NOT MODIFY
syntax = "proto3";

package xyz.block.ftl.v1.schema;
Expand Down Expand Up @@ -147,11 +148,13 @@ message Metadata {
oneof value {
MetadataAlias alias = 5;
MetadataCalls calls = 1;
MetadataConfig config = 10;
MetadataCronJob cronJob = 3;
MetadataDatabases databases = 4;
MetadataEncoding encoding = 9;
MetadataIngress ingress = 2;
MetadataRetry retry = 6;
MetadataSecrets secrets = 11;
MetadataSubscriber subscriber = 7;
MetadataTypeMap typeMap = 8;
}
Expand All @@ -168,6 +171,11 @@ message MetadataCalls {
repeated Ref calls = 2;
}

message MetadataConfig {
optional Position pos = 1;
repeated Ref config = 2;
}

message MetadataCronJob {
optional Position pos = 1;
string cron = 2;
Expand Down Expand Up @@ -199,6 +207,11 @@ message MetadataRetry {
optional Ref catch = 5;
}

message MetadataSecrets {
optional Position pos = 1;
repeated Ref secrets = 2;
}

message MetadataSubscriber {
optional Position pos = 1;
string name = 2;
Expand Down
1 change: 1 addition & 0 deletions cmd/go2proto/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ func genErrorf(pos token.Pos, format string, args ...any) error {

var tmpl = template.Must(template.New("proto").
Parse(`
// THIS FILE IS GENERATED; DO NOT MODIFY
syntax = "proto3";
package {{ .Package }};
Expand Down
102 changes: 102 additions & 0 deletions frontend/console/src/protos/xyz/block/ftl/v1/schema/schema_pb.ts

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

4 changes: 2 additions & 2 deletions internal/schema/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ func (d *Data) Monomorphise(ref *Ref) (*Data, error) {

case *Any, *Bool, *Bytes, *Data, *Ref, *Database, Decl, *Float,
IngressPathComponent, *IngressPathLiteral, *IngressPathParameter,
*Int, Metadata, *MetadataCalls, *MetadataDatabases, *MetadataRetry,
*MetadataIngress, *MetadataCronJob, *MetadataAlias, *Module,
*Int, Metadata, *MetadataCalls, *MetadataConfig, *MetadataDatabases, *MetadataRetry,
*MetadataIngress, *MetadataCronJob, *MetadataAlias, *MetadataSecrets, *Module,
*Schema, *String, *Time, Type, *TypeParameter, *Unit, *Verb, *Enum,
*EnumVariant, Value, *IntValue, *StringValue, *TypeValue, Symbol,
Named, *FSM, *FSMTransition, *TypeAlias, *Topic, *Subscription, *MetadataSubscriber, *MetadataTypeMap,
Expand Down
4 changes: 2 additions & 2 deletions internal/schema/jsonschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ func nodeToJSSchema(node Node, refs map[RefKey]*Ref) *jsonschema.Schema {
case *TypeAlias:
return nodeToJSSchema(node.Type, refs)

case Decl, *Field, Metadata, *MetadataCalls, *MetadataDatabases, *MetadataIngress,
*MetadataAlias, IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Module,
case Decl, *Field, Metadata, *MetadataCalls, *MetadataConfig, *MetadataDatabases, *MetadataIngress,
*MetadataAlias, *MetadataSecrets, IngressPathComponent, *IngressPathLiteral, *IngressPathParameter, *Module,
*Schema, Type, *Database, *Verb, *EnumVariant, *MetadataCronJob, Value,
*StringValue, *IntValue, *TypeValue, *Config, *Secret, Symbol, Named,
*FSM, *FSMTransition, *MetadataRetry, *Topic, *Subscription, *MetadataSubscriber, *MetadataTypeMap,
Expand Down
59 changes: 59 additions & 0 deletions internal/schema/metadataconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package schema

import (
"fmt"
"strings"

"google.golang.org/protobuf/proto"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)

// MetadataConfig represents a metadata block with a list of config items that are used.
//
//protobuf:10,optional
type MetadataConfig struct {
Pos Position `parser:"" protobuf:"1,optional"`

Config []*Ref `parser:"'+' 'config' @@ (',' @@)*" protobuf:"2"`
}

var _ Metadata = (*MetadataConfig)(nil)

func (m *MetadataConfig) Position() Position { return m.Pos }
func (m *MetadataConfig) String() string {
out := &strings.Builder{}
fmt.Fprint(out, "+config ")
w := 6
for i, config := range m.Config {
if i > 0 {
fmt.Fprint(out, ", ")
w += 2
}
str := config.String()
if w+len(str) > 70 {
w = 6
fmt.Fprint(out, "\n ")
}
w += len(str)
fmt.Fprint(out, str)
}
fmt.Fprint(out)
return out.String()
}

func (m *MetadataConfig) schemaChildren() []Node {
out := make([]Node, 0, len(m.Config))
for _, ref := range m.Config {
out = append(out, ref)
}
return out
}
func (*MetadataConfig) schemaMetadata() {}

func (m *MetadataConfig) ToProto() proto.Message {
return &schemapb.MetadataConfig{
Pos: posToProto(m.Pos),
Config: nodeListToProto[*schemapb.Ref](m.Config),
}
}
59 changes: 59 additions & 0 deletions internal/schema/metadatasecrets.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package schema

import (
"fmt"
"strings"

"google.golang.org/protobuf/proto"

schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema"
)

// MetadataSecrets represents a metadata block with a list of config items that are used.
//
//protobuf:11,optional
type MetadataSecrets struct {
Pos Position `parser:"" protobuf:"1,optional"`

Secrets []*Ref `parser:"'+' 'secrets' @@ (',' @@)*" protobuf:"2"`
}

var _ Metadata = (*MetadataSecrets)(nil)

func (m *MetadataSecrets) Position() Position { return m.Pos }
func (m *MetadataSecrets) String() string {
out := &strings.Builder{}
fmt.Fprint(out, "+secrets ")
w := 6
for i, secret := range m.Secrets {
if i > 0 {
fmt.Fprint(out, ", ")
w += 2
}
str := secret.String()
if w+len(str) > 70 {
w = 6
fmt.Fprint(out, "\n ")
}
w += len(str)
fmt.Fprint(out, str)
}
fmt.Fprint(out)
return out.String()
}

func (m *MetadataSecrets) schemaChildren() []Node {
out := make([]Node, 0, len(m.Secrets))
for _, ref := range m.Secrets {
out = append(out, ref)
}
return out
}
func (*MetadataSecrets) schemaMetadata() {}

func (m *MetadataSecrets) ToProto() proto.Message {
return &schemapb.MetadataSecrets{
Pos: posToProto(m.Pos),
Secrets: nodeListToProto[*schemapb.Ref](m.Secrets),
}
}
5 changes: 3 additions & 2 deletions internal/schema/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ var (
&Ref{},
}
typeUnion = append(nonOptionalTypeUnion, &Optional{})
metadataUnion = []Metadata{&MetadataCalls{}, &MetadataIngress{}, &MetadataCronJob{}, &MetadataDatabases{},
&MetadataAlias{}, &MetadataRetry{}, &MetadataSubscriber{}, &MetadataTypeMap{}, &MetadataEncoding{}}
metadataUnion = []Metadata{&MetadataCalls{}, &MetadataConfig{}, &MetadataIngress{}, &MetadataCronJob{},
&MetadataDatabases{}, &MetadataAlias{}, &MetadataRetry{}, &MetadataSecrets{}, &MetadataSubscriber{},
&MetadataTypeMap{}, &MetadataEncoding{}}
ingressUnion = []IngressPathComponent{&IngressPathLiteral{}, &IngressPathParameter{}}
valueUnion = []Value{&StringValue{}, &IntValue{}, &TypeValue{}}

Expand Down
12 changes: 11 additions & 1 deletion internal/schema/protobuf_dec.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ func metadataToSchema(s *schemapb.Metadata) Metadata {
Pos: PosFromProto(s.Calls.Pos),
Calls: refListToSchema(s.Calls.Calls),
}

case *schemapb.Metadata_Config:
return &MetadataConfig{
Pos: PosFromProto(s.Config.Pos),
Config: refListToSchema(s.Config.Config),
}
case *schemapb.Metadata_Databases:
return &MetadataDatabases{
Pos: PosFromProto(s.Databases.Pos),
Expand Down Expand Up @@ -158,6 +162,12 @@ func metadataToSchema(s *schemapb.Metadata) Metadata {
Catch: catch,
}

case *schemapb.Metadata_Secrets:
return &MetadataSecrets{
Pos: PosFromProto(s.Secrets.Pos),
Secrets: refListToSchema(s.Secrets.Secrets),
}

case *schemapb.Metadata_Subscriber:
return &MetadataSubscriber{
Pos: PosFromProto(s.Subscriber.Pos),
Expand Down
6 changes: 6 additions & 0 deletions internal/schema/protobuf_enc.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ func metadataListToProto(nodes []Metadata) []*schemapb.Metadata {
case *MetadataCalls:
v = &schemapb.Metadata_Calls{Calls: n.ToProto().(*schemapb.MetadataCalls)}

case *MetadataConfig:
v = &schemapb.Metadata_Config{Config: n.ToProto().(*schemapb.MetadataConfig)}

case *MetadataDatabases:
v = &schemapb.Metadata_Databases{Databases: n.ToProto().(*schemapb.MetadataDatabases)}

Expand All @@ -84,6 +87,9 @@ func metadataListToProto(nodes []Metadata) []*schemapb.Metadata {
case *MetadataRetry:
v = &schemapb.Metadata_Retry{Retry: n.ToProto().(*schemapb.MetadataRetry)}

case *MetadataSecrets:
v = &schemapb.Metadata_Secrets{Secrets: n.ToProto().(*schemapb.MetadataSecrets)}

case *MetadataSubscriber:
v = &schemapb.Metadata_Subscriber{Subscriber: n.ToProto().(*schemapb.MetadataSubscriber)}

Expand Down
Loading

0 comments on commit 8e83519

Please sign in to comment.