Skip to content

Commit

Permalink
feat: add setting/getting of config to console (#3407)
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman authored Nov 15, 2024
1 parent c3d54f7 commit a112a30
Show file tree
Hide file tree
Showing 22 changed files with 947 additions and 268 deletions.
34 changes: 33 additions & 1 deletion backend/controller/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"google.golang.org/protobuf/types/known/durationpb"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/TBD54566975/ftl/backend/controller/admin"
"github.com/TBD54566975/ftl/backend/controller/dal"
dalmodel "github.com/TBD54566975/ftl/backend/controller/dal/model"
"github.com/TBD54566975/ftl/backend/controller/timeline"
Expand All @@ -29,14 +30,16 @@ import (
type ConsoleService struct {
dal *dal.DAL
timeline *timeline.Service
admin *admin.AdminService
}

var _ pbconsoleconnect.ConsoleServiceHandler = (*ConsoleService)(nil)

func NewService(dal *dal.DAL, timeline *timeline.Service) *ConsoleService {
func NewService(dal *dal.DAL, timeline *timeline.Service, admin *admin.AdminService) *ConsoleService {
return &ConsoleService{
dal: dal,
timeline: timeline,
admin: admin,
}
}

Expand Down Expand Up @@ -890,6 +893,35 @@ func eventDALToProto(event timeline.Event) *pbconsole.Event {
}
}

func (c *ConsoleService) GetConfig(ctx context.Context, req *connect.Request[pbconsole.GetConfigRequest]) (*connect.Response[pbconsole.GetConfigResponse], error) {
resp, err := c.admin.ConfigGet(ctx, connect.NewRequest(&ftlv1.GetConfigRequest{
Ref: &ftlv1.ConfigRef{
Module: req.Msg.Module,
Name: req.Msg.Name,
},
}))
if err != nil {
return nil, fmt.Errorf("failed to get config: %w", err)
}
return connect.NewResponse(&pbconsole.GetConfigResponse{
Value: resp.Msg.Value,
}), nil
}

func (c *ConsoleService) SetConfig(ctx context.Context, req *connect.Request[pbconsole.SetConfigRequest]) (*connect.Response[pbconsole.SetConfigResponse], error) {
_, err := c.admin.ConfigSet(ctx, connect.NewRequest(&ftlv1.SetConfigRequest{
Ref: &ftlv1.ConfigRef{
Module: req.Msg.Module,
Name: req.Msg.Name,
},
Value: req.Msg.Value,
}))
if err != nil {
return nil, fmt.Errorf("failed to set config: %w", err)
}
return connect.NewResponse(&pbconsole.SetConfigResponse{}), nil
}

func graph(sch *schema.Schema) map[string][]string {
out := make(map[string][]string)
for _, module := range sch.Modules {
Expand Down
2 changes: 1 addition & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func Start(
logger.Debugf("Advertising as %s", config.Advertise)

admin := admin.NewAdminService(cm, sm, svc.dal)
console := console.NewService(svc.dal, svc.timeline)
console := console.NewService(svc.dal, svc.timeline, admin)

ingressHandler := otelhttp.NewHandler(http.Handler(svc), "ftl.ingress")
if len(config.AllowOrigins) > 0 {
Expand Down
Loading

0 comments on commit a112a30

Please sign in to comment.