Skip to content

Commit

Permalink
Fix Ensign Config Preventing GDS from Running (#1176)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbengfort authored Nov 19, 2024
1 parent 9f7a4b8 commit 821fb8b
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 29 deletions.
1 change: 1 addition & 0 deletions pkg/bff/activity_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (s *bffTestSuite) TestActivitySubscriber() {
// Test running the subscriber under a waitgroup
conf.Topic = "network-activity"
conf.Testing = true
conf.Network = activity.TestNet
conf.Ensign = ensign.Config{
ClientID: "client-id",
ClientSecret: "client-secret",
Expand Down
7 changes: 0 additions & 7 deletions pkg/bff/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/rs/zerolog"
"github.com/trisacrypto/directory/pkg/store/config"
"github.com/trisacrypto/directory/pkg/utils/activity"
"github.com/trisacrypto/directory/pkg/utils/ensign"
"github.com/trisacrypto/directory/pkg/utils/logger"
"github.com/trisacrypto/directory/pkg/utils/sentry"
"github.com/trisacrypto/trisa/pkg/trisa/mtls"
Expand Down Expand Up @@ -104,12 +103,6 @@ type CacheConfig struct {
Expiration time.Duration `split_words:"true" default:"8h"`
}

type ActivityConfig struct {
Enabled bool `split_words:"true" default:"false"`
Topic string `split_words:"true"`
Ensign ensign.Config
}

// New creates a new Config object from environment variables prefixed with GDS_BFF.
func New() (conf Config, err error) {
// Load and validate the configuration from the environment.
Expand Down
9 changes: 8 additions & 1 deletion pkg/gds/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ func (c Config) Validate() (err error) {
return err
}

if err = c.Sentry.Validate(); err != nil {
return err
}

if err = c.Activity.Validate(); err != nil {
return err
}

return nil
}

Expand All @@ -171,7 +179,6 @@ func (c GDSConfig) Validate() error {
return errors.New("invalid configuration: bind addr is required for enabled GDS")
}
}

return nil
}

Expand Down
1 change: 0 additions & 1 deletion pkg/gds/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,6 @@ func TestAuthorizedDomainsPreprocessing(t *testing.T) {
}

func TestRequiredConfig(t *testing.T) {
t.Skip("test assumes that confire is processing required tags recursively, is it?")
required := []string{
"GDS_DATABASE_URL",
"GDS_SECRET_KEY",
Expand Down
24 changes: 14 additions & 10 deletions pkg/utils/activity/config.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package activity

import (
"errors"
"time"

"github.com/trisacrypto/directory/pkg/utils/ensign"
)

type Config struct {
Enabled bool `split_words:"true" default:"false"`
Topic string `split_words:"true"`
Network Network `split_words:"true"`
Enabled bool `default:"false"`
Topic string `required:"false"`
Network Network `required:"false" validate:"ignore"`
AggregationWindow time.Duration `split_words:"true" default:"5m"`
Testing bool `split_words:"true" default:"false"`
Ensign ensign.Config
Testing bool `default:"false" `
Ensign ensign.Config `validate:"ignore"`
}

func (c Config) Validate() (err error) {
if c.Enabled {
if c.Topic == "" {
return ErrMissingTopic
err = errors.Join(err, ErrMissingTopic)
}

if err = c.Ensign.Validate(); err != nil {
return err
if verr := c.Network.Validate(); verr != nil {
err = errors.Join(err, verr)
}
}

return nil
if verr := c.Ensign.Validate(); verr != nil {
err = errors.Join(err, verr)
}
}
return err
}
1 change: 1 addition & 0 deletions pkg/utils/activity/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestActivityValidation(t *testing.T) {

// Test valid enabled configuration
conf.Enabled = true
conf.Network = activity.TestNet
conf.Ensign.ClientID = "client-id"
require.NoError(t, conf.Validate())
}
1 change: 1 addition & 0 deletions pkg/utils/activity/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func (n Network) String() string {
}
}

// Check if the network is valid.
func (n Network) Validate() error {
if n == UnknownNetwork {
return ErrUnknownNetwork
Expand Down
2 changes: 1 addition & 1 deletion pkg/utils/activity/publisher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func TestPublisher(t *testing.T) {
Enabled: true,
AggregationWindow: time.Minute * 5,
}
require.ErrorIs(t, activity.ErrMissingTopic, activity.Start(conf), "expected missing topic error")
require.Error(t, activity.Start(conf), "expected error with bad configuration")

// Test publisher in disabled mode starts
activity.Reset()
Expand Down
25 changes: 16 additions & 9 deletions pkg/utils/ensign/config.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
package ensign

import (
"errors"

sdk "github.com/rotationalio/go-ensign"
)

// Config defines common configuration for Ensign clients.
type Config struct {
ClientID string `split_words:"true"`
ClientSecret string `split_words:"true"`
Endpoint string `split_words:"true" default:"ensign.rotational.app:443"`
Endpoint string `default:"ensign.rotational.app:443"`
AuthURL string `split_words:"true" default:"https://auth.rotational.app"`
Insecure bool `split_words:"true" default:"false"`
Testing bool `split_words:"true" default:"false"`
Insecure bool `default:"false"`
Testing bool `default:"false"`
}

func (c Config) Validate() error {
// Validate that the ensign config is ready for connection.
func (c Config) Validate() (err error) {
if c.Testing {
return nil
}

if c.ClientID == "" {
return ErrMissingClientID
err = errors.Join(err, ErrMissingClientID)
}

if c.ClientSecret == "" {
return ErrMissingClientSecret
err = errors.Join(err, ErrMissingClientSecret)
}

if c.Endpoint == "" {
return ErrMissingEndpoint
err = errors.Join(err, ErrMissingEndpoint)
}

if c.AuthURL == "" {
return ErrMissingAuthURL
err = errors.Join(err, ErrMissingAuthURL)
}

return nil
return err
}

func (c Config) ClientOptions() []sdk.Option {
Expand Down

0 comments on commit 821fb8b

Please sign in to comment.