Skip to content

Commit 2068b0f

Browse files
committed
fix
1 parent 417d354 commit 2068b0f

3 files changed

Lines changed: 10 additions & 5 deletions

File tree

aws/logs_monitoring_go/internal/config/apikey.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"log/slog"
1414
"net/http"
1515
"os"
16+
"strings"
1617
"time"
1718

1819
"github.com/aws/aws-sdk-go-v2/aws"
@@ -70,7 +71,8 @@ func (c *Config) resolveAPIKey(ctx context.Context) error {
7071
if err != nil {
7172
return fmt.Errorf("resolving API key from %s: %w", resolver.envVar, err)
7273
}
73-
c.APIKey = key
74+
c.APIKey = strings.TrimSpace(key)
75+
slog.Debug("API key resolved", "source", resolver.envVar)
7476
return nil
7577
}
7678
}
@@ -116,6 +118,7 @@ func (c *Config) validateAPIKey() error {
116118
resp.Body.Close()
117119

118120
if resp.StatusCode >= 200 && resp.StatusCode < 300 {
121+
slog.Debug("API key validated successfully")
119122
return nil
120123
}
121124

aws/logs_monitoring_go/internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func Load(ctx context.Context) (*Config, error) {
5050
}
5151

5252
cfg.deriveURLs()
53+
slog.Debug("config loaded", "site", cfg.Site, "intakeURL", cfg.IntakeURL, "apiURL", cfg.APIURL, "port", cfg.Port, "noSSL", cfg.NoSSL, "useFIPS", cfg.UseFIPS)
5354

5455
logDroppedEnvVars()
5556

@@ -69,7 +70,7 @@ func (c *Config) deriveURLs() {
6970
if c.NoSSL {
7071
scheme = "http"
7172
}
72-
c.IntakeURL = envOrDefault("DD_URL", "http-intake.logs."+c.Site)
73+
c.IntakeURL = envOrDefault("DD_URL", fmt.Sprintf("%s://http-intake.logs.%s", scheme, c.Site))
7374
c.APIURL = envOrDefault("DD_API_URL", fmt.Sprintf("%s://api.%s", scheme, c.Site))
7475
}
7576

aws/logs_monitoring_go/internal/config/config_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@ func TestDeriveURLs(t *testing.T) {
1111
t.Run("defaults", func(t *testing.T) {
1212
cfg := &Config{Site: "datadoghq.com", NoSSL: false}
1313
cfg.deriveURLs()
14-
assert.Equal(t, "http-intake.logs.datadoghq.com", cfg.IntakeURL)
14+
assert.Equal(t, "https://http-intake.logs.datadoghq.com", cfg.IntakeURL)
1515
assert.Equal(t, "https://api.datadoghq.com", cfg.APIURL)
1616
})
1717

1818
t.Run("NoSSL switches scheme to http", func(t *testing.T) {
1919
cfg := &Config{Site: "datadoghq.com", NoSSL: true}
2020
cfg.deriveURLs()
21+
assert.Equal(t, "http://http-intake.logs.datadoghq.com", cfg.IntakeURL)
2122
assert.Equal(t, "http://api.datadoghq.com", cfg.APIURL)
2223
})
2324

2425
t.Run("custom site", func(t *testing.T) {
2526
cfg := &Config{Site: "datadoghq.eu", NoSSL: false}
2627
cfg.deriveURLs()
27-
assert.Equal(t, "http-intake.logs.datadoghq.eu", cfg.IntakeURL)
28+
assert.Equal(t, "https://http-intake.logs.datadoghq.eu", cfg.IntakeURL)
2829
assert.Equal(t, "https://api.datadoghq.eu", cfg.APIURL)
2930
})
3031

@@ -57,7 +58,7 @@ func TestLoad(t *testing.T) {
5758
assert.Equal(t, false, cfg.SkipSSLValidation)
5859
assert.Equal(t, "INFO", cfg.LogLevel)
5960
assert.Equal(t, false, cfg.UseFIPS)
60-
assert.Equal(t, "http-intake.logs.datadoghq.com", cfg.IntakeURL)
61+
assert.Equal(t, "https://http-intake.logs.datadoghq.com", cfg.IntakeURL)
6162
assert.Equal(t, "abcdef1234567890abcdef1234567890", cfg.APIKey)
6263
})
6364

0 commit comments

Comments
 (0)