Skip to content

Commit

Permalink
Rename SSL_DOMAIN to TLS_DOMAIN
Browse files Browse the repository at this point in the history
  • Loading branch information
3v0k4 committed Apr 16, 2024
1 parent 356d1f0 commit 0df229e
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 57 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Unreleased

* Deprecate `SSL_DOMAIN` in favor of `TLS_DOMAIN`
* [BREAKING] Rename the `SSL_DOMAIN` env to `TLS_DOMAIN`

## v0.1.3 / 2024-03-21

Expand Down
2 changes: 0 additions & 2 deletions cmd/thrust/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ func setLogger(level slog.Level) {
}

func main() {
setLogger(slog.LevelWarn)

config, err := internal.NewConfig()
if err != nil {
fmt.Printf("ERROR: %s\n", err)
Expand Down
14 changes: 1 addition & 13 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,6 @@ type Config struct {
LogLevel slog.Level
}

var warn func(msg string, args ...any)

func init() {
warn = slog.Warn
}

func NewConfig() (*Config, error) {
if len(os.Args) < 2 {
return nil, errors.New("missing upstream command")
Expand All @@ -77,12 +71,6 @@ func NewConfig() (*Config, error) {
logLevel = slog.LevelDebug
}

sslDomain := getEnvString("SSL_DOMAIN", "")
if sslDomain != "" {
warn("SSL_DOMAIN is deprecated. Use TLS_DOMAIN instead.", "SSL_DOMAIN", sslDomain)
}
tlsDomain := getEnvString("TLS_DOMAIN", sslDomain)

return &Config{
TargetPort: getEnvInt("TARGET_PORT", defaultTargetPort),
UpstreamCommand: os.Args[1],
Expand All @@ -93,7 +81,7 @@ func NewConfig() (*Config, error) {
XSendfileEnabled: getEnvBool("X_SENDFILE_ENABLED", true),
MaxRequestBody: getEnvInt("MAX_REQUEST_BODY", defaultMaxRequestBody),

TLSDomain: tlsDomain,
TLSDomain: getEnvString("TLS_DOMAIN", ""),
ACMEDirectoryURL: getEnvString("ACME_DIRECTORY", defaultACMEDirectoryURL),
EAB_KID: getEnvString("EAB_KID", ""),
EAB_HMACKey: getEnvString("EAB_HMAC_KEY", ""),
Expand Down
41 changes: 0 additions & 41 deletions internal/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,64 +11,23 @@ import (

func TestConfig_tls(t *testing.T) {
t.Run("with no ENV", func(t *testing.T) {
var calls int
warn = func(msg string, args ...any) {
calls++
}
usingProgramArgs(t, "thruster", "echo", "hello")

c, err := NewConfig()
require.NoError(t, err)

assert.Equal(t, calls, 0)
assert.Equal(t, "", c.TLSDomain)
})

t.Run("with deprecated SSL_DOMAIN", func(t *testing.T) {
var warns []string
warn = func(msg string, args ...any) {
warns = append(warns, msg)
}
usingProgramArgs(t, "thruster", "echo", "hello")
usingEnvVar(t, "SSL_DOMAIN", "example.com")

c, err := NewConfig()
require.NoError(t, err)

assert.Equal(t, warns, []string{"SSL_DOMAIN is deprecated. Use TLS_DOMAIN instead."})
assert.Equal(t, "example.com", c.TLSDomain)
})

t.Run("with TLS_DOMAIN", func(t *testing.T) {
var calls int
warn = func(msg string, args ...any) {
calls++
}
usingProgramArgs(t, "thruster", "echo", "hello")
usingEnvVar(t, "TLS_DOMAIN", "example.com")

c, err := NewConfig()
require.NoError(t, err)

assert.Equal(t, calls, 0)
assert.Equal(t, "example.com", c.TLSDomain)
})

t.Run("with both SSL_DOMAIN and TLS_DOMAIN", func(t *testing.T) {
var warns []string
warn = func(msg string, args ...any) {
warns = append(warns, msg)
}
usingProgramArgs(t, "thruster", "echo", "hello")
usingEnvVar(t, "SSL_DOMAIN", "ssl.example.com")
usingEnvVar(t, "TLS_DOMAIN", "tls.example.com")

c, err := NewConfig()
require.NoError(t, err)

assert.Equal(t, warns, []string{"SSL_DOMAIN is deprecated. Use TLS_DOMAIN instead."})
assert.Equal(t, "tls.example.com", c.TLSDomain)
})
}

func TestConfig_defaults(t *testing.T) {
Expand Down

0 comments on commit 0df229e

Please sign in to comment.