Skip to content

Commit

Permalink
Refactor and Test of ConfigSecurity (apache#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gschiavon authored and jlopezmalla committed Sep 6, 2017
1 parent f33d6a3 commit 4a0e0ba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ hose {
DEV = { config ->

doPackage(config)
// doUT(config)
doUT(config)
parallel(DOCKER1: {
doDocker(conf: config, dockerfile:"DockerfileDispatcher")
}, DEPLOY: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,16 @@ object ConfigSecurity extends Logging{

var vaultToken: Option[String] = None
val vaultHost: Option[String] = sys.env.get("VAULT_HOST")
val vaultUri: Option[String] = {
(sys.env.get("VAULT_PROTOCOL"), vaultHost, sys.env.get("VAULT_PORT")) match {
val vaultUri: Option[String] =
getVaultUri(sys.env.get("VAULT_PROTOCOL"), vaultHost, sys.env.get("VAULT_PORT"))

def getVaultUri(vaultProtocol: Option[String],
vaultHost: Option[String],
vaultPort: Option[String]): Option[String] = {
(vaultProtocol, vaultHost, vaultPort) match {
case (Some(vaultProtocol), Some(vaultHost), Some(vaultPort)) =>
val vaultUri = s"$vaultProtocol://$vaultHost:$vaultPort"
logDebug(s"vault uri: $vaultUri found, any Vault Connection will use it")
logDebug(s"Vault uri: $vaultUri found, any Vault Connection will use it")
Option(vaultUri)
case _ =>
logDebug("No Vault information found, any Vault Connection will fail")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,31 @@ class ConfigSecuritySuite extends SparkFunSuite with Matchers {
"datastore" -> Map("DATASTORE_ENABLE" -> "true"),
"kafka" -> Map("KAFKA_ENABLE" -> "true")))
}

/**
* getVaultUri
*/

val vaultProtocol = Option("https")
val vaultHost = Option("vault.labs.stratio.com")
val vaultPort = Option("8200")
val expectedResult = "https://vault.labs.stratio.com:8200"


test("getVaultUri with all the parameters given") {
val vaultUri = ConfigSecurity.getVaultUri(vaultProtocol, vaultHost, vaultPort)
assert(vaultUri === Option(expectedResult))
}

test("getVaultUri without one of the parameters needed") {
val vaultUri = ConfigSecurity.getVaultUri(None, vaultHost, vaultPort)
assert(vaultUri === None)
}

test("getVaultUri without none of the parameters needed") {
val vaultUri = ConfigSecurity.getVaultUri(None, None, None)
assert(vaultUri === None)
}
}


0 comments on commit 4a0e0ba

Please sign in to comment.