Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions admin/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,22 @@ func WithDBLogger(dbfile string, config *backend.JSONConfigurationDB) HandlersOp
}
logger, err := logging.CreateLoggerDBConfig(*config)
if err != nil {
log.Err(err).Msg("error creating DB logger")
logger.Enabled = false
logger.Database = nil
log.Err(err).Msg("error creating DB logger (config)")
logger = &logging.LoggerDB{
Enabled: false,
Database: nil,
}
}
h.DBLogger = logger
return
}
logger, err := logging.CreateLoggerDBFile(dbfile)
if err != nil {
log.Err(err).Msg("error creating DB logger")
logger.Enabled = false
logger.Database = nil
log.Err(err).Msg("error creating DB logger (file)")
logger = &logging.LoggerDB{
Enabled: false,
Database: nil,
}
}
h.DBLogger = logger
}
Expand Down
6 changes: 5 additions & 1 deletion admin/jwt.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ package main
import (
"crypto/rsa"
"crypto/tls"
"fmt"

"github.com/golang-jwt/jwt/v4"
"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/types"
"github.com/spf13/viper"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)

// Function to load the configuration file
Expand All @@ -22,6 +23,9 @@ func loadJWTConfiguration(file string) (types.JSONConfigurationJWT, error) {
}
// JWT values
jwtRaw := viper.Sub(settings.AuthJWT)
if jwtRaw == nil {
return cfg, fmt.Errorf("JSON key %s not found in file %s", settings.AuthJWT, file)
}
if err := jwtRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
Expand Down
2 changes: 1 addition & 1 deletion admin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func loadConfiguration(file, service string) (types.JSONConfigurationAdmin, erro
// Admin values
adminRaw := viper.Sub(service)
if adminRaw == nil {
return cfg, fmt.Errorf("JSON key %s not found in %s", service, file)
return cfg, fmt.Errorf("JSON key %s not found in file %s", service, file)
}
if err := adminRaw.Unmarshal(&cfg); err != nil {
return cfg, err
Expand Down
5 changes: 5 additions & 0 deletions admin/oauth.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"

"github.com/jmpsec/osctrl/settings"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
Expand All @@ -26,6 +28,9 @@ func loadOAuth(file string) (JSONConfigurationOAuth, error) {
}
// OAuth values
oauthRaw := viper.Sub(settings.AuthOAuth)
if oauthRaw == nil {
return cfg, fmt.Errorf("JSON key %s not found in %s", settings.AuthOAuth, file)
}
if err := oauthRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
Expand Down
6 changes: 5 additions & 1 deletion admin/oidc.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package main

import (
"fmt"

"github.com/jmpsec/osctrl/settings"
"github.com/spf13/viper"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
)

// JSONConfigurationOIDC to keep all OIDC details for auth
Expand All @@ -30,6 +31,9 @@ func loadOIDC(file string) (JSONConfigurationOIDC, error) {
}
// OAuth values
oauthRaw := viper.Sub(settings.AuthOIDC)
if oauthRaw == nil {
return cfg, fmt.Errorf("JSON key %s not found in %s", settings.AuthOIDC, file)
}
if err := oauthRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
Expand Down
3 changes: 3 additions & 0 deletions admin/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ func loadSAML(file string) (JSONConfigurationSAML, error) {
}
// SAML values
samlRaw := viper.Sub(settings.AuthSAML)
if samlRaw == nil {
return cfg, fmt.Errorf("JSON key %s not found in %s", settings.AuthSAML, file)
}
if err := samlRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
Expand Down
9 changes: 7 additions & 2 deletions api/jwt.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"fmt"

"github.com/jmpsec/osctrl/settings"
"github.com/jmpsec/osctrl/types"
"github.com/rs/zerolog/log"
Expand All @@ -17,8 +19,11 @@ func loadJWTConfiguration(file string) (types.JSONConfigurationJWT, error) {
return cfg, err
}
// JWT values
headersRaw := viper.Sub(settings.AuthJWT)
if err := headersRaw.Unmarshal(&cfg); err != nil {
jwtRaw := viper.Sub(settings.AuthJWT)
if jwtRaw == nil {
return cfg, fmt.Errorf("JSON key %s not found in %s", settings.AuthJWT, file)
}
if err := jwtRaw.Unmarshal(&cfg); err != nil {
return cfg, err
}
// No errors!
Expand Down
3 changes: 3 additions & 0 deletions backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ func LoadConfiguration(file, key string) (JSONConfigurationDB, error) {
}
// Backend values
dbRaw := viper.Sub(key)
if dbRaw == nil {
return config, fmt.Errorf("JSON key %s not found in %s", key, file)
}
if err := dbRaw.Unmarshal(&config); err != nil {
return config, err
}
Expand Down
7 changes: 5 additions & 2 deletions cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,11 @@ func LoadConfiguration(file, key string) (JSONConfigurationRedis, error) {
return config, err
}
// Backend values
dbRaw := viper.Sub(key)
if err := dbRaw.Unmarshal(&config); err != nil {
redisRaw := viper.Sub(key)
if redisRaw == nil {
return config, fmt.Errorf("JSON key %s not found in %s", key, file)
}
if err := redisRaw.Unmarshal(&config); err != nil {
return config, err
}
// No errors!
Expand Down
3 changes: 3 additions & 0 deletions carves/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ func LoadS3(file string) (types.S3Configuration, error) {
return _s3Cfg, err
}
cfgRaw := viper.Sub(settings.LoggingS3)
if cfgRaw == nil {
return _s3Cfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingS3, file)
}
if err := cfgRaw.Unmarshal(&_s3Cfg); err != nil {
return _s3Cfg, err
}
Expand Down
2 changes: 1 addition & 1 deletion cli/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func loadAPIConfiguration(file string) (JSONConfigurationAPI, error) {
// API values
apiRaw := viper.Sub(projectName)
if apiRaw == nil {
return config, fmt.Errorf("could not find key %s", projectName)
return config, fmt.Errorf("JSON key %s not found in %s", projectName, file)
}
if err := apiRaw.Unmarshal(&config); err != nil {
return config, err
Expand Down
3 changes: 3 additions & 0 deletions logging/elastic.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ func LoadElastic(file string) (ElasticConfiguration, error) {
return _elasticCfg, err
}
cfgRaw := viper.Sub(settings.LoggingElastic)
if cfgRaw == nil {
return _elasticCfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingElastic, file)
}
if err := cfgRaw.Unmarshal(&_elasticCfg); err != nil {
return _elasticCfg, err
}
Expand Down
7 changes: 5 additions & 2 deletions logging/graylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logging

import (
"encoding/json"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -32,8 +33,10 @@ func LoadGraylog(file string) (GraylogConfiguration, error) {
return _graylogCfg, err
}
cfgRaw := viper.Sub(settings.LoggingGraylog)
err = cfgRaw.Unmarshal(&_graylogCfg)
if err != nil {
if cfgRaw == nil {
return _graylogCfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingGraylog, file)
}
if err := cfgRaw.Unmarshal(&_graylogCfg); err != nil {
return _graylogCfg, err
}
// No errors!
Expand Down
3 changes: 3 additions & 0 deletions logging/kinesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ func LoadKinesis(file string) (KinesisConfiguration, error) {
return _kinesisCfg, err
}
cfgRaw := viper.Sub(settings.LoggingSplunk)
if cfgRaw == nil {
return _kinesisCfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingSplunk, file)
}
if err := cfgRaw.Unmarshal(&_kinesisCfg); err != nil {
return _kinesisCfg, err
}
Expand Down
3 changes: 3 additions & 0 deletions logging/logstash.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ func LoadLogstash(file string) (LogstashConfiguration, error) {
return _logstashCfg, err
}
cfgRaw := viper.Sub(settings.LoggingLogstash)
if cfgRaw == nil {
return _logstashCfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingLogstash, file)
}
if err := cfgRaw.Unmarshal(&_logstashCfg); err != nil {
return _logstashCfg, err
}
Expand Down
4 changes: 4 additions & 0 deletions logging/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package logging
import (
"bytes"
"context"
"fmt"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -72,6 +73,9 @@ func LoadS3(file string) (types.S3Configuration, error) {
return _s3Cfg, err
}
cfgRaw := viper.Sub(settings.LoggingS3)
if cfgRaw == nil {
return _s3Cfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingS3, file)
}
if err := cfgRaw.Unmarshal(&_s3Cfg); err != nil {
return _s3Cfg, err
}
Expand Down
4 changes: 4 additions & 0 deletions logging/splunk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logging

import (
"encoding/json"
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -54,6 +55,9 @@ func LoadSplunk(file string) (SlunkConfiguration, error) {
return _splunkCfg, err
}
cfgRaw := viper.Sub(settings.LoggingSplunk)
if cfgRaw == nil {
return _splunkCfg, fmt.Errorf("JSON key %s not found in %s", settings.LoggingSplunk, file)
}
if err := cfgRaw.Unmarshal(&_splunkCfg); err != nil {
return _splunkCfg, err
}
Expand Down
3 changes: 3 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ func LoadConfiguration() (Configuration, error) {
return _metricsCfg, err
}
cfgRaw := viper.Sub(metricsName)
if cfgRaw == nil {
return _metricsCfg, fmt.Errorf("JSON key %s not found in %s", metricsName, metricsConfigFile)
}
if err := cfgRaw.Unmarshal(&_metricsCfg); err != nil {
return _metricsCfg, err
}
Expand Down
Loading