Skip to content

Commit de6cc33

Browse files
authored
chore: Read destination metadata path from config (#127)
* chore: Read destination metadata path from config * chore: Custom webhook instructions for docker compose example
1 parent 1966052 commit de6cc33

File tree

15 files changed

+55
-26
lines changed

15 files changed

+55
-26
lines changed

examples/docker-compose/compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ services:
1010
condition: service_healthy
1111
ports:
1212
- "${PORT}:${PORT}"
13+
volumes:
14+
- ./config/outpost:/config/outpost
1315
environment:
1416
SERVICE: api
1517

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Webhook
2+
3+
My custom webhook instructions!

internal/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type Config struct {
4444
RetryMaxCount int
4545
LogBatcherDelayThresholdSeconds int
4646
LogBatcherItemCountThreshold int
47+
DestinationMetadataPath string
4748
}
4849

4950
var defaultConfig = map[string]any{
@@ -63,6 +64,7 @@ var defaultConfig = map[string]any{
6364
"MAX_RETRY_COUNT": 10,
6465
"LOG_BATCHER_DELAY_THRESHOLD_SECONDS": 5,
6566
"LOG_BATCHER_ITEM_COUNT_THRESHOLD": 100,
67+
"DESTINATION_METADATA_PATH": "config/outpost/destinations",
6668
}
6769

6870
var (
@@ -179,6 +181,7 @@ func Parse(flags Flags) (*Config, error) {
179181
RetryMaxCount: mustInt(viper, "MAX_RETRY_COUNT"),
180182
LogBatcherDelayThresholdSeconds: mustInt(viper, "LOG_BATCHER_DELAY_THRESHOLD_SECONDS"),
181183
LogBatcherItemCountThreshold: mustInt(viper, "LOG_BATCHER_ITEM_COUNT_THRESHOLD"),
184+
DestinationMetadataPath: viper.GetString("DESTINATION_METADATA_PATH"),
182185
}
183186

184187
return config, nil

internal/destregistry/baseprovider.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ type BaseProvider struct {
1717
}
1818

1919
// NewBaseProvider creates a new base provider with loaded metadata
20-
func NewBaseProvider(providerType string) (*BaseProvider, error) {
21-
loader := metadata.NewMetadataLoader("")
20+
func NewBaseProvider(loader *metadata.MetadataLoader, providerType string) (*BaseProvider, error) {
2221
meta, err := loader.Load(providerType)
2322
if err != nil {
2423
return nil, fmt.Errorf("loading provider metadata: %w", err)

internal/destregistry/providers/default.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,21 @@ import (
88
)
99

1010
func RegisterDefault(registry destregistry.Registry) error {
11-
aws, err := destaws.New()
11+
loader := registry.MetadataLoader()
12+
13+
aws, err := destaws.New(loader)
1214
if err != nil {
1315
return err
1416
}
1517
registry.RegisterProvider("aws", aws)
1618

17-
rabbitmq, err := destrabbitmq.New()
19+
rabbitmq, err := destrabbitmq.New(loader)
1820
if err != nil {
1921
return err
2022
}
2123
registry.RegisterProvider("rabbitmq", rabbitmq)
2224

23-
webhook, err := destwebhook.New()
25+
webhook, err := destwebhook.New(loader)
2426
if err != nil {
2527
return err
2628
}

internal/destregistry/providers/destaws/destaws.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/aws/aws-sdk-go-v2/service/sqs/types"
1212
"github.com/aws/aws-sdk-go/aws"
1313
"github.com/hookdeck/outpost/internal/destregistry"
14+
"github.com/hookdeck/outpost/internal/destregistry/metadata"
1415
"github.com/hookdeck/outpost/internal/models"
1516
)
1617

@@ -32,8 +33,8 @@ type AWSDestinationCredentials struct {
3233

3334
var _ destregistry.Provider = (*AWSDestination)(nil)
3435

35-
func New() (*AWSDestination, error) {
36-
base, err := destregistry.NewBaseProvider("aws")
36+
func New(loader *metadata.MetadataLoader) (*AWSDestination, error) {
37+
base, err := destregistry.NewBaseProvider(loader, "aws")
3738
if err != nil {
3839
return nil, err
3940
}

internal/destregistry/providers/destaws/destaws_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestAWSDestination_Validate(t *testing.T) {
3636
}),
3737
)
3838

39-
awsDestination, err := destaws.New()
39+
awsDestination, err := destaws.New(testutil.Registry.MetadataLoader())
4040
require.NoError(t, err)
4141

4242
t.Run("should validate valid destination", func(t *testing.T) {
@@ -118,7 +118,7 @@ func TestIntegrationAWSDestination_Publish(t *testing.T) {
118118
require.NoError(t, err)
119119
queueURL, err := awsutil.EnsureQueue(context.Background(), sqsClient, mq.AWSSQS.Topic, nil)
120120
require.NoError(t, err)
121-
awsdestination, err := destaws.New()
121+
awsdestination, err := destaws.New(testutil.Registry.MetadataLoader())
122122
require.NoError(t, err)
123123

124124
destination := testutil.DestinationFactory.Any(

internal/destregistry/providers/destrabbitmq/destrabbitmq.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66

77
"github.com/hookdeck/outpost/internal/destregistry"
8+
"github.com/hookdeck/outpost/internal/destregistry/metadata"
89
"github.com/hookdeck/outpost/internal/models"
910
"github.com/rabbitmq/amqp091-go"
1011
)
@@ -25,8 +26,8 @@ type RabbitMQDestinationCredentials struct {
2526

2627
var _ destregistry.Provider = (*RabbitMQDestination)(nil)
2728

28-
func New() (*RabbitMQDestination, error) {
29-
base, err := destregistry.NewBaseProvider("rabbitmq")
29+
func New(loader *metadata.MetadataLoader) (*RabbitMQDestination, error) {
30+
base, err := destregistry.NewBaseProvider(loader, "rabbitmq")
3031
if err != nil {
3132
return nil, err
3233
}

internal/destregistry/providers/destrabbitmq/destrabbitmq_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestRabbitMQDestination_Validate(t *testing.T) {
3333
}),
3434
)
3535

36-
rabbitmqDestination, err := destrabbitmq.New()
36+
rabbitmqDestination, err := destrabbitmq.New(testutil.Registry.MetadataLoader())
3737
require.NoError(t, err)
3838

3939
t.Run("should validate valid destination", func(t *testing.T) {
@@ -108,7 +108,7 @@ func TestRabbitMQDestination_Validate(t *testing.T) {
108108
func TestRabbitMQDestination_Publish(t *testing.T) {
109109
t.Parallel()
110110

111-
rabbitmqDestination, err := destrabbitmq.New()
111+
rabbitmqDestination, err := destrabbitmq.New(testutil.Registry.MetadataLoader())
112112
require.NoError(t, err)
113113

114114
destination := testutil.DestinationFactory.Any(
@@ -139,7 +139,7 @@ func TestIntegrationRabbitMQDestination_Publish(t *testing.T) {
139139
t.Cleanup(testinfra.Start(t))
140140

141141
mq := testinfra.NewMQRabbitMQConfig(t)
142-
rabbitmqDestination, err := destrabbitmq.New()
142+
rabbitmqDestination, err := destrabbitmq.New(testutil.Registry.MetadataLoader())
143143
require.NoError(t, err)
144144

145145
destination := testutil.DestinationFactory.Any(

internal/destregistry/providers/destwebhook/destwebhook.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"net/http"
1111

1212
"github.com/hookdeck/outpost/internal/destregistry"
13+
"github.com/hookdeck/outpost/internal/destregistry/metadata"
1314
"github.com/hookdeck/outpost/internal/models"
1415
)
1516

@@ -23,8 +24,8 @@ type WebhookDestinationConfig struct {
2324

2425
var _ destregistry.Provider = (*WebhookDestination)(nil)
2526

26-
func New() (*WebhookDestination, error) {
27-
base, err := destregistry.NewBaseProvider("webhook")
27+
func New(loader *metadata.MetadataLoader) (*WebhookDestination, error) {
28+
base, err := destregistry.NewBaseProvider(loader, "webhook")
2829
if err != nil {
2930
return nil, err
3031
}

0 commit comments

Comments
 (0)