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
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ For more details see the github repo at https://github.com/saferwall
return nil
}
cfgFilePath := filepath.Join(util.UserHomeDir(), ".config", "saferwall")
if err := config.Load(cfgFilePath, "", &cfg); err != nil {
if err := config.Load(cfgFilePath, &cfg); err != nil {
return fmt.Errorf("failed loading CLI config: %v\nRun 'saferwall-cli init' to configure", err)
}
return nil
Expand Down
2 changes: 0 additions & 2 deletions cmd/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import (
)

const (
statusQueued = 1
statusScanning = 2
statusCompleted = 3

pollInterval = 5 * time.Second
Expand Down
76 changes: 6 additions & 70 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,91 +14,27 @@ type CredentialsCfg struct {
APIKey string `mapstructure:"api_key"`
}

// AWSS3Cfg represents AWS S3 credentials.
type AWSS3Cfg struct {
Region string `mapstructure:"region"`
SecretKey string `mapstructure:"secret_key"`
AccessKey string `mapstructure:"access_key"`
}

// MinIOCfg represents MinIO credentials.
type MinIOCfg struct {
Endpoint string `mapstructure:"endpoint"`
Region string `mapstructure:"region"`
SecretKey string `mapstructure:"secret_key"`
AccessKey string `mapstructure:"access_key"`
}

// LocalFsCfg represents local file system storage data.
type LocalFsCfg struct {
RootDir string `mapstructure:"root_dir"`
}

// StorageCfg represents the object storage config.
type StorageCfg struct {
// Deployment kind, possible values: aws, gcp, azure, local.
DeploymentKind string `mapstructure:"deployment_kind"`
SamplesBucket string `mapstructure:"samples_bucket"`
ArtifactsBucket string `mapstructure:"artifacts_bucket"`
S3 AWSS3Cfg `mapstructure:"s3"`
MinIO MinIOCfg `mapstructure:"minio"`
Local LocalFsCfg `mapstructure:"local"`
}

// DatabaseCfg represents the database config.
type DatabaseCfg struct {
// the data source name (DSN) for connecting to the database.
Server string `mapstructure:"server"`
// Username used to access the db.
Username string `mapstructure:"username"`
// Password used to access the db.
Password string `mapstructure:"password"`
// Name of the couchbase bucket.
BucketName string `mapstructure:"bucket_name"`
}

// Config represents our CLI app config.
type Config struct {
Credentials CredentialsCfg `mapstructure:"credentials"`
Storage StorageCfg `mapstructure:"storage"`
DB DatabaseCfg `mapstructure:"db"`
}

// Load returns an application configuration which is populated
// from the given configuration file.
func Load(path, env string, c any) error {
// from the config file in the given directory.
func Load(path string, c any) error {

// Adding our TOML config file.
viper.AddConfigPath(path)

// Load the config type depending on env variable.
var name string
switch env {
case "local":
name = "local"
case "dev":
name = "dev"
case "prod":
name = "prod"
default:
name = "config"
}

// Set the config name to choose from the config path
// Set the config name to choose from the config path.
// Extension not needed.
viper.SetConfigName(name)
viper.SetConfigName("config")

// Load the configuration from disk.
err := viper.ReadInConfig()
if err != nil {
if err := viper.ReadInConfig(); err != nil {
return err
}

// Unmarshal the config into our interface.
err = viper.Unmarshal(&c)
if err != nil {
return err
}

return err
return viper.Unmarshal(&c)
}
30 changes: 0 additions & 30 deletions internal/entity/user.go

This file was deleted.

10 changes: 3 additions & 7 deletions internal/webapi/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,20 @@ import (
)

const (
usersEndpoint = "/v1/users/"
filesEndpoint = "/v1/files/"

defaultTimeout = 5 * time.Minute
)

type Service struct {
filesURL string
usersURL string
client *http.Client
}

// New generates new web apis service object.
func New(baseURL string) Service {
s := Service{
client: &http.Client{Timeout: defaultTimeout},
return Service{
client: &http.Client{Timeout: defaultTimeout},
filesURL: baseURL + filesEndpoint,
}
s.usersURL = baseURL + usersEndpoint
s.filesURL = baseURL + filesEndpoint
return s
}
106 changes: 0 additions & 106 deletions internal/webapi/users.go

This file was deleted.