Skip to content

Commit

Permalink
WIP: fixes from integration
Browse files Browse the repository at this point in the history
  • Loading branch information
ewollesen committed Nov 2, 2023
1 parent c79ab93 commit 0aa1f1f
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 3 deletions.
7 changes: 6 additions & 1 deletion alerts/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/kelseyhightower/envconfig"

"github.com/tidepool-org/platform/client"
"github.com/tidepool-org/platform/log"
"github.com/tidepool-org/platform/log/null"
"github.com/tidepool-org/platform/platform"
)

Expand All @@ -29,20 +31,23 @@ func NewClient(cfg *ClientConfig) (*Client, error) {

// Upsert updates cfg in the service if it exists, or creates it if it doesn't.
func (c *Client) Upsert(ctx context.Context, cfg *Config) error {
ctx = log.NewContextWithLogger(ctx, null.NewLogger())
url := c.client.ConstructURL("v1", "alerts", cfg.UserID, cfg.FollowedUserID)
return c.client.RequestData(ctx, http.MethodPost, url, nil, cfg, nil)
}

// Delete the alerts config.
func (c *Client) Delete(ctx context.Context, cfg *Config) error {
// Ideally the base client wouldn't require a logger, or if it found a nil, would use a null logger itself.
ctx = log.NewContextWithLogger(ctx, null.NewLogger())
url := c.client.ConstructURL("v1", "alerts", cfg.UserID, cfg.FollowedUserID)
return c.client.RequestData(ctx, http.MethodDelete, url, nil, nil, nil)
}

// ClientConfig leverages platform.Config for the alerts client.
type ClientConfig struct {
*platform.Config
Address string `envconfig:"TIDEPOOL_DATA_CLIENT_ADDRESS"`
Address string `envconfig:"TIDEPOOL_DATA_CLIENT_ADDRESS" required:"true"`
}

// ConfigLoader abstracts the method by which config values are loaded.
Expand Down
2 changes: 1 addition & 1 deletion log/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func LoggerFromContext(ctx context.Context) Logger {
return logger
}
}
return nil
return NewNullLogger()
}

func ContextWithField(ctx context.Context, key string, value interface{}) context.Context {
Expand Down
71 changes: 71 additions & 0 deletions log/null.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package log

func NewNullLogger() *nullLogger {
return &nullLogger{}
}

type nullLogger struct{}

func (l *nullLogger) Log(level Level, message string) {
return
}

func (l *nullLogger) Debug(message string) {
return
}

func (l *nullLogger) Info(message string) {
return
}

func (l *nullLogger) Warn(message string) {
return
}

func (l *nullLogger) Error(message string) {
return
}

func (l *nullLogger) Debugf(message string, args ...interface{}) {
return
}

func (l *nullLogger) Infof(message string, args ...interface{}) {
return
}

func (l *nullLogger) Warnf(message string, args ...interface{}) {
return
}

func (l *nullLogger) Errorf(message string, args ...interface{}) {
return
}

func (l *nullLogger) WithError(err error) Logger {
return l
}

func (l *nullLogger) WithField(key string, value interface{}) Logger {
return l
}

func (l *nullLogger) WithFields(fields Fields) Logger {
return l
}

func (l *nullLogger) WithLevelRank(level Level, rank Rank) Logger {
return l
}

func (l *nullLogger) WithLevelRanks(levelRanks LevelRanks) Logger {
return l
}

func (l *nullLogger) WithLevel(level Level) Logger {
return l
}

func (l *nullLogger) Level() Level {
return DebugLevel
}
2 changes: 1 addition & 1 deletion platform/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// Config extends client.Config with additional properties.
type Config struct {
*client.Config
ServiceSecret string `envconfig:"TIDEPOOL_SERVICE_SECRET"`
ServiceSecret string `envconfig:"TIDEPOOL_SERVER_SECRET" required:"true"`
}

func NewConfig() *Config {
Expand Down

0 comments on commit 0aa1f1f

Please sign in to comment.