Skip to content

Djf cross compile #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 20, 2017
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
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ services:
- docker

scala:
- 2.11.8
- 2.11.12
- 2.12.4

jdk: oraclejdk8

Expand All @@ -19,6 +20,6 @@ before_install:
- bash scripts/start_vault

script:
- sbt scalastyle
- sbt test
- sbt it:test
- sbt ++$TRAVIS_SCALA_VERSION scalastyle
- sbt ++$TRAVIS_SCALA_VERSION test
- sbt ++$TRAVIS_SCALA_VERSION it:test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.scalacheck.{Gen, Prop}
import org.specs2.ScalaCheck
import org.specs2.matcher.MatchResult

//noinspection ScalaStyle
class UserPassIT extends VaultSpec with ScalaCheck {
import VaultSpec._

Expand Down
16 changes: 8 additions & 8 deletions auth/src/main/scala/janstenpickle/vault/auth/UserPass.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package janstenpickle.vault.auth

import java.net.{HttpURLConnection => status}

import io.circe.generic.auto._
import janstenpickle.scala.syntax.AsyncResultSyntax._
import janstenpickle.scala.syntax.SyntaxRequest._
import janstenpickle.scala.syntax.ResponseSyntax._
import janstenpickle.scala.syntax.SyntaxRequest._
import janstenpickle.vault.core.WSClient
import uscala.concurrent.result.AsyncResult

Expand All @@ -17,13 +19,11 @@ case class UserPass(wsClient: WSClient) {
ttl: Int,
client: String = "userpass"
)(implicit ec: ExecutionContext): AsyncResult[String, UserPassResponse] =
wsClient.path(s"auth/$client/login/$username").
post(Map("password" -> password, "ttl" -> s"${ttl}s")).
toAsyncResult.
// scalastyle:off magic.number
acceptStatusCodes(200).
// scalastyle:on magic.number
extractFromJson[UserPassResponse](_.downField("auth"))
wsClient.path(s"auth/$client/login/$username")
.post(Map("password" -> password, "ttl" -> s"${ttl}s"))
.toAsyncResult
.acceptStatusCodes(status.HTTP_OK)
.extractFromJson[UserPassResponse](_.downField("auth"))
}

case class UserPassResponse(
Expand Down
17 changes: 11 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import sbt.Keys._

import org.scalastyle.sbt._

name := "vault"

lazy val uscalaVersion = "0.5.1"
lazy val specs2Version = "3.8.8"
lazy val circeVersion = "0.7.0"
lazy val dispatchVersion = "0.11.3"
lazy val specs2Version = "3.9.5"
lazy val circeVersion = "0.7.1"
lazy val dispatchVersion = "0.13.2"
lazy val startVaultTask = TaskKey[Unit](
"startVaultTask",
"Start dev vault server for integration test"
Expand Down Expand Up @@ -37,8 +39,10 @@ val pomInfo = (
)

lazy val commonSettings = Seq(
resolvers += Resolver.bintrayRepo("albertpastrana", "maven"),
version := "0.4.2-SNAPSHOT",
scalaVersion := "2.11.11",
scalaVersion := "2.11.12",
crossScalaVersions := Seq( "2.11.12", "2.12.4"),
organization := "janstenpickle.vault",
pomExtra := pomInfo,
autoAPIMappings := true,
Expand Down Expand Up @@ -90,8 +94,7 @@ lazy val commonSettings = Seq(
unmanagedSourceDirectories in IntegrationTest += baseDirectory.value /
"test" / "scala",
// check style settings
checkStyleBeforeCompile :=
org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value,
checkStyleBeforeCompile := (scalastyle in Compile).toTask("").value,
(compile in Compile) := (
(compile in Compile) dependsOn
checkStyleBeforeCompile
Expand All @@ -102,11 +105,13 @@ lazy val core = (project in file("core")).
settings(name := "vault-core").
settings(commonSettings: _*).
configs(IntegrationTest)

lazy val manage = (project in file("manage")).
settings(name := "vault-manage").
settings(commonSettings: _*).
configs(IntegrationTest).
dependsOn(core % "compile->compile;it->it,it->test")

lazy val auth = (project in file("auth")).
settings(name := "vault-auth").
settings(commonSettings: _*).
Expand Down
4 changes: 2 additions & 2 deletions core/src/it/scala/janstenpickle/vault/core/SecretsIT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ trait SecretsTests extends VaultSpec with ScalaCheck {
})
}

def failGet = good.get("john").attemptRun(_.getMessage()) must beFail.
like { case err =>
def failGet = good.get("john").attemptRun(_.getMessage()) must beFail
.like { case err =>
err must contain("Received failure response from server: 404")
}

Expand Down
3 changes: 0 additions & 3 deletions core/src/it/scala/janstenpickle/vault/core/VaultSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ package janstenpickle.vault.core

import java.net.URL

import janstenpickle.scala.syntax.SyntaxRequest._
import janstenpickle.scala.syntax.ResponseSyntax._
import janstenpickle.scala.syntax.VaultConfigSyntax._
import org.scalacheck.Gen
import org.specs2.Specification
import org.specs2.specification.core.Fragments
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/scala/janstenpickle/scala/syntax/syntax.scala
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package janstenpickle.scala.syntax

import com.ning.http.client.Response
import dispatch.{Http, Req}
import io.circe._
import io.circe.parser._
import io.circe.syntax._
import janstenpickle.vault.core.VaultConfig
import org.asynchttpclient.Response
import uscala.concurrent.result.AsyncResult
import uscala.result.Result

Expand Down Expand Up @@ -34,7 +34,9 @@ object AsyncResultSyntax {

implicit class ReqToAsyncResult(req: Req)
(implicit ec: ExecutionContext) {
def toAsyncResult: AsyncResult[String, Response] = Http(req).toAsyncResult
def toAsyncResult: AsyncResult[String, Response] =
Http.default(req)
.toAsyncResult
}

implicit def toAsyncResult[T](future: scala.concurrent.Future[T])
Expand Down Expand Up @@ -109,7 +111,7 @@ object SyntaxRequest {
implicit class ExecuteRequest(req: AsyncResult[String, Req])
(implicit ec: ExecutionContext) {
def execute: AsyncResult[String, Response] =
req.flatMapF(Http(_))
req.flatMapF(Http.default.apply)
}

implicit class HttpOps(req: Req) {
Expand Down
30 changes: 15 additions & 15 deletions core/src/main/scala/janstenpickle/vault/core/Secrets.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package janstenpickle.vault.core

import com.ning.http.client.Response
import janstenpickle.scala.syntax.SyntaxRequest._
import java.net.{HttpURLConnection => status}

import janstenpickle.scala.syntax.ResponseSyntax._
import janstenpickle.scala.syntax.SyntaxRequest._
import janstenpickle.scala.syntax.VaultConfigSyntax._
import org.asynchttpclient.Response
import uscala.concurrent.result.AsyncResult
import uscala.result.Result

import scala.concurrent.ExecutionContext

// scalastyle:off magic.number
case class Secrets(config: VaultConfig, backend: String) {
def get(key: String, subKey: String = "value")
(implicit ec: ExecutionContext): AsyncResult[String, String] =
Expand All @@ -19,10 +20,10 @@ case class Secrets(config: VaultConfig, backend: String) {

def getAll(key: String)
(implicit ec: ExecutionContext): AsyncResult[String, Map[String, String]] =
config.authenticatedRequest(path(key))(_.get).
execute.
acceptStatusCodes(200).
extractFromJson[Map[String, String]](_.downField("data"))
config.authenticatedRequest(path(key))(_.get)
.execute
.acceptStatusCodes(status.HTTP_OK)
.extractFromJson[Map[String, String]](_.downField("data"))

def set(key: String, value: String)
(implicit ec: ExecutionContext): AsyncResult[String, Response] =
Expand All @@ -34,17 +35,16 @@ case class Secrets(config: VaultConfig, backend: String) {

def set(key: String, values: Map[String, String])
(implicit ec: ExecutionContext): AsyncResult[String, Response] =
config.authenticatedRequest(path(key))(_.post(values)).
execute.
acceptStatusCodes(204)
config.authenticatedRequest(path(key))(_.post(values))
.execute
.acceptStatusCodes(status.HTTP_NO_CONTENT)

def list(implicit ec: ExecutionContext): AsyncResult[String, List[String]] =
config.authenticatedRequest(backend)(
_.addQueryParameter("list", true.toString).get).
execute.
acceptStatusCodes(200).
extractFromJson[List[String]](_.downField("data").downField("keys"))
_.addQueryParameter("list", true.toString).get)
.execute
.acceptStatusCodes(status.HTTP_OK)
.extractFromJson[List[String]](_.downField("data").downField("keys"))

def path(key: String): String = s"$backend/$key"
}
// scalastyle:on magic.number
45 changes: 21 additions & 24 deletions core/src/main/scala/janstenpickle/vault/core/VaultConfig.scala
Original file line number Diff line number Diff line change
@@ -1,65 +1,62 @@
package janstenpickle.vault.core

import java.net.URL
import java.net.{URL, HttpURLConnection => status}
import java.nio.charset.Charset

import dispatch.{Req, url}
import io.circe.generic.auto._
import io.circe.syntax._
import janstenpickle.scala.syntax.AsyncResultSyntax._
import janstenpickle.scala.syntax.SyntaxRequest._
import janstenpickle.scala.syntax.ResponseSyntax._
import janstenpickle.scala.syntax.SyntaxRequest._
import uscala.concurrent.result.AsyncResult

import scala.concurrent.ExecutionContext

case class VaultConfig(wsClient: WSClient, token: AsyncResult[String, String])

@deprecated("Vault 0.6.5 deprecated AppId in favor of AppRole", "0.4.0")
case class AppId(app_id: String, user_id: String)

case class AppRole(role_id: String, secret_id: String)

object VaultConfig {

@deprecated("Vault 0.6.5 deprecated AppId in favor of AppRole", "0.4.0")
def apply(client: WSClient, appId: AppId)
(implicit ec: ExecutionContext): VaultConfig =
(implicit ec: ExecutionContext): VaultConfig =
VaultConfig(client,
client.path("auth/app-id/login").
post(appId.asJson).
toAsyncResult.
// scalastyle:off magic.number
acceptStatusCodes(200).
// scalastyle:on magic.number
extractFromJson[String](
client.path("auth/app-id/login")
.post(appId.asJson)
.toAsyncResult
.acceptStatusCodes(status.HTTP_OK)
.extractFromJson[String](
_.downField("auth").downField("client_token")
)
)

def apply(client: WSClient, appRole: AppRole)
(implicit ec: ExecutionContext): VaultConfig =
(implicit ec: ExecutionContext): VaultConfig =
VaultConfig(client,
client.path("auth/approle/login").
post(appRole.asJson).
toAsyncResult.
// scalastyle:off magic.number
acceptStatusCodes(200).
// scalastyle:on magic.number
extractFromJson[String](
client.path("auth/approle/login")
.post(appRole.asJson)
.toAsyncResult
.acceptStatusCodes(status.HTTP_OK)
.extractFromJson[String](
_.downField("auth").downField("client_token")
)
)

def apply(wsClient: WSClient, token: String)
(implicit ec: ExecutionContext): VaultConfig =
def apply(wsClient: WSClient, token: String): VaultConfig =
VaultConfig(wsClient, AsyncResult.ok[String, String](token))
}



case class WSClient(server: URL,
version: String = "v1") {
def path(p: String): Req =
url(s"${server.toString}/$version/$p").
setContentType("application/json", "UTF-8")
def path(p: String): Req =
url(s"${server.toString}/$version/$p")
.setContentType("application/json", Charset.forName("UTF-8"))
}


16 changes: 8 additions & 8 deletions manage/src/it/scala/janstenpickle/vault/manage/MountIT.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package janstenpickle.vault.manage

import com.ning.http.client.Response
import com.ning.http.client.providers.jdk.JDKResponse
import janstenpickle.vault.core.VaultSpec
import janstenpickle.vault.manage.Model.{Mount, MountConfig}
import org.asynchttpclient.Response
import org.asynchttpclient.netty.NettyResponse
import org.scalacheck.{Gen, Prop}
import org.specs2.ScalaCheck
import uscala.result.Result
Expand All @@ -19,7 +19,7 @@ class MountIT extends VaultSpec with ScalaCheck {
Cannot enable an invalid mount type $enableFail
"""

lazy val underTest = new Mounts(config)
lazy val underTest = Mounts(config)

def happy = Prop.forAllNoShrink(
mountGen,
Expand Down Expand Up @@ -75,9 +75,9 @@ object MountIT {
forceNoCache <- Gen.option(Gen.oneOf(true, false))
} yield Mount(mountType, description, Some(MountConfig(defaultTtl, maxTtl, forceNoCache)))

def processMountTypes(op: (Result[String, Response], String) => Result[String,
Response]) =
mountTypes.foldLeft[Result[String, Response]](Result.ok(new
JDKResponse(null, null, null)))(op)

def processMountTypes(op: (Result[String, Response], String) =>
Result[String, Response]) =
mountTypes.foldLeft[Result[String, Response]](
Result.ok(new NettyResponse(null, null, null))
)(op)
}
11 changes: 5 additions & 6 deletions manage/src/it/scala/janstenpickle/vault/manage/PolicyIT.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import janstenpickle.vault.core.VaultSpec
import janstenpickle.vault.manage.Model.Rule
import org.scalacheck.{Gen, Prop}
import org.specs2.ScalaCheck
import uscala.result.Result

class PolicyIT extends VaultSpec with ScalaCheck {
import PolicyIT._
Expand All @@ -20,8 +19,8 @@ class PolicyIT extends VaultSpec with ScalaCheck {

def happy = Prop.forAllNoShrink(
longerStrGen,
Gen.listOf(ruleGen(longerStrGen, policyGen, capabilitiesGen)).
suchThat(_.nonEmpty)) { (name, rules) =>
Gen.listOf(ruleGen(longerStrGen, policyGen, capabilitiesGen))
.suchThat(_.nonEmpty)) { (name, rules) =>
(underTest.set(name.toLowerCase, rules)
.attemptRun(_.getMessage()) must beOk) and
(underTest.inspect(name.toLowerCase)
Expand All @@ -40,9 +39,9 @@ object PolicyIT {
val policyGen = Gen.option(Gen.oneOf("read", "write", "sudo", "deny"))
val capabilitiesGen =
Gen.listOf(Gen.oneOf(
"create", "read", "update", "delete", "list", "sudo", "deny")).
suchThat(_.nonEmpty).
map(_.distinct)
"create", "read", "update", "delete", "list", "sudo", "deny"))
.suchThat(_.nonEmpty)
.map(_.distinct)

def ruleGen(
pathGen: Gen[String],
Expand Down
Loading