Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Omit runtime SatoriClient warning log if Satori config is empty #1079

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions internal/satori/satori.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ func NewSatoriClient(logger *zap.Logger, satoriUrl, apiKeyName, apiKey, signingK
tokenExpirySec: 3600,
}

if err := sc.validateConfig(); err != nil {
if sc.urlString == "" && sc.apiKeyName == "" && sc.apiKey == "" && sc.signingKey == "" {
sc.invalidConfig = true
} else if err := sc.validateConfig(); err != nil {
sc.invalidConfig = true
logger.Warn(err.Error())
}
Expand All @@ -69,18 +71,23 @@ func NewSatoriClient(logger *zap.Logger, satoriUrl, apiKeyName, apiKey, signingK

func (s *SatoriClient) validateConfig() error {
errorStrings := make([]string, 0)
if s.url == nil {
_, err := url.Parse(s.urlString)
satoriUrl, err := url.Parse(s.urlString)
if err != nil {
errorStrings = append(errorStrings, fmt.Sprintf("Invalid URL: %s", err.Error()))
}
if s.apiKeyName == "" {
errorStrings = append(errorStrings, "api_key_name not set")
}
if s.apiKey == "" {
errorStrings = append(errorStrings, "api_key not set")
}
if s.signingKey == "" {
errorStrings = append(errorStrings, "signing_key not set")

if satoriUrl.String() != "" {
if s.apiKeyName == "" {
errorStrings = append(errorStrings, "api_key_name not set")
}
if s.apiKey == "" {
errorStrings = append(errorStrings, "api_key not set")
}
if s.signingKey == "" {
errorStrings = append(errorStrings, "signing_key not set")
}
} else if s.apiKeyName != "" || s.apiKey != "" || s.signingKey != "" {
errorStrings = append(errorStrings, "Satori configuration incomplete: url not set")
}

if len(errorStrings) > 0 {
Expand Down
Loading