NB: the client library has been moved to the main Permission code-base. Please make any further updates there. https://github.com/guardian/permissions
Scala Client library for the Guardian's Editorial Permissions service.
Add the following dependency to your build.sbt
libraryDependencies += "com.gu" %% "editorial-permissions-client" % "0.2"
Then mixin the PermissionsProvider
trait to configure integration with
PermissionsConfig
and all your application Permissions by defining val all: Seq[Permission]
.
For example:
import com.gu.editorial.permissions.client._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future
object MyPermissions extends PermissionsProvider {
val app = "composer"
implicit def config = PermissionsConfig(
app = app,
all = all
)
val LaunchContent = Permission("launch_content", app, PermissionGranted)
val all = Seq(LaunchContent)
}
object Example {
implicit def permissionsUser: PermissionsUser =
PermissionsUser("[email protected]")
MyPermissions.get(MyPermissions.LaunchContent).map {
case PermissionGranted => "I'm in!"
case PermissionDenied => ":("
}
val myPerms: Future[PermissionsMap] = MyPermissions.list
}
Ensure tests pass before a release.
sbt clean test
Then release using:
sbt release
Note you will need:
- access to the
com.gu
group in Sonatype - a gpg key with public key sent to http://pgp.mit.edu/ see sbt-pgp
- your Sonatype credentials accessible to SBT using sbt-sonatype