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: add secrets / config to a verbs metadata #2999

Merged
merged 1 commit into from
Oct 7, 2024
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
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call.

syntax = "proto3";

package {{ .Package }};
Expand Down
8 changes: 4 additions & 4 deletions examples/go/http/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ require (
go.opentelemetry.io/otel v1.30.0 // indirect
go.opentelemetry.io/otel/metric v1.30.0 // indirect
go.opentelemetry.io/otel/trace v1.30.0 // indirect
golang.org/x/crypto v0.27.0 // indirect
golang.org/x/crypto v0.28.0 // indirect
golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 // indirect
golang.org/x/mod v0.21.0 // indirect
golang.org/x/net v0.29.0 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.8.0 // indirect
golang.org/x/sys v0.25.0 // indirect
golang.org/x/text v0.18.0 // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/text v0.19.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
20 changes: 10 additions & 10 deletions examples/go/http/go.sum

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

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 ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot to say, there are tests that should be updated to exercise this parsing, in particular TestParserRoundtrip et al and TestProtoRoundTrip.

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),
}
}
Loading
Loading