Skip to content

Commit

Permalink
fix: update rpc function names, setting config is WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed May 29, 2024
1 parent 6351020 commit b5f53bd
Show file tree
Hide file tree
Showing 9 changed files with 258 additions and 223 deletions.
60 changes: 39 additions & 21 deletions backend/controller/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,30 @@ import (
ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
cf "github.com/TBD54566975/ftl/common/configuration"
"github.com/TBD54566975/ftl/internal/log"
)

type AdminService struct{}
type AdminService struct {
cm *cf.Manager[cf.Configuration]
sm *cf.Manager[cf.Secrets]
}

var _ ftlv1connect.AdminServiceHandler = (*AdminService)(nil)

func NewAdminService() *AdminService {
return &AdminService{}
func NewAdminService(cm *cf.Manager[cf.Configuration], sm *cf.Manager[cf.Secrets]) *AdminService {
return &AdminService{
cm: cm,
sm: sm,
}
}

func (s *AdminService) Ping(ctx context.Context, req *connect.Request[ftlv1.PingRequest]) (*connect.Response[ftlv1.PingResponse], error) {
return connect.NewResponse(&ftlv1.PingResponse{}), nil
}

// List configuration.

Check warning on line 35 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.ConfigList should be of the form "ConfigList ..." (revive)
func (s *AdminService) ListConfig(ctx context.Context, req *connect.Request[ftlv1.ListConfigRequest]) (*connect.Response[ftlv1.ListConfigResponse], error) {
cm := cf.ConfigFromContext(ctx)
listing, err := cm.List(ctx)
func (s *AdminService) ConfigList(ctx context.Context, req *connect.Request[ftlv1.ListConfigRequest]) (*connect.Response[ftlv1.ListConfigResponse], error) {
listing, err := s.cm.List(ctx)
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to list config: %w", err))
}
Expand All @@ -48,7 +54,7 @@ func (s *AdminService) ListConfig(ctx context.Context, req *connect.Request[ftlv
cv := ""
if *req.Msg.IncludeValues {
var value any
err := cm.Get(ctx, config.Ref, &value)
err := s.cm.Get(ctx, config.Ref, &value)
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to get value: %w", err))
} else {

Check warning on line 60 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

indent-error-flow: if block ends with a return statement, so drop this else and outdent its block (revive)
Expand All @@ -66,10 +72,9 @@ func (s *AdminService) ListConfig(ctx context.Context, req *connect.Request[ftlv
}

// Get a config value.

Check warning on line 74 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.ConfigGet should be of the form "ConfigGet ..." (revive)
func (s *AdminService) GetConfig(ctx context.Context, req *connect.Request[ftlv1.GetConfigRequest]) (*connect.Response[ftlv1.GetConfigResponse], error) {
cm := cf.ConfigFromContext(ctx)
func (s *AdminService) ConfigGet(ctx context.Context, req *connect.Request[ftlv1.GetConfigRequest]) (*connect.Response[ftlv1.GetConfigResponse], error) {
var value any
err := cm.Get(ctx, cf.NewRef(*req.Msg.Ref.Module, req.Msg.Ref.Name), &value)
err := s.cm.Get(ctx, cf.NewRef(*req.Msg.Ref.Module, req.Msg.Ref.Name), &value)
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to get value: %w", err))
}
Expand All @@ -86,13 +91,27 @@ func (s *AdminService) GetConfig(ctx context.Context, req *connect.Request[ftlv1
}

// Set a config value.

Check warning on line 93 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.ConfigSet should be of the form "ConfigSet ..." (revive)
func (s *AdminService) SetConfig(ctx context.Context, req *connect.Request[ftlv1.SetConfigRequest]) (*connect.Response[ftlv1.SetConfigResponse], error) {
cm := cf.ConfigFromContext(ctx) // TODO(saf): use cf.New to create a cm with the appropriate provider/writer
if err := cm.Mutable(); err != nil {
func (s *AdminService) ConfigSet(ctx context.Context, req *connect.Request[ftlv1.SetConfigRequest]) (*connect.Response[ftlv1.SetConfigResponse], error) {
// cm := cf.ConfigFromContext(ctx) // TODO(saf): use cf.New to create a cm with the appropriate provider/writer

var err error

// var providerKey string
// switch *req.Msg.Provider {
// case ftlv1.ConfigProvider_CONFIG_ENVAR:
// providerKey = "envar"
// case ftlv1.ConfigProvider_CONFIG_INLINE:
// providerKey = "inline"
// }

logger := log.FromContext(ctx)
logger.Warnf("cm pre-mutable %+v", s.cm)
if err := s.cm.Mutable(); err != nil {
return nil, connect.NewError(connect.CodeInternal, err)
}
logger.Warnf("cm post-mutable %+v", s.cm)

err := cm.Set(ctx, cf.NewRef(*req.Msg.Ref.Module, req.Msg.Ref.Name), req.Msg.Value)
err = s.cm.Set(ctx, cf.NewRef(*req.Msg.Ref.Module, req.Msg.Ref.Name), req.Msg.Value)
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to set value: %w", err))
}
Expand All @@ -103,31 +122,30 @@ func (s *AdminService) SetConfig(ctx context.Context, req *connect.Request[ftlv1
}

// Unset a config value.

Check warning on line 124 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.ConfigUnset should be of the form "ConfigUnset ..." (revive)
func (s *AdminService) UnsetConfig(ctx context.Context, req *connect.Request[ftlv1.UnsetConfigRequest]) (*connect.Response[ftlv1.UnsetConfigResponse], error) {
cm := cf.ConfigFromContext(ctx) // TODO(saf): use cf.New to create a cm with the appropriate provider/writer
err := cm.Unset(ctx, cf.NewRef(*req.Msg.Ref.Module, req.Msg.Ref.Name))
func (s *AdminService) ConfigUnset(ctx context.Context, req *connect.Request[ftlv1.UnsetConfigRequest]) (*connect.Response[ftlv1.UnsetConfigResponse], error) {
err := s.cm.Unset(ctx, cf.NewRef(*req.Msg.Ref.Module, req.Msg.Ref.Name))
if err != nil {
return nil, connect.NewError(connect.CodeInternal, fmt.Errorf("failed to unset value: %w", err))
}
return connect.NewResponse(&ftlv1.UnsetConfigResponse{}), nil
}

// List secrets.

Check warning on line 133 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.SecretsList should be of the form "SecretsList ..." (revive)
func (s *AdminService) ListSecrets(ctx context.Context, req *connect.Request[ftlv1.ListSecretsRequest]) (*connect.Response[ftlv1.ListSecretsResponse], error) {
func (s *AdminService) SecretsList(ctx context.Context, req *connect.Request[ftlv1.ListSecretsRequest]) (*connect.Response[ftlv1.ListSecretsResponse], error) {
return connect.NewResponse(&ftlv1.ListSecretsResponse{}), nil
}

// Get a secret.

Check warning on line 138 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.SecretGet should be of the form "SecretGet ..." (revive)
func (s *AdminService) GetSecret(ctx context.Context, req *connect.Request[ftlv1.GetSecretRequest]) (*connect.Response[ftlv1.GetSecretResponse], error) {
func (s *AdminService) SecretGet(ctx context.Context, req *connect.Request[ftlv1.GetSecretRequest]) (*connect.Response[ftlv1.GetSecretResponse], error) {
return connect.NewResponse(&ftlv1.GetSecretResponse{}), nil
}

// Set a secret.

Check warning on line 143 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.SecretSet should be of the form "SecretSet ..." (revive)
func (s *AdminService) SetSecret(ctx context.Context, req *connect.Request[ftlv1.SetSecretRequest]) (*connect.Response[ftlv1.SetSecretResponse], error) {
func (s *AdminService) SecretSet(ctx context.Context, req *connect.Request[ftlv1.SetSecretRequest]) (*connect.Response[ftlv1.SetSecretResponse], error) {
return connect.NewResponse(&ftlv1.SetSecretResponse{}), nil
}

// Unset a secret.

Check warning on line 148 in backend/controller/admin.go

View workflow job for this annotation

GitHub Actions / Lint

exported: comment on exported method AdminService.SecretUnset should be of the form "SecretUnset ..." (revive)
func (s *AdminService) UnsetSecret(ctx context.Context, req *connect.Request[ftlv1.UnsetSecretRequest]) (*connect.Response[ftlv1.UnsetSecretResponse], error) {
func (s *AdminService) SecretUnset(ctx context.Context, req *connect.Request[ftlv1.UnsetSecretRequest]) (*connect.Response[ftlv1.UnsetSecretResponse], error) {
return connect.NewResponse(&ftlv1.UnsetSecretResponse{}), nil
}
8 changes: 7 additions & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ func Start(ctx context.Context, config Config, runnerScaling scaling.RunnerScali
}
logger.Debugf("Listening on %s", config.Bind)

admin := NewAdminService()
cm := cf.ConfigFromContext(ctx)
sm := cf.SecretsFromContext(ctx)

logger.Warnf("config manager: %+v", cm)
logger.Warnf("secrets manager: %+v", sm)

admin := NewAdminService(cm, sm)
console := NewConsoleService(dal)

ingressHandler := http.StripPrefix("/ingress", svc)
Expand Down
56 changes: 28 additions & 28 deletions backend/protos/xyz/block/ftl/v1/ftl.pb.go

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

16 changes: 8 additions & 8 deletions backend/protos/xyz/block/ftl/v1/ftl.proto
Original file line number Diff line number Diff line change
Expand Up @@ -486,26 +486,26 @@ service AdminService {
}

// List configuration.
rpc ListConfig(ListConfigRequest) returns (ListConfigResponse);
rpc ConfigList(ListConfigRequest) returns (ListConfigResponse);

// Get a config value.
rpc GetConfig(GetConfigRequest) returns (GetConfigResponse);
rpc ConfigGet(GetConfigRequest) returns (GetConfigResponse);

// Set a config value.
rpc SetConfig(SetConfigRequest) returns (SetConfigResponse);
rpc ConfigSet(SetConfigRequest) returns (SetConfigResponse);

// Unset a config value.
rpc UnsetConfig(UnsetConfigRequest) returns (UnsetConfigResponse);
rpc ConfigUnset(UnsetConfigRequest) returns (UnsetConfigResponse);

// List secrets.
rpc ListSecrets(ListSecretsRequest) returns (ListSecretsResponse);
rpc SecretsList(ListSecretsRequest) returns (ListSecretsResponse);

// Get a secret.
rpc GetSecret(GetSecretRequest) returns (GetSecretResponse);
rpc SecretGet(GetSecretRequest) returns (GetSecretResponse);

// Set a secret.
rpc SetSecret(SetSecretRequest) returns (SetSecretResponse);
rpc SecretSet(SetSecretRequest) returns (SetSecretResponse);

// Unset a secret.
rpc UnsetSecret(UnsetSecretRequest) returns (UnsetSecretResponse);
rpc SecretUnset(UnsetSecretRequest) returns (UnsetSecretResponse);
}
Loading

0 comments on commit b5f53bd

Please sign in to comment.