Repository: globocom/huskyCI
Pull request #443 (2019-12-16 16:38:23)

Refactoring environment variables
After reviewing and creating new huskyCI documentation, some environment variables code were not being used or a refactoring was needed.


Patch:
diff --git a/api/auth/pbkdf2caller.go b/api/auth/pbkdf2caller.go
index 6861523..1c36418 100644
--- a/api/auth/pbkdf2caller.go
+++ b/api/auth/pbkdf2caller.go
@@ -52,19 +52,27 @@ func (pC *Pbkdf2Caller) GetHashName() string {
 }
 
 // GetIterations returns the default number of iteration that is stored in an env var.
-func (pC *Pbkdf2Caller) GetIterations() (int, error) {
-	iterations := os.Getenv("HUSKYCI_API_DEFAULT_ITERATIONS")
-	if iterations != "" {
-		return strconv.Atoi(iterations)
+func (pC *Pbkdf2Caller) GetIterations() int {
+	rawIterations := os.Getenv("HUSKYCI_API_DEFAULT_ITERATIONS")
+	if rawIterations != "" {
+		iterations, err := strconv.Atoi(rawIterations)
+		if err != nil {
+			return 100000
+		}
+		return iterations
 	}
-	return 100000, nil
+	return 100000
 }
 
 // GetKeyLength returns the default key lenght that is stored in an env var.
-func (pC *Pbkdf2Caller) GetKeyLength() (int, error) {
-	keyLength := os.Getenv("HUSKYCI_API_DEFAULT_KEY_LENGTH")
-	if keyLength != "" {
-		return strconv.Atoi(keyLength)
+func (pC *Pbkdf2Caller) GetKeyLength() int {
+	rawKeyLength := os.Getenv("HUSKYCI_API_DEFAULT_KEY_LENGTH")
+	if rawKeyLength != "" {
+		keyLengh, err := strconv.Atoi(rawKeyLength)
+		if err != nil {
+			return 512
+		}
+		return keyLengh
 	}
-	return 512, nil
+	return 512
 }
diff --git a/api/auth/types.go b/api/auth/types.go
index ff657b5..7ff3584 100644
--- a/api/auth/types.go
+++ b/api/auth/types.go
@@ -23,8 +23,8 @@ type Pbkdf2Generator interface {
 	GenHashValue(value, salt []byte, iter, keyLen int, h hash.Hash) string
 	GenerateSalt() (string, error)
 	GetHashName() string
-	GetIterations() (int, error)
-	GetKeyLength() (int, error)
+	GetIterations() int
+	GetKeyLength() int
 }
 
 // Pbkdf2Caller is the pbkdf2 caller struct.
diff --git a/api/context/context.go b/api/context/context.go
index 28f245a..95a6094 100644
--- a/api/context/context.go
+++ b/api/context/context.go
@@ -44,14 +44,11 @@ type DBConfig struct {
 
 // DockerHostsConfig represents Docker Hosts configuration.
 type DockerHostsConfig struct {
-	Address              string
-	DockerAPIPort        int
-	Certificate          string
-	PathCertificate      string
-	Key                  string
-	Host                 string
-	TLSVerify            int
-	MaxContainersAllowed int
+	Address         string
+	DockerAPIPort   int
+	PathCertificate string
+	Host            string
+	TLSVerify       int
 }
 
 // GraylogConfig represents Graylog configuration.
@@ -156,7 +153,11 @@ func (dF DefaultConfig) GetAPIReleaseDate() string {
 
 // GetAllowOriginValue returns the allow origin value
 func (dF DefaultConfig) GetAllowOriginValue() string {
-	return dF.Caller.GetEnvironmentVariable("HUSKYCI_API_ALLOW_ORIGIN_CORS")
+	urlCORS := dF.Caller.GetEnvironmentVariable("HUSKYCI_API_ALLOW_ORIGIN_CORS")
+	if urlCORS == "" {
+		return "http://127.0.0.1:8888"
+	}
+	return urlCORS
 }
 
 // GetAPIUseTLS returns a boolean. If true, Husky API
@@ -287,18 +288,13 @@ func (dF DefaultConfig) getDockerHostsConfig() *DockerHostsConfig {
 	dockerAPIPort := dF.GetDockerAPIPort()
 	dockerHostsAddressesEnv := dF.Caller.GetEnvironmentVariable("HUSKYCI_DOCKERAPI_ADDR")
 	dockerHostsAddresses := strings.Split(dockerHostsAddressesEnv, " ")
-	dockerHostsCertificate := dF.Caller.GetEnvironmentVariable("HUSKYCI_DOCKERAPI_CERT_FILE")
 	dockerHostsPathCertificates := dF.Caller.GetEnvironmentVariable("HUSKYCI_DOCKERAPI_CERT_PATH")
-	dockerHostsKey := dF.Caller.GetEnvironmentVariable("HUSKYCI_DOCKERAPI_CERT_KEY")
 	return &DockerHostsConfig{
-		Address:              dockerHostsAddresses[0],
-		DockerAPIPort:        dockerAPIPort,
-		Certificate:          dockerHostsCertificate,
-		PathCertificate:      dockerHostsPathCertificates,
-		Key:                  dockerHostsKey,
-		Host:                 fmt.Sprintf("%s:%d", dockerHostsAddresses[0], dockerAPIPort),
-		TLSVerify:            dF.GetDockerAPITLSVerify(),
-		MaxContainersAllowed: dF.GetMaxContainersAllowed(),
+		Address:         dockerHostsAddresses[0],
+		DockerAPIPort:   dockerAPIPort,
+		PathCertificate: dockerHostsPathCertificates,
+		Host:            fmt.Sprintf("%s:%d", dockerHostsAddresses[0], dockerAPIPort),
+		TLSVerify:       dF.GetDockerAPITLSVerify(),
 	}
 }
 
@@ -339,18 +335,6 @@ func (dF DefaultConfig) getSecurityTestConfig(securityTestName string) *types.Se
 	}
 }
 
-// GetMaxContainersAllowed returns an interger the maximum number
-// interpreted as the maximum number of containers initialized
-// in parallel. It depends on the environment variable called
-// HUSKYCI_DOCKERAPI_MAX_CONTAINERS_BEFORE_CLEANING.
-func (dF DefaultConfig) GetMaxContainersAllowed() int {
-	maxContainersAllowed, err := dF.Caller.ConvertStrToInt(dF.Caller.GetEnvironmentVariable("HUSKYCI_DOCKERAPI_MAX_CONTAINERS_BEFORE_CLEANING"))
-	if err != nil {
-		return 50
-	}
-	return maxContainersAllowed
-}
-
 // GetDB returns a Requests implementation based on the
 // on the type configured on HUSKYCI_DATABASE_TYPE env var.
 // The default returns a MongoRequests that implements mongo
diff --git a/api/token/token.go b/api/token/token.go
index 7a96f54..c9d3a80 100644
--- a/api/token/token.go
+++ b/api/token/token.go
@@ -42,14 +42,8 @@ func (tH *THandler) GenerateAccessToken(repo types.TokenRequest) (string, error)
 		return "", err
 	}
 	hashFunction := tH.HashGen.GetHashName()
-	keyLength, err := tH.HashGen.GetKeyLength()
-	if err != nil {
-		return "", err
-	}
-	iterations, err := tH.HashGen.GetIterations()
-	if err != nil {
-		return "", err
-	}
+	keyLength := tH.HashGen.GetKeyLength()
+	iterations := tH.HashGen.GetIterations()
 	h, isOk := auth.GetValidHashFunction(hashFunction)
 	if !isOk {
 		return "", errors.New("Invalid hash function")
@@ -96,14 +90,8 @@ func (tH *THandler) ValidateRandomData(rdata, hashdata, salt string) error {
 	if !isOk {
 		return errors.New("Invalid hash function")
 	}
-	keyLength, err := tH.HashGen.GetKeyLength()
-	if err != nil {
-		return err
-	}
-	iterations, err := tH.HashGen.GetIterations()
-	if err != nil {
-		return err
-	}
+	keyLength := tH.HashGen.GetKeyLength()
+	iterations := tH.HashGen.GetIterations()
 	hashval := tH.HashGen.GenHashValue([]byte(rdata), bSalt, iterations, keyLength, h)
 	if hashval != hashdata {
 		return errors.New("Hash value from random data is different")
diff --git a/api/user/user.go b/api/user/user.go
index c256adc..03b184d 100644
--- a/api/user/user.go
+++ b/api/user/user.go
@@ -12,7 +12,6 @@ import (
 	"errors"
 	"hash"
 	"io"
-	"strconv"
 
 	"github.com/globocom/huskyCI/api/auth"
 	apiContext "github.com/globocom/huskyCI/api/context"
@@ -25,12 +24,6 @@ var (
 	DefaultAPIUser = os.Getenv("HUSKYCI_API_DEFAULT_USERNAME")
 	// DefaultAPIPassword is the default API password from huskyCI
 	DefaultAPIPassword = os.Getenv("HUSKYCI_API_DEFAULT_PASSWORD")
-	// DefaultIterations is the default number of iterations used for auth
-	DefaultIterations = os.Getenv("HUSKYCI_API_DEFAULT_ITERATIONS")
-	// DefaultKeyLength is the default key length used for auth
-	DefaultKeyLength = os.Getenv("HUSKYCI_API_DEFAULT_KEY_LENGTH")
-	// DefaultHashFunction is the default hash function name of iterations used for auth
-	DefaultHashFunction = os.Getenv("HUSKYCI_API_DEFAULT_HASH_FUNCTION")
 )
 
 // Create generates a new user
@@ -41,7 +34,13 @@ func Create() types.User {
 
 // InsertDefaultUser insert default user into MongoDB
 func InsertDefaultUser() error {
-	hashFunction, isValid := auth.GetValidHashFunction(DefaultHashFunction)
+
+	var pbkdf2Caller auth.Pbkdf2Caller
+	defaultHashFunction := pbkdf2Caller.GetHashName()
+	keyLength := pbkdf2Caller.GetKeyLength()
+	iterations := pbkdf2Caller.GetIterations()
+
+	hashFunction, isValid := auth.GetValidHashFunction(defaultHashFunction)
 	if !isValid {
 		return errors.New("Invalid hash function")
 	}
@@ -50,17 +49,9 @@ func InsertDefaultUser() error {
 	if err != nil {
 		return err
 	}
-	keyLength, err := strconv.Atoi(DefaultKeyLength)
-	if err != nil {
-		return err
-	}
-	iterations, err := strconv.Atoi(DefaultIterations)
-	if err != nil {
-		return err
-	}
 	newUser := types.User{}
 	newUser.Username = DefaultAPIUser
-	newUser.HashFunction = DefaultHashFunction
+	newUser.HashFunction = defaultHashFunction
 	newUser.Iterations = iterations
 	newUser.KeyLen = keyLength
 	newUser.Salt = base64.StdEncoding.EncodeToString(salt)
diff --git a/api/util/api/api.go b/api/util/api/api.go
index 40d52c3..436fe10 100644
--- a/api/util/api/api.go
+++ b/api/util/api/api.go
@@ -16,7 +16,6 @@ import (
 const logActionCheckReqs = "CheckHuskyRequirements"
 const logInfoAPIUtil = "API-UTIL"
 
-
 // CheckHuskyRequirements checks for all requirements needed before starting huskyCI.
 func (hU HuskyUtils) CheckHuskyRequirements(configAPI *apiContext.APIConfig) error {
 
@@ -53,49 +52,19 @@ func (hU HuskyUtils) CheckHuskyRequirements(configAPI *apiContext.APIConfig) err
 	return nil
 }
 
+// checkEnvVar verifies if all required environment variables are set
 func (cH *CheckUtils) checkEnvVars() error {
 
 	envVars := []string{
-		// Logging
-		// "HUSKYCI_LOGGING_GRAYLOG_ADDR", (optional)
-		// "HUSKYCI_LOGGING_GRAYLOG_PROTO", (optional)
-		// "HUSKYCI_LOGGING_GRAYLOG_APP_NAME", (optional)
-		// "HUSKYCI_LOGGING_GRAYLOG_TAG", (optional)
-		// "HUSKYCI_LOGGING_GRAYLOG_DEV", (optional)
-
-		// Database:
 		"HUSKYCI_DATABASE_DB_ADDR",
 		"HUSKYCI_DATABASE_DB_NAME",
 		"HUSKYCI_DATABASE_DB_USERNAME",
 		"HUSKYCI_DATABASE_DB_PASSWORD",
-		// "HUSKYCI_DATABASE_MONGO_PORT", (optional)
-		// "HUSKYCI_DATABASE_MONGO_TIMEOUT", (optional)
-		// "HUSKYCI_DATABASE_MONGO_POOL_LIMIT", (optional)
-
-		// Docker API:
-		"HUSKYCI_DOCKERAPI_ADDR",
-		"HUSKYCI_DOCKERAPI_CERT_PATH",
-		"HUSKYCI_DOCKERAPI_CERT_FILE",
-		"HUSKYCI_DOCKERAPI_CERT_KEY",
 		"HUSKYCI_API_DEFAULT_USERNAME",
 		"HUSKYCI_API_DEFAULT_PASSWORD",
 		"HUSKYCI_API_ALLOW_ORIGIN_CORS",
-		// "HUSKYCI_API_DEFAULT_ITERATIONS", (optional)
-		// "HUSKYCI_API_DEFAULT_KEY_LENGTH", (optional)
-		// "HUSKYCI_API_DEFAULT_HASH_FUNCTION", (optional)
-		// "HUSKYCI_DOCKERAPI_CERT_FILE_VALUE", (optional)
-		// "HUSKYCI_DOCKERAPI_CERT_KEY_VALUE", (optional)
-		// "HUSKYCI_DOCKERAPI_API_TLS_CERT_VALUE", (optional)
-		// "HUSKYCI_DOCKERAPI_API_TLS_KEY_VALUE", (optional)
-		// "HUSKYCI_DOCKERAPI_CERT_CA_VALUE", (optional)
-		// "HUSKYCI_DOCKERAPI_PORT", (optional)
-		// "HUSKYCI_DOCKERAPI_TLS_VERIFY", (optional)
-		// "HUSKYCI_DOCKERAPI_MAX_CONTAINERS_BEFORE_CLEANING", (optional)
-
-		// huskyCI API:
-		// "HUSKYCI_API_PORT", (optional)
-		// "HUSKYCI_API_ENABLE_HTTPS", (optional)
-		// "HUSKYCI_API_GIT_PRIVATE_SSH_KEY", (optional)
+		"HUSKYCI_DOCKERAPI_ADDR",
+		"HUSKYCI_DOCKERAPI_CERT_PATH",
 	}
 
 	var envIsSet bool
diff --git a/deployments/docker-compose.yml b/deployments/docker-compose.yml
index a25c1d2..37c8e8d 100644
--- a/deployments/docker-compose.yml
+++ b/deployments/docker-compose.yml
@@ -20,26 +20,15 @@ services:
         environment:
             GOPATH: /go/
             # required envs
-            HUSKYCI_DATABASE_TYPE: mongodb
             HUSKYCI_DATABASE_DB_ADDR: mongodb
-            HUSKYCI_DATABASE_DB_PORT: "27017"
             HUSKYCI_DATABASE_DB_NAME: huskyCIDB
             HUSKYCI_DATABASE_DB_USERNAME: huskyCIUser
             HUSKYCI_DATABASE_DB_PASSWORD: huskyCIPassword
             HUSKYCI_API_DEFAULT_USERNAME: huskyCIUser
             HUSKYCI_API_DEFAULT_PASSWORD: huskyCIPassword
-            HUSKYCI_API_DEFAULT_ITERATIONS: 100000
-            HUSKYCI_API_DEFAULT_KEY_LENGTH: 512
             HUSKYCI_API_ALLOW_ORIGIN_CORS: "*"
-            HUSKYCI_API_DEFAULT_HASH_FUNCTION: SHA512
             HUSKYCI_DOCKERAPI_ADDR: dockerapi
-            HUSKYCI_DOCKERAPI_CERT_FILE: /go/src/github.com/globocom/huskyCI/cert.pem
-            HUSKYCI_DOCKERAPI_CERT_KEY: /go/src/github.com/globocom/huskyCI/key.pem
             HUSKYCI_DOCKERAPI_CERT_PATH: /go/src/github.com/globocom/huskyCI/
-            HUSKYCI_DOCKERAPI_TLS_VERIFY: 1
-            # optional envs
-            HUSKYCI_DOCKERAPI_PORT: 2376
-            HUSKYCI_LOGGING_GRAYLOG_APP_NAME: huskyCI   
         build:
             context: ../
             dockerfile: deployments/dockerfiles/api.Dockerfile
diff --git a/go.mod b/go.mod
index 7e8d1ef..5bd74ef 100644
--- a/go.mod
+++ b/go.mod
@@ -43,12 +43,12 @@ require (
 	github.com/stretchr/testify v1.4.0
 	github.com/uudashr/gocognit v1.0.0 // indirect
 	github.com/valyala/fasttemplate v1.0.1 // indirect
-	golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
+	golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550
 	golang.org/x/lint v0.0.0-20190930215403-16217165b5de // indirect
-	golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914
+	golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
 	golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
-	golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e // indirect
-	golang.org/x/tools v0.0.0-20191122080028-f774e2e2e5be // indirect
+	golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 // indirect
+	golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 // indirect
 	gopkg.in/Graylog2/go-gelf.v2 v2.0.0-20180326133423-4dbb9d721348 // indirect
 	gopkg.in/fsnotify/fsnotify.v1 v1.4.7 // indirect
 	gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce
diff --git a/go.sum b/go.sum
index ee1e291..1545b98 100644
--- a/go.sum
+++ b/go.sum
@@ -360,11 +360,14 @@ golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACk
 golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
 golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
 golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
 golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
 golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
 golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
+golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
 golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
 golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -388,6 +391,8 @@ golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582 h1:p9xBe/w/OzkeYVKm234g55gMd
 golang.org/x/net v0.0.0-20191014212845-da9a3fd4c582/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914 h1:MlY3mEfbnWGmUi4rtHOtNnnnN4UJRGSyLPx+DXA5Sq4=
 golang.org/x/net v0.0.0-20191119073136-fc4aabc6c914/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
+golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
 golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -421,6 +426,8 @@ golang.org/x/sys v0.0.0-20191018095205-727590c5006e h1:ZtoklVMHQy6BFRHkbG6JzK+S6
 golang.org/x/sys v0.0.0-20191018095205-727590c5006e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e h1:N7DeIrjYszNmSW409R3frPPwglRwMkXSBzwVbkOjLLA=
 golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191210023423-ac6580df4449 h1:gSbV7h1NRL2G1xTg/owz62CST1oJBmxy4QpMMregXVQ=
+golang.org/x/sys v0.0.0-20191210023423-ac6580df4449/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
 golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
 golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -457,7 +464,12 @@ golang.org/x/tools v0.0.0-20191018000036-341939e08647 h1:kfteFQIbFl9R5RwgjPgqDtp
 golang.org/x/tools v0.0.0-20191018000036-341939e08647/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
 golang.org/x/tools v0.0.0-20191122080028-f774e2e2e5be h1:6d2MOtryvuMarrCTOqjhCZCVONST5uq4zNzBWKxzOls=
 golang.org/x/tools v0.0.0-20191122080028-f774e2e2e5be/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20191216052735-49a3e744a425 h1:VvQyQJN0tSuecqgcIxMWnnfG5kSmgy9KZR9sW3W5QeA=
+golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
+golang.org/x/tools v0.0.0-20191216173652-a0e659d51361 h1:RIIXAeV6GvDBuADKumTODatUqANFZ+5BPMnzsy4hulY=
+golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
 golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
 google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
 google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=


Test patch:
diff --git a/api/auth/authmongo_test.go b/api/auth/authmongo_test.go
index f4acd59..3b75ca4 100644
--- a/api/auth/authmongo_test.go
+++ b/api/auth/authmongo_test.go
@@ -43,12 +43,12 @@ func (fG *FakeGen) GetHashName() string {
 	return ""
 }
 
-func (fG *FakeGen) GetIterations() (int, error) {
-	return 0, nil
+func (fG *FakeGen) GetIterations() int {
+	return 0
 }
 
-func (fG *FakeGen) GetKeyLength() (int, error) {
-	return 0, nil
+func (fG *FakeGen) GetKeyLength() int {
+	return 0
 }
 
 var _ = Describe("Authmongo", func() {
diff --git a/api/context/context_test.go b/api/context/context_test.go
index fe342d1..6384093 100644
--- a/api/context/context_test.go
+++ b/api/context/context_test.go
@@ -265,32 +265,6 @@ var _ = Describe("Context", func() {
 			})
 		})
 	})
-	Describe("GetMaxContainersAllowed", func() {
-		Context("When ConvertStrToInt returns an error", func() {
-			It("Should return a maximum number of containers equals to 50", func() {
-				fakeCaller := FakeCaller{
-					expectedIntegerValue:         0,
-					expectedConvertStrToIntError: errors.New("Error during the convertion from string to integer"),
-				}
-				config := DefaultConfig{
-					Caller: &fakeCaller,
-				}
-				Expect(config.GetMaxContainersAllowed()).To(Equal(50))
-			})
-		})
-		Context("When ConvertStrToInt returns a value", func() {
-			It("Should return a maximum number of containers as expected", func() {
-				fakeCaller := FakeCaller{
-					expectedIntegerValue:         25000,
-					expectedConvertStrToIntError: nil,
-				}
-				config := DefaultConfig{
-					Caller: &fakeCaller,
-				}
-				Expect(config.GetMaxContainersAllowed()).To(Equal(fakeCaller.expectedIntegerValue))
-			})
-		})
-	})
 	Describe("GetAPIConfig", func() {
 		Context("When SetConfigFile returns an error", func() {
 			It("Should return the expected error", func() {
@@ -347,14 +321,11 @@ var _ = Describe("Context", func() {
 						ConnMaxLifetime: time.Duration(fakeCaller.expectedIntegerValue) * time.Hour,
 					},
 					DockerHostsConfig: &DockerHostsConfig{
-						Address:              "1",
-						DockerAPIPort:        fakeCaller.expectedIntegerValue,
-						Certificate:          fakeCaller.expectedEnvVar,
-						PathCertificate:      fakeCaller.expectedEnvVar,
-						Key:                  fakeCaller.expectedEnvVar,
-						Host:                 "1:1234",
-						TLSVerify:            1,
-						MaxContainersAllowed: fakeCaller.expectedIntegerValue,
+						Address:         "1",
+						DockerAPIPort:   fakeCaller.expectedIntegerValue,
+						PathCertificate: fakeCaller.expectedEnvVar,
+						Host:            "1:1234",
+						TLSVerify:       1,
 					},
 					EnrySecurityTest: &types.SecurityTest{
 						Name:             fakeCaller.expectedStringFromConfig,
diff --git a/api/token/token_test.go b/api/token/token_test.go
index 405ae22..95ba54e 100644
--- a/api/token/token_test.go
+++ b/api/token/token_test.go
@@ -35,16 +35,14 @@ type FakeExternal struct {
 }
 
 type FakeHashGen struct {
-	expectedSalt               string
-	expectedGenerateSaltError  error
-	expectedDecodedSalt        []byte
-	expectedDecodeSaltError    error
-	expectedHashName           string
-	expectedKeyLength          int
-	expectedGetKeyError        error
-	expectedIterations         int
-	expectedGetIterationsError error
-	expectedHashValue          string
+	expectedSalt              string
+	expectedGenerateSaltError error
+	expectedDecodedSalt       []byte
+	expectedDecodeSaltError   error
+	expectedHashName          string
+	expectedKeyLength         int
+	expectedIterations        int
+	expectedHashValue         string
 }
 
 func (fE *FakeExternal) ValidateURL(url string) (string, error) {
@@ -100,12 +98,12 @@ func (fH *FakeHashGen) GetHashName() string {
 	return fH.expectedHashName
 }
 
-func (fH *FakeHashGen) GetKeyLength() (int, error) {
-	return fH.expectedKeyLength, fH.expectedGetKeyError
+func (fH *FakeHashGen) GetKeyLength() int {
+	return fH.expectedKeyLength
 }
 
-func (fH *FakeHashGen) GetIterations() (int, error) {
-	return fH.expectedIterations, fH.expectedGetIterationsError
+func (fH *FakeHashGen) GetIterations() int {
+	return fH.expectedIterations
 }
 
 func (fH *FakeHashGen) GenHashValue(value, salt []byte, iter, keyLen int, h hash.Hash) string {
@@ -215,8 +213,8 @@ var _ = Describe("Token", func() {
 			Expect(err).To(Equal(fakeHash.expectedDecodeSaltError))
 		})
 	})
-	Context("When GetKeyLength returns an error", func() {
-		It("Should return the same error and an empty string", func() {
+	Context("When GetValidHashFunction returns a false boolean", func() {
+		It("Should return the expected error", func() {
 			fakeExt := FakeExternal{
 				expectedURL:           "MyValidURL",
 				expectedValidateError: nil,
@@ -229,68 +227,8 @@ var _ = Describe("Token", func() {
 				expectedDecodedSalt:       make([]byte, 0),
 				expectedDecodeSaltError:   nil,
 				expectedHashName:          "",
-				expectedKeyLength:         0,
-				expectedGetKeyError:       errors.New("Error during key length conversion"),
-			}
-			tokenGen := THandler{
-				External: &fakeExt,
-				HashGen:  &fakeHash,
-			}
-			accessToken, err := tokenGen.GenerateAccessToken(types.TokenRequest{
-				RepositoryURL: "myRepo.com",
-			})
-			Expect(accessToken).To(Equal(""))
-			Expect(err).To(Equal(fakeHash.expectedGetKeyError))
-		})
-	})
-	Context("When GetIterations returns an error", func() {
-		It("Should return the same error and an empty string", func() {
-			fakeExt := FakeExternal{
-				expectedURL:           "MyValidURL",
-				expectedValidateError: nil,
-				expectedToken:         "MyBrandNewToken",
-				expectedGenerateError: nil,
-			}
-			fakeHash := FakeHashGen{
-				expectedSalt:               "MySalt",
-				expectedGenerateSaltError:  nil,
-				expectedDecodedSalt:        make([]byte, 0),
-				expectedDecodeSaltError:    nil,
-				expectedHashName:           "",
-				expectedKeyLength:          32,
-				expectedGetKeyError:        nil,
-				expectedIterations:         0,
-				expectedGetIterationsError: errors.New("Failed to convert iterations"),
-			}
-			tokenGen := THandler{
-				External: &fakeExt,
-				HashGen:  &fakeHash,
-			}
-			accessToken, err := tokenGen.GenerateAccessToken(types.TokenRequest{
-				RepositoryURL: "myRepo.com",
-			})
-			Expect(accessToken).To(Equal(""))
-			Expect(err).To(Equal(fakeHash.expectedGetIterationsError))
-		})
-	})
-	Context("When GetValidHashFunction returns a false boolean", func() {
-		It("Should return the expected error", func() {
-			fakeExt := FakeExternal{
-				expectedURL:           "MyValidURL",
-				expectedValidateError: nil,
-				expectedToken:         "MyBrandNewToken",
-				expectedGenerateError: nil,
-			}
-			fakeHash := FakeHashGen{
-				expectedSalt:               "MySalt",
-				expectedGenerateSaltError:  nil,
-				expectedDecodedSalt:        make([]byte, 0),
-				expectedDecodeSaltError:    nil,
-				expectedHashName:           "",
-				expectedKeyLength:          32,
-				expectedGetKeyError:        nil,
-				expectedIterations:         1024,
-				expectedGetIterationsError: nil,
+				expectedKeyLength:         32,
+				expectedIterations:        1024,
 			}
 			tokenGen := THandler{
 				External: &fakeExt,
@@ -315,16 +253,14 @@ var _ = Describe("Token", func() {
 				expectedStoreAccessError: errors.New("Failed to store token"),
 			}
 			fakeHash := FakeHashGen{
-				expectedSalt:               "MySalt",
-				expectedGenerateSaltError:  nil,
-				expectedDecodedSalt:        make([]byte, 0),
-				expectedDecodeSaltError:    nil,
-				expectedHashName:           "Sha512",
-				expectedKeyLength:          32,
-				expectedGetKeyError:        nil,
-				expectedIterations:         1024,
-				expectedGetIterationsError: nil,
-				expectedHashValue:          "MyTokenHashValue",
+				expectedSalt:              "MySalt",
+				expectedGenerateSaltError: nil,
+				expectedDecodedSalt:       make([]byte, 0),
+				expectedDecodeSaltError:   nil,
+				expectedHashName:          "Sha512",
+				expectedKeyLength:         32,
+				expectedIterations:        1024,
+				expectedHashValue:         "MyTokenHashValue",
 			}
 			tokenGen := THandler{
 				External: &fakeExt,
@@ -349,16 +285,14 @@ var _ = Describe("Token", func() {
 				expectedStoreAccessError: nil,
 			}
 			fakeHash := FakeHashGen{
-				expectedSalt:               "MySalt",
-				expectedGenerateSaltError:  nil,
-				expectedDecodedSalt:        make([]byte, 0),
-				expectedDecodeSaltError:    nil,
-				expectedHashName:           "Sha512",
-				expectedKeyLength:          32,
-				expectedGetKeyError:        nil,
-				expectedIterations:         1024,
-				expectedGetIterationsError: nil,
-				expectedHashValue:          "MyTokenHashValue",
+				expectedSalt:              "MySalt",
+				expectedGenerateSaltError: nil,
+				expectedDecodedSalt:       make([]byte, 0),
+				expectedDecodeSaltError:   nil,
+				expectedHashName:          "Sha512",
+				expectedKeyLength:         32,
+				expectedIterations:        1024,
+				expectedHashValue:         "MyTokenHashValue",
 			}
 			tokenGen := THandler{
 				External: &fakeExt,
@@ -444,49 +378,15 @@ var _ = Describe("Token", func() {
 				Expect(tokenVal.ValidateRandomData("ReceivedRandom", "StoredRandom", "StoredSalt")).To(Equal(errors.New("Invalid hash function")))
 			})
 		})
-		Context("When GetKeyLength returns an error", func() {
-			It("Should return the same error", func() {
+		Context("When calculated hash differs from the stored hash", func() {
+			It("Should return the expected error", func() {
 				hashGen := FakeHashGen{
 					expectedDecodedSalt:     []byte("StoredSalt"),
 					expectedDecodeSaltError: nil,
 					expectedHashName:        "Sha512",
-					expectedKeyLength:       0,
-					expectedGetKeyError:     errors.New("Invalid key format"),
-				}
-				tokenVal := THandler{
-					HashGen: &hashGen,
-				}
-				Expect(tokenVal.ValidateRandomData("ReceivedRandom", "StoredRandom", "StoredSalt")).To(Equal(hashGen.expectedGetKeyError))
-			})
-		})
-		Context("When GetIterations returns an error", func() {
-			It("Should return the same error", func() {
-				hashGen := FakeHashGen{
-					expectedDecodedSalt:        []byte("StoredSalt"),
-					expectedDecodeSaltError:    nil,
-					expectedHashName:           "Sha512",
-					expectedKeyLength:          128,
-					expectedGetKeyError:        nil,
-					expectedIterations:         0,
-					expectedGetIterationsError: errors.New("Invalid iterations value format"),
-				}
-				tokenVal := THandler{
-					HashGen: &hashGen,
-				}
-				Expect(tokenVal.ValidateRandomData("ReceivedRandom", "StoredRandom", "StoredSalt")).To(Equal(hashGen.expectedGetIterationsError))
-			})
-		})
-		Context("When calculated hash differs from the stored hash", func() {
-			It("Should return the expected error", func() {
-				hashGen := FakeHashGen{
-					expectedDecodedSalt:        []byte("StoredSalt"),
-					expectedDecodeSaltError:    nil,
-					expectedHashName:           "Sha512",
-					expectedKeyLength:          128,
-					expectedGetKeyError:        nil,
-					expectedIterations:         1024,
-					expectedGetIterationsError: nil,
-					expectedHashValue:          "DifferentFromTheStored",
+					expectedKeyLength:       128,
+					expectedIterations:      1024,
+					expectedHashValue:       "DifferentFromTheStored",
 				}
 				tokenVal := THandler{
 					HashGen: &hashGen,
@@ -497,14 +397,12 @@ var _ = Describe("Token", func() {
 		Context("When calculated hash is equal from the stored hash", func() {
 			It("Should return a nil error", func() {
 				hashGen := FakeHashGen{
-					expectedDecodedSalt:        []byte("StoredSalt"),
-					expectedDecodeSaltError:    nil,
-					expectedHashName:           "Sha512",
-					expectedKeyLength:          128,
-					expectedGetKeyError:        nil,
-					expectedIterations:         1024,
-					expectedGetIterationsError: nil,
-					expectedHashValue:          "StoredRandomHash",
+					expectedDecodedSalt:     []byte("StoredSalt"),
+					expectedDecodeSaltError: nil,
+					expectedHashName:        "Sha512",
+					expectedKeyLength:       128,
+					expectedIterations:      1024,
+					expectedHashValue:       "StoredRandomHash",
 				}
 				tokenVal := THandler{
 					HashGen: &hashGen,
@@ -596,13 +494,11 @@ var _ = Describe("Token", func() {
 		Context("When hash of random data is different from the stored hash", func() {
 			It("Should return the expected error from ValidateRandomData", func() {
 				fakeHash := FakeHashGen{
-					expectedDecodedSalt:        []byte("MySaltDecoded"),
-					expectedDecodeSaltError:    nil,
-					expectedHashName:           "Sha512",
-					expectedKeyLength:          256,
-					expectedGetKeyError:        nil,
-					expectedGetIterationsError: nil,
-					expectedHashValue:          "MyDifferentHash",
+					expectedDecodedSalt:     []byte("MySaltDecoded"),
+					expectedDecodeSaltError: nil,
+					expectedHashName:        "Sha512",
+					expectedKeyLength:       256,
+					expectedHashValue:       "MyDifferentHash",
 				}
 				fakeExt := FakeExternal{
 					expectedURL:             "MyValidURL",
@@ -627,13 +523,11 @@ var _ = Describe("Token", func() {
 		Context("When hash of random data if equal from the stored hash", func() {
 			It("Should return the expected error from ValidateRandomData", func() {
 				fakeHash := FakeHashGen{
-					expectedDecodedSalt:        []byte("MySaltDecoded"),
-					expectedDecodeSaltError:    nil,
-					expectedHashName:           "Sha512",
-					expectedKeyLength:          256,
-					expectedGetKeyError:        nil,
-					expectedGetIterationsError: nil,
-					expectedHashValue:          "MyValidHash",
+					expectedDecodedSalt:     []byte("MySaltDecoded"),
+					expectedDecodeSaltError: nil,
+					expectedHashName:        "Sha512",
+					expectedKeyLength:       256,
+					expectedHashValue:       "MyValidHash",
 				}
 				fakeExt := FakeExternal{
 					expectedURL:             "MyValidURL",