Issue 511 - Fix review comments
This commit is contained in:
@@ -27,9 +27,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: keymanager
|
||||
config:
|
||||
@@ -70,9 +70,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: keymanager
|
||||
config:
|
||||
@@ -109,9 +109,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: keymanager
|
||||
config:
|
||||
@@ -148,9 +148,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: keymanager
|
||||
config:
|
||||
|
||||
@@ -27,9 +27,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://registry:3030/subscribers
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: simplekeymanager
|
||||
config:
|
||||
@@ -72,9 +72,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://registry:3030/subscribers
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: simplekeymanager
|
||||
config:
|
||||
@@ -113,9 +113,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://registry:3030/subscribers
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: simplekeymanager
|
||||
config:
|
||||
@@ -152,9 +152,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://registry:3030/subscribers
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: simplekeymanager
|
||||
config:
|
||||
|
||||
@@ -24,13 +24,13 @@ modules:
|
||||
type: std
|
||||
role: bap
|
||||
plugins:
|
||||
registry:
|
||||
registry:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
@@ -69,13 +69,13 @@ modules:
|
||||
type: std
|
||||
role: bap
|
||||
plugins:
|
||||
registry:
|
||||
registry:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
|
||||
@@ -25,13 +25,13 @@ modules:
|
||||
role: bpp
|
||||
subscriberId: bpp1
|
||||
plugins:
|
||||
registry:
|
||||
registry:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
@@ -70,13 +70,13 @@ modules:
|
||||
type: std
|
||||
role: bpp
|
||||
plugins:
|
||||
registry:
|
||||
registry:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
|
||||
@@ -28,9 +28,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
@@ -73,9 +73,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
@@ -119,9 +119,9 @@ modules:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: "3"
|
||||
retry_wait_min: "100ms"
|
||||
retry_wait_max: "500ms"
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
@@ -159,8 +159,14 @@ modules:
|
||||
handler:
|
||||
type: std
|
||||
role: bpp
|
||||
registryUrl: http://localhost:8080/reg
|
||||
plugins:
|
||||
registry:
|
||||
id: registry
|
||||
config:
|
||||
url: http://localhost:8080/reg
|
||||
retry_max: 3
|
||||
retry_wait_min: 100ms
|
||||
retry_wait_max: 500ms
|
||||
keyManager:
|
||||
id: secretskeymanager
|
||||
config:
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
)
|
||||
|
||||
type RegistryLookup interface {
|
||||
// looks up Registry entry to obtain public keys to validate signature of the incoming message
|
||||
Lookup(ctx context.Context, req *model.Subscription) ([]model.Subscription, error)
|
||||
Subscribe(ctx context.Context, subscription *model.Subscription) error
|
||||
}
|
||||
|
||||
// RegistryLookupProvider initializes a new registry lookup instance.
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
@@ -14,39 +15,61 @@ import (
|
||||
// registryProvider implements the RegistryLookupProvider interface for the registry plugin.
|
||||
type registryProvider struct{}
|
||||
|
||||
// newRegistryFunc is a function type that creates a new Registry instance.
|
||||
var newRegistryFunc = registry.New
|
||||
|
||||
// parseConfig parses the configuration map and returns a registry.Config with optional parameters.
|
||||
func (r registryProvider) parseConfig(config map[string]string) (*registry.Config, error) {
|
||||
registryConfig := ®istry.Config{
|
||||
URL: config["url"],
|
||||
}
|
||||
|
||||
// Parse retry_max
|
||||
if retryMaxStr, exists := config["retry_max"]; exists && retryMaxStr != "" {
|
||||
retryMax, err := strconv.Atoi(retryMaxStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid retry_max value '%s': %w", retryMaxStr, err)
|
||||
}
|
||||
registryConfig.RetryMax = retryMax
|
||||
}
|
||||
|
||||
// Parse retry_wait_min
|
||||
if retryWaitMinStr, exists := config["retry_wait_min"]; exists && retryWaitMinStr != "" {
|
||||
retryWaitMin, err := time.ParseDuration(retryWaitMinStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid retry_wait_min value '%s': %w", retryWaitMinStr, err)
|
||||
}
|
||||
registryConfig.RetryWaitMin = retryWaitMin
|
||||
}
|
||||
|
||||
// Parse retry_wait_max
|
||||
if retryWaitMaxStr, exists := config["retry_wait_max"]; exists && retryWaitMaxStr != "" {
|
||||
retryWaitMax, err := time.ParseDuration(retryWaitMaxStr)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("invalid retry_wait_max value '%s': %w", retryWaitMaxStr, err)
|
||||
}
|
||||
registryConfig.RetryWaitMax = retryWaitMax
|
||||
}
|
||||
|
||||
return registryConfig, nil
|
||||
}
|
||||
|
||||
// New creates a new registry plugin instance.
|
||||
func (r registryProvider) New(ctx context.Context, config map[string]string) (definition.RegistryLookup, func() error, error) {
|
||||
if ctx == nil {
|
||||
return nil, nil, errors.New("context cannot be nil")
|
||||
}
|
||||
|
||||
// Parse configuration from map
|
||||
registryConfig := ®istry.Config{
|
||||
URL: config["url"],
|
||||
}
|
||||
|
||||
// Parse optional retry settings
|
||||
if retryMaxStr, exists := config["retry_max"]; exists && retryMaxStr != "" {
|
||||
if retryMax, err := strconv.Atoi(retryMaxStr); err == nil {
|
||||
registryConfig.RetryMax = retryMax
|
||||
}
|
||||
}
|
||||
|
||||
if retryWaitMinStr, exists := config["retry_wait_min"]; exists && retryWaitMinStr != "" {
|
||||
if retryWaitMin, err := time.ParseDuration(retryWaitMinStr); err == nil {
|
||||
registryConfig.RetryWaitMin = retryWaitMin
|
||||
}
|
||||
}
|
||||
|
||||
if retryWaitMaxStr, exists := config["retry_wait_max"]; exists && retryWaitMaxStr != "" {
|
||||
if retryWaitMax, err := time.ParseDuration(retryWaitMaxStr); err == nil {
|
||||
registryConfig.RetryWaitMax = retryWaitMax
|
||||
}
|
||||
// Parse configuration from map using the dedicated method
|
||||
registryConfig, err := r.parseConfig(config)
|
||||
if err != nil {
|
||||
log.Errorf(ctx, err, "Failed to parse registry configuration")
|
||||
return nil, nil, fmt.Errorf("failed to parse registry configuration: %w", err)
|
||||
}
|
||||
|
||||
log.Debugf(ctx, "Registry config mapped: %+v", registryConfig)
|
||||
|
||||
registryClient, closer, err := registry.New(ctx, registryConfig)
|
||||
registryClient, closer, err := newRegistryFunc(ctx, registryConfig)
|
||||
if err != nil {
|
||||
log.Errorf(ctx, err, "Failed to create registry instance")
|
||||
return nil, nil, err
|
||||
|
||||
@@ -145,7 +145,6 @@ func TestRegistryProvider_IntegrationTest(t *testing.T) {
|
||||
require.NotNil(t, closer)
|
||||
defer closer()
|
||||
|
||||
// Test Subscribe
|
||||
subscription := &model.Subscription{
|
||||
Subscriber: model.Subscriber{
|
||||
SubscriberID: "test-subscriber",
|
||||
@@ -161,9 +160,6 @@ func TestRegistryProvider_IntegrationTest(t *testing.T) {
|
||||
Status: "SUBSCRIBED",
|
||||
}
|
||||
|
||||
err = registry.Subscribe(ctx, subscription)
|
||||
require.NoError(t, err)
|
||||
|
||||
// Test Lookup
|
||||
results, err := registry.Lookup(ctx, subscription)
|
||||
require.NoError(t, err)
|
||||
@@ -249,18 +245,6 @@ func TestRegistryProvider_ConfigurationParsing(t *testing.T) {
|
||||
require.NotNil(t, closer)
|
||||
defer closer()
|
||||
|
||||
// The registry should work regardless of invalid config values
|
||||
subscription := &model.Subscription{
|
||||
KeyID: "test-key",
|
||||
SigningPublicKey: "test-signing-key",
|
||||
EncrPublicKey: "test-encryption-key",
|
||||
ValidFrom: time.Now(),
|
||||
ValidUntil: time.Now().Add(24 * time.Hour),
|
||||
Status: "SUBSCRIBED",
|
||||
}
|
||||
|
||||
err = registry.Subscribe(ctx, subscription)
|
||||
assert.NoError(t, err)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,22 +47,22 @@ func New(ctx context.Context, cfg *Config) (*RegistryClient, func() error, error
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
retryClient := retryablehttp.NewClient()
|
||||
rc := retryablehttp.NewClient()
|
||||
|
||||
// Configure retry settings if provided
|
||||
if cfg.RetryMax > 0 {
|
||||
retryClient.RetryMax = cfg.RetryMax
|
||||
rc.RetryMax = cfg.RetryMax
|
||||
}
|
||||
if cfg.RetryWaitMin > 0 {
|
||||
retryClient.RetryWaitMin = cfg.RetryWaitMin
|
||||
rc.RetryWaitMin = cfg.RetryWaitMin
|
||||
}
|
||||
if cfg.RetryWaitMax > 0 {
|
||||
retryClient.RetryWaitMax = cfg.RetryWaitMax
|
||||
rc.RetryWaitMax = cfg.RetryWaitMax
|
||||
}
|
||||
|
||||
client := &RegistryClient{
|
||||
config: cfg,
|
||||
client: retryClient,
|
||||
client: rc,
|
||||
}
|
||||
|
||||
// Cleanup function
|
||||
@@ -74,7 +74,7 @@ func New(ctx context.Context, cfg *Config) (*RegistryClient, func() error, error
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Infof(ctx, "Registry client connection established successfully")
|
||||
log.Infof(ctx, "Registry client is created successfully")
|
||||
return client, closer, nil
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func (c *RegistryClient) Subscribe(ctx context.Context, subscription *model.Subs
|
||||
return fmt.Errorf("subscribe request failed with status: %s", resp.Status)
|
||||
}
|
||||
|
||||
log.Debugf(ctx, "Subscribe request successful")
|
||||
log.Debugf(ctx, "Subscribe request is initiated successfully")
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user