generated from ydataai/opensource-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,035 additions
and
115 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package clients | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// StorageClient is a structure that holds all the dependencies for the following client | ||
type StorageClient struct { | ||
logger *logrus.Logger | ||
configuration StorageClientConfiguration | ||
} | ||
|
||
// NewStorageClient returns an initialized struct with the required dependencies injected | ||
func NewStorageClient(logger *logrus.Logger, configuration StorageClientConfiguration) StorageClient { | ||
return StorageClient{ | ||
logger: logger, | ||
configuration: configuration, | ||
} | ||
} | ||
|
||
// CreateWorkspace attempts to create a directory to hold requirements.txt | ||
func (sc StorageClient) CreateWorkspace(obj, relativePath string) error { | ||
fullPath := fmt.Sprintf("%s/%s/%s", sc.configuration.BasePath, obj, relativePath) | ||
|
||
sc.logger.Info("Attempting to create directory ", fullPath) | ||
|
||
if _, err := os.Stat(fullPath); os.IsNotExist(err) { | ||
return os.MkdirAll(fullPath, os.ModePerm) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// CheckIfExists attempts to check if the directory exists | ||
func (sc *StorageClient) CheckIfExists(obj, relativePath string) bool { | ||
fullPath := fmt.Sprintf("%s/%s/%s", sc.configuration.BasePath, obj, relativePath) | ||
|
||
_, err := os.Stat(fullPath) | ||
if err != nil && os.IsNotExist(err) { | ||
return false | ||
} | ||
|
||
return true | ||
} | ||
|
||
// RemoveDirectory attempts to remove the directory that holds requirements.txt | ||
func (sc StorageClient) RemoveDirectory(obj, relativePath string) error { | ||
fullPath := fmt.Sprintf("%s/%s/%s", sc.configuration.BasePath, obj, relativePath) | ||
sc.logger.Info("Attempting to remove ", fullPath) | ||
return os.RemoveAll(fullPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package clients | ||
|
||
import ( | ||
"github.com/kelseyhightower/envconfig" | ||
) | ||
|
||
// StorageClientConfiguration is a struct that holds all the environment variables required to the Storage Client | ||
type StorageClientConfiguration struct { | ||
BasePath string `envconfig:"STORAGE_PATH" required:"true"` | ||
} | ||
|
||
// LoadFromEnvVars parses the required configuration variables. Throws an error if the validations aren't met | ||
func (c *StorageClientConfiguration) LoadFromEnvVars() error { | ||
return envconfig.Process("", c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,30 @@ | ||
package common | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strconv" | ||
) | ||
package config | ||
|
||
// ConfigurationVariables is an interface with LoadFromEnvVars method. The method is meant to be implemented as a struct | ||
// method: | ||
// | ||
// type StructWithVars struct { | ||
// var1 string | ||
// var2 string | ||
// Var1 string `envconfig:"VAR1"` | ||
// Var2 string `envconfig:"VAR2"` | ||
// } | ||
// | ||
// func (swv *StructWithVars) LoadFromEnvVars() error { | ||
// swv.var1 = os.Getenv("VALUE_1") | ||
// swv.var2 = "value 2" | ||
// } | ||
// func (swv *StructWithVars) LoadFromEnvVars() error { | ||
// if err := envconfig.Process("", swv); err != nil { | ||
// return err | ||
// } | ||
// return nil | ||
// } | ||
// | ||
type ConfigurationVariables interface { | ||
LoadFromEnvVars() error | ||
} | ||
|
||
// VariableFromEnvironment check from the value in the os.Getenv and returns it of error if doesn't exists. | ||
func VariableFromEnvironment(env string) (string, error) { | ||
value := os.Getenv(env) | ||
if value == "" { | ||
return "", fmt.Errorf("%s variable not set", env) | ||
} | ||
|
||
return value, nil | ||
} | ||
|
||
// BooleanVariableFromEnvironment check from the value in the os.Getenv, converts to boolean returns it of error if doesn't exists. | ||
func BooleanVariableFromEnvironment(env string) (bool, error) { | ||
value, err := VariableFromEnvironment(env) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
booleanValue, err := strconv.ParseBool(value) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
return booleanValue, nil | ||
} | ||
|
||
// IntVariableFromEnvironment check from the value in the os.Getenv and returns it of error if doesn't exists. | ||
func IntVariableFromEnvironment(env string) (int, error) { | ||
value, err := VariableFromEnvironment(env) | ||
if err != nil { | ||
return 0, err | ||
// InitConfigurationVariables according to environment | ||
func InitConfigurationVariables(configs []ConfigurationVariables) error { | ||
for _, configuration := range configs { | ||
if err := configuration.LoadFromEnvVars(); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
intValue, err := strconv.Atoi(value) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return intValue, nil | ||
} | ||
|
||
// Int32VariableFromEnvironment check from the value in the os.Getenv and returns it of error if doesn't exists. | ||
func Int32VariableFromEnvironment(env string) (int32, error) { | ||
value, err := IntVariableFromEnvironment(env) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return int32(value), nil | ||
} | ||
|
||
// Int64VariableFromEnvironment check from the value in the os.Getenv and returns it of error if doesn't exists. | ||
func Int64VariableFromEnvironment(env string) (int64, error) { | ||
value, err := IntVariableFromEnvironment(env) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return int64(value), nil | ||
return nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/kelseyhightower/envconfig" | ||
) | ||
|
||
// ManagerConfiguration defines required variables to configure the environment | ||
type ManagerConfiguration struct { | ||
EnableLeaderElection bool `envconfig:"ENABLE_LEADER_ELECTION" required:"true"` | ||
LeaderElectionID string `envconfig:"LEADER_ELECTION_ID" required:"true"` | ||
Port int `envconfig:"MANAGER_PORT" default:"9443"` | ||
MetricsServerPort int `envconfig:"METRICS_SERVER_PORT" default:"8080"` | ||
HealthProbeAddress string `envconfig:"HEALTH_PROBE_ADDRESS" default:":8081"` | ||
} | ||
|
||
// LoadFromEnvVars from the Manager | ||
func (c *ManagerConfiguration) LoadFromEnvVars() error { | ||
return envconfig.Process("", c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package config | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/kelseyhightower/envconfig" | ||
) | ||
|
||
// RESTControllerConfiguration defines a struct with required environment variables for rest controller | ||
type RESTControllerConfiguration struct { | ||
UserID string `envconfig:"USER_ID" required:"true"` | ||
UserIDPrefix string `envconfig:"USER_ID_PREFIX" default:""` | ||
HTTPRequestTimeout time.Duration `envconfig:"HTTP_REQUEST_TIMEOUT" default:"30s"` | ||
} | ||
|
||
// LoadFromEnvVars reads all env vars required | ||
func (c *RESTControllerConfiguration) LoadFromEnvVars() error { | ||
return envconfig.Process("", c) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.