Skip to content

Commit

Permalink
Replacing available env lookup with packaged utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
andream16 committed Nov 26, 2024
1 parent 0b359ee commit 5aaa1ea
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 521 deletions.
15 changes: 8 additions & 7 deletions sdk/component/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/go-errors/errors"
"github.com/smithy-security/pkg/env"

"github.com/smithy-security/smithy/sdk"
"github.com/smithy-security/smithy/sdk/component/internal/uuid"
Expand Down Expand Up @@ -191,12 +192,12 @@ func newRunnerConfig() (*RunnerConfig, error) {
return nil, errors.Errorf("could not construct panic handler: %w", err)
}

componentName, err := fromEnvOrDefault(envVarKeyComponentName, "", withFallbackToDefaultOnError(true))
componentName, err := env.GetOrDefault(envVarKeyComponentName, "", env.WithDefaultOnError(true))
if err != nil {
return nil, errors.Errorf("could not lookup environment for '%s': %w", envVarKeyComponentName, err)
}

instanceIDStr, err := fromEnvOrDefault(envVarKeyInstanceID, "", withFallbackToDefaultOnError(true))
instanceIDStr, err := env.GetOrDefault(envVarKeyInstanceID, "", env.WithDefaultOnError(true))
if err != nil {
return nil, errors.Errorf("could not lookup environment for '%s': %w", envVarKeyInstanceID, err)
}
Expand All @@ -208,10 +209,10 @@ func newRunnerConfig() (*RunnerConfig, error) {
// --- END - BASIC ENV - END ---

// --- BEGIN - LOGGING ENV - BEGIN ---
logLevel, err := fromEnvOrDefault(
logLevel, err := env.GetOrDefault(
envVarKeyLoggingLogLevel,
RunnerConfigLoggingLevelDebug.String(),
withFallbackToDefaultOnError(true),
env.WithDefaultOnError(true),
)
if err != nil {
return nil, errors.Errorf("could not lookup environment for '%s': %w", envVarKeyLoggingLogLevel, err)
Expand All @@ -224,7 +225,7 @@ func newRunnerConfig() (*RunnerConfig, error) {
// --- END - LOGGING ENV - END ---

// --- BEGIN - STORER ENV - BEGIN ---
st, err := fromEnvOrDefault(envVarKeyBackendStoreType, "", withFallbackToDefaultOnError(true))
st, err := env.GetOrDefault(envVarKeyBackendStoreType, "", env.WithDefaultOnError(true))
if err != nil {
return nil, errors.Errorf("could not lookup environment for '%s': %w", envVarKeyBackendStoreType, err)
}
Expand All @@ -248,10 +249,10 @@ func newRunnerConfig() (*RunnerConfig, error) {

conf.storerConfig.storeType = storageType

dbDSN, err := fromEnvOrDefault(
dbDSN, err := env.GetOrDefault(
envVarKeyBackendStoreDSN,
"smithy.db",
withFallbackToDefaultOnError(true),
env.WithDefaultOnError(true),
)
if err != nil {
return nil, errors.Errorf("could not lookup environment for '%s': %w", envVarKeyBackendStoreDSN, err)
Expand Down
127 changes: 0 additions & 127 deletions sdk/component/env.go

This file was deleted.

Loading

0 comments on commit 5aaa1ea

Please sign in to comment.