Skip to content
This repository has been archived by the owner on Sep 27, 2021. It is now read-only.

Commit

Permalink
Bumped sbt-nexus, nexus-commons and nexus-sourcing deps. (#229)
Browse files Browse the repository at this point in the history
* Bumped sbt-nexus, nexus-commons and nexus-sourcing deps.

* Fixes formatting due to scalafmt update to 2.0.0
  • Loading branch information
umbreak committed Aug 8, 2019
1 parent 71232da commit 9cf451a
Show file tree
Hide file tree
Showing 45 changed files with 486 additions and 334 deletions.
1 change: 1 addition & 0 deletions .scalafmt.conf
@@ -1,5 +1,6 @@
style = defaultWithAlign
maxColumn = 120
version = 2.0.0
align.tokens = [
{ code = "=>", owner = "Case" }
{ code = "⇒", owner = "Case" }
Expand Down
14 changes: 7 additions & 7 deletions build.sbt
Expand Up @@ -26,8 +26,8 @@ scalafmt: {

// Dependency versions
val alpakkaVersion = "1.1.0"
val commonsVersion = "0.17.2"
val sourcingVersion = "0.16.3"
val commonsVersion = "0.17.3"
val sourcingVersion = "0.16.4"
val akkaVersion = "2.5.23"
val akkaCorsVersion = "0.4.1"
val akkaHttpVersion = "10.1.9"
Expand All @@ -37,9 +37,9 @@ val catsVersion = "1.6.1"
val circeVersion = "0.11.1"
val journalVersion = "3.0.19"
val logbackVersion = "1.2.3"
val mockitoVersion = "1.5.12"
val mockitoVersion = "1.5.13"
val monixVersion = "3.0.0-RC3"
val nimbusJoseJwtVersion = "7.6"
val nimbusJoseJwtVersion = "7.7"
val pureconfigVersion = "0.11.1"
val scalaTestVersion = "3.0.8"
val kryoVersion = "0.5.2"
Expand Down Expand Up @@ -113,7 +113,7 @@ lazy val iam = project
akkaPersistenceMem % Test,
commonsTest % Test,
mockitoScala % Test,
scalaTest % Test,
scalaTest % Test
),
resolvers += "dnvriend" at "http://dl.bintray.com/dnvriend/maven",
mappings in Universal := {
Expand Down Expand Up @@ -146,7 +146,7 @@ lazy val client = project
akkaHttpTestKit % Test,
commonsTest % Test,
mockitoScala % Test,
scalaTest % Test,
scalaTest % Test
)
)

Expand All @@ -159,7 +159,7 @@ lazy val testSettings = Seq(
dependencyClasspath in Jmh := (dependencyClasspath in Test).value,
// rewire tasks, so that 'jmh:run' automatically invokes 'jmh:compile' (otherwise a clean 'jmh:run' would fail)
compile in Jmh := (compile in Jmh).dependsOn(compile in Test).value,
run in Jmh := (run in Jmh).dependsOn(Keys.compile in Jmh).evaluated,
run in Jmh := (run in Jmh).dependsOn(Keys.compile in Jmh).evaluated
)

lazy val buildInfoSettings = Seq(
Expand Down
Expand Up @@ -40,7 +40,8 @@ object EventSource {
* @tparam A the type of the data parameter on the SSE, attempted to convert using Json
*/
def apply[A: Decoder](
config: IamClientConfig)(implicit as: ActorSystem, mt: Materializer, ec: ExecutionContext): EventSource[A] =
config: IamClientConfig
)(implicit as: ActorSystem, mt: Materializer, ec: ExecutionContext): EventSource[A] =
new EventSource[A] {
private val logger = Logger[this.type]
private val http = Http()
Expand All @@ -56,7 +57,8 @@ object EventSource {
}

override def apply(iri: AbsoluteIri, offset: Option[String])(
implicit cred: Option[AuthToken]): Source[A, NotUsed] =
implicit cred: Option[AuthToken]
): Source[A, NotUsed] =
SSESource(iri.toAkkaUri, send, offset, config.sseRetryDelay).flatMapConcat { sse =>
decode[A](sse.data) match {
case Right(ev) => Source.single(ev)
Expand Down
Expand Up @@ -50,7 +50,8 @@ class IamClient[F[_]] private[client] (
* @param credentials an optionally available token
*/
def acls(path: Path, ancestors: Boolean = false, self: Boolean = false)(
implicit credentials: Option[AuthToken]): F[AccessControlLists] = {
implicit credentials: Option[AuthToken]
): F[AccessControlLists] = {
val endpoint = config.aclsIri + path
val req = requestFrom(endpoint, Query("ancestors" -> ancestors.toString, "self" -> self.toString))
aclsClient(req)
Expand Down Expand Up @@ -84,7 +85,8 @@ class IamClient[F[_]] private[client] (
* @param credentials an optionally available token
*/
def putAcls(path: Path, acl: AccessControlList, rev: Option[Long] = None)(
implicit credentials: Option[AuthToken]): F[Unit] = {
implicit credentials: Option[AuthToken]
): F[Unit] = {
implicit val _ = config
val endpoint = config.aclsIri + path
val entity = HttpEntity(ContentTypes.`application/json`, acl.asJson.noSpaces)
Expand Down Expand Up @@ -127,7 +129,8 @@ class IamClient[F[_]] private[client] (
* @param offset the optional offset from where to start streaming the events
*/
def permissionEvents(f: PermissionsEvent => F[Unit], offset: Option[String] = None)(
implicit cred: Option[AuthToken]): Unit = {
implicit cred: Option[AuthToken]
): Unit = {
val pf: PartialFunction[Event, F[Unit]] = { case ev: PermissionsEvent => f(ev) }
events(config.permissionsIri + "events", pf, offset)
}
Expand Down Expand Up @@ -155,7 +158,8 @@ class IamClient[F[_]] private[client] (
}

private def events(iri: AbsoluteIri, f: PartialFunction[Event, F[Unit]], offset: Option[String])(
implicit cred: Option[AuthToken]): Unit =
implicit cred: Option[AuthToken]
): Unit =
source(iri, offset)
.mapAsync(1) { event =>
f.lift(event) match {
Expand Down Expand Up @@ -209,18 +213,19 @@ object IamClient {
val value = L.liftIO(IO.fromFuture(IO(um(resp.entity))))
value.recoverWith {
case pf: ParsingFailure =>
logger.error(
s"Failed to parse a successful response of '${req.method.name()} ${req.getUri().toString}'.")
logger
.error(s"Failed to parse a successful response of '${req.method.name()} ${req.getUri().toString}'.")
F.raiseError[A](UnmarshallingError(pf.getMessage()))
case df: DecodingFailure =>
logger.error(
s"Failed to decode a successful response of '${req.method.name()} ${req.getUri().toString}'.")
logger
.error(s"Failed to decode a successful response of '${req.method.name()} ${req.getUri().toString}'.")
F.raiseError(UnmarshallingError(df.getMessage()))
}
case other =>
cl.toString(resp.entity).flatMap { entityAsString =>
logger.error(
s"Received '${other.value}' when accessing '${req.method.name()} ${req.uri.toString()}', response entity as string: '$entityAsString.'")
s"Received '${other.value}' when accessing '${req.method.name()} ${req.uri.toString()}', response entity as string: '$entityAsString.'"
)
F.raiseError[A](UnknownError(other, entityAsString))
}
}
Expand Down
Expand Up @@ -20,7 +20,8 @@ object IamClientError {

final case class UnmarshallingError[A: ClassTag](reason: String)
extends IamClientError(
s"Unable to parse or decode the response from IAM to a '${implicitly[ClassTag[A]]}' due to '$reason'.")
s"Unable to parse or decode the response from IAM to a '${implicitly[ClassTag[A]]}' due to '$reason'."
)

final case class UnknownError(status: StatusCode, entityAsString: String)
extends IamClientError("The request did not complete successfully.")
Expand Down
Expand Up @@ -12,9 +12,11 @@ import scala.concurrent.duration._
* @param internalIri base URL for all the HTTP calls, including prefix.
* @param sseRetryDelay delay for retrying after completion on SSE. 1 second by default.
*/
final case class IamClientConfig(publicIri: AbsoluteIri,
internalIri: AbsoluteIri,
sseRetryDelay: FiniteDuration = 1 second) {
final case class IamClientConfig(
publicIri: AbsoluteIri,
internalIri: AbsoluteIri,
sseRetryDelay: FiniteDuration = 1 second
) {
lazy val identitiesIri: AbsoluteIri = internalIri + "identities"
lazy val aclsIri: AbsoluteIri = internalIri + "acls"
lazy val permissionsIri: AbsoluteIri = internalIri + "permissions"
Expand Down
Expand Up @@ -91,19 +91,25 @@ object Identity {

implicit def identityEncoder(implicit config: IamClientConfig): Encoder[Identity] = {
case i @ User(subject, realm) =>
Json.obj("@id" -> i.id.asJson,
"@type" -> Json.fromString("User"),
nxv.realm.prefix -> Json.fromString(realm),
nxv.subject.prefix -> Json.fromString(subject))
Json.obj(
"@id" -> i.id.asJson,
"@type" -> Json.fromString("User"),
nxv.realm.prefix -> Json.fromString(realm),
nxv.subject.prefix -> Json.fromString(subject)
)
case i @ Group(group, realm) =>
Json.obj("@id" -> i.id.asJson,
"@type" -> Json.fromString("Group"),
nxv.realm.prefix -> Json.fromString(realm),
nxv.group.prefix -> Json.fromString(group))
Json.obj(
"@id" -> i.id.asJson,
"@type" -> Json.fromString("Group"),
nxv.realm.prefix -> Json.fromString(realm),
nxv.group.prefix -> Json.fromString(group)
)
case i @ Authenticated(realm) =>
Json.obj("@id" -> i.id.asJson,
"@type" -> Json.fromString("Authenticated"),
nxv.realm.prefix -> Json.fromString(realm))
Json.obj(
"@id" -> i.id.asJson,
"@type" -> Json.fromString("Authenticated"),
nxv.realm.prefix -> Json.fromString(realm)
)
case i @ Anonymous =>
Json.obj("@id" -> i.id.asJson, "@type" -> Json.fromString("Anonymous"))
}
Expand Down
Expand Up @@ -26,14 +26,16 @@ import io.circe.syntax._
* @param updatedBy the subject that performed the last update to the resource
* @param value the Access Control List
*/
final case class ResourceAccessControlList(id: AbsoluteIri,
rev: Long,
types: Set[AbsoluteIri],
createdAt: Instant,
createdBy: Subject,
updatedAt: Instant,
updatedBy: Subject,
value: AccessControlList)
final case class ResourceAccessControlList(
id: AbsoluteIri,
rev: Long,
types: Set[AbsoluteIri],
createdAt: Instant,
createdBy: Subject,
updatedAt: Instant,
updatedBy: Subject,
value: AccessControlList
)
object ResourceAccessControlList {

implicit def resourceAccessControlListEncoder(implicit config: IamClientConfig): Encoder[ResourceAccessControlList] =
Expand Down
Expand Up @@ -70,14 +70,16 @@ class IamClientSpec

"fetching ACLs and authorizing" should {
val acl = AccessControlList(Anonymous -> Set(Permission.unsafe("create"), Permission.unsafe("read")))
val aclWithMeta = ResourceAccessControlList(url"http://example.com/id".value,
7L,
Set.empty,
clock.instant(),
Anonymous,
clock.instant(),
Anonymous,
acl)
val aclWithMeta = ResourceAccessControlList(
url"http://example.com/id".value,
7L,
Set.empty,
clock.instant(),
Anonymous,
clock.instant(),
Anonymous,
acl
)

"succeed with token" in {
implicit val tokenOpt = Option(AuthToken("token"))
Expand All @@ -96,7 +98,8 @@ class IamClientSpec
val expected = AccessControlLists(/ -> aclWithMeta)

aclsClient(Get("http://internal.example.com/some/v1/acls/a/b?ancestors=true&self=true")) shouldReturn IO(
expected)
expected
)
client.acls("a" / "b", ancestors = true, self = true).ioValue shouldEqual expected
client.hasPermission("a" / "b", Permission.unsafe("read")).ioValue shouldEqual true
}
Expand Down Expand Up @@ -194,7 +197,8 @@ class IamClientSpec
val expected = Caller(user, Set(user, Anonymous))

callerClient(Get("http://internal.example.com/some/v1/identities").addCredentials(token)) shouldReturn IO.pure(
expected)
expected
)
client.identities.ioValue shouldEqual expected
}

Expand Down
Expand Up @@ -11,10 +11,12 @@ class CallerDecoderSpec extends WordSpecLike with Matchers with Resources with E

jsonContentOf("/identities/caller.json").as[Caller].right.value shouldEqual Caller(
User("nexus-test-user", "nexusdev"),
Set(Anonymous,
Authenticated("nexusdev"),
Group("nexus-test-group", "nexusdev"),
User("nexus-test-user", "nexusdev"))
Set(
Anonymous,
Authenticated("nexusdev"),
Group("nexus-test-group", "nexusdev"),
User("nexus-test-user", "nexusdev")
)
)

}
Expand Down
Expand Up @@ -32,7 +32,7 @@ class IdentitySpec
url"http://nexus.example.com/v1/realms/myrealm/authenticated".value -> authenticated,
url"https://random.com/v1/realms/myrealm/authenticated".value -> authenticated,
url"http://nexus.example.com/v1/anonymous".value -> Anonymous,
url"https://random.com/v1/anonymous".value -> Anonymous,
url"https://random.com/v1/anonymous".value -> Anonymous
)
forAll(cases) {
case (iri, identity) => Identity(iri).value shouldEqual identity
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
@@ -1,5 +1,5 @@
resolvers += Resolver.bintrayRepo("bbp", "nexus-releases")

addSbtPlugin("ch.epfl.bluebrain.nexus" % "sbt-nexus" % "0.11.0")
addSbtPlugin("ch.epfl.bluebrain.nexus" % "sbt-nexus" % "0.12.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.6")
addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.3.7")
5 changes: 3 additions & 2 deletions src/main/scala/ch/epfl/bluebrain/nexus/iam/Main.scala
Expand Up @@ -53,8 +53,9 @@ object Main {
}
}

def bootstrap(as: ActorSystem)(implicit cfg: AppConfig,
mt: ActorMaterializer): (Permissions[Task], Acls[Task], Realms[Task]) = {
def bootstrap(
as: ActorSystem
)(implicit cfg: AppConfig, mt: ActorMaterializer): (Permissions[Task], Acls[Task], Realms[Task]) = {
implicit val eff: Effect[Task] = Task.catsEffect(Scheduler.global)
import de.heikoseeberger.akkahttpcirce.FailFastCirceSupport._
implicit val system = as
Expand Down
Expand Up @@ -26,9 +26,11 @@ object RepairFromMessages {

private val log = Logger[RepairFromMessages.type]

def repair(p: Permissions[Task],
r: Realms[Task],
a: Acls[Task])(implicit as: ActorSystem, mt: ActorMaterializer, sc: Scheduler, pm: CanBlock): Unit = {
def repair(
p: Permissions[Task],
r: Realms[Task],
a: Acls[Task]
)(implicit as: ActorSystem, mt: ActorMaterializer, sc: Scheduler, pm: CanBlock): Unit = {
val pq = PersistenceQuery(as).readJournalFor[CassandraReadJournal](CassandraReadJournal.Identifier)

pq.currentPersistenceIds()
Expand Down
Expand Up @@ -46,7 +46,8 @@ object AclRejection {
*/
final case class IncorrectRev(path: Path, provided: Long, expected: Long)
extends AclRejection(
s"Incorrect revision '$provided' provided, expected '$expected', the ACL on path '${path.asString}' may have been updated since last seen.")
s"Incorrect revision '$provided' provided, expected '$expected', the ACL on path '${path.asString}' may have been updated since last seen."
)

/**
* Signals an attempt to create/replace/append/subtract ACL collection which contains void permissions.
Expand All @@ -63,7 +64,8 @@ object AclRejection {
*/
final case class UnknownPermissions(permissions: Set[Permission])
extends AclRejection(
s"Some of the permissions specified are not known: '${permissions.mkString("\"", ", ", "\"")}'")
s"Some of the permissions specified are not known: '${permissions.mkString("\"", ", ", "\"")}'"
)

implicit val aclRejectionEncoder: Encoder[AclRejection] = {
implicit val rejectionConfig: Configuration = Configuration.default.withDiscriminator("@type")
Expand Down
10 changes: 6 additions & 4 deletions src/main/scala/ch/epfl/bluebrain/nexus/iam/acls/Acls.scala
Expand Up @@ -30,7 +30,7 @@ import ch.epfl.bluebrain.nexus.sourcing.retry.Retry
//noinspection RedundantDefaultArgument
class Acls[F[_]](
val agg: Agg[F],
private val index: AclsIndex[F],
private val index: AclsIndex[F]
)(implicit F: MonadThrowable[F], http: HttpConfig, pc: PermissionsConfig) {

/**
Expand Down Expand Up @@ -164,7 +164,8 @@ object Acls {
* Constructs a new acls aggregate.
*/
def aggregate[F[_]: Effect: Timer: Clock](
perms: F[Permissions[F]])(implicit as: ActorSystem, mt: ActorMaterializer, ac: AclsConfig): F[Agg[F]] =
perms: F[Permissions[F]]
)(implicit as: ActorSystem, mt: ActorMaterializer, ac: AclsConfig): F[Agg[F]] =
AkkaAggregate.sharded[F](
"acls",
AclState.Initial,
Expand Down Expand Up @@ -271,8 +272,9 @@ object Acls {
}
}

private def evaluate[F[_]: Monad: Clock](perms: F[Permissions[F]])(state: State,
cmd: Command): F[EventOrRejection] = {
private def evaluate[F[_]: Monad: Clock](
perms: F[Permissions[F]]
)(state: State, cmd: Command): F[EventOrRejection] = {
val F = implicitly[Monad[F]]
val C = implicitly[Clock[F]]
def accept(f: Instant => Event): F[EventOrRejection] =
Expand Down

0 comments on commit 9cf451a

Please sign in to comment.