This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def writes(o: T): JsObject = { | |
val canonicalName = Option(clazz.getCanonicalName()).getOrElse(throw new IllegalArgumentException("Cannot serialize this class because its canonical name is null. This is most likely because it is an Array or a Local or Anonymous class.")) | |
JsObject(Seq("className" -> JsString(canonicalName))) | |
} | |
// i find using the container type in one place better for understanding | |
// since we are threading transformations and operations on the Option until | |
// the end when we either have a result or we throw an exception | |
def writes(o: T): JsObject = | |
Option(clazz.getCanonicalName()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Clean, simple, compatible and meaningful. | |
# Tested on Linux, Unix and Windows under ANSI colors. | |
# It is recommended to use with a dark background and the font Inconsolata. | |
# Colors: black, red, green, yellow, *blue, magenta, cyan, and white. | |
# | |
# http://ysmood.org/wp/2013/03/my-ys-terminal-theme/ | |
# Mar 2013 ys | |
# Machine name. | |
function box_name { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ pkgs ? import <nixpkgs> {} | |
, lookout ? import <lookout> {} | |
, ... }: | |
let | |
inherit (pkgs) stdenv nixops jq git which bash curl ruby_1_9 maven redis procps; | |
inherit (pkgs.haskellPackages) ShellCheck; | |
inherit (lookout) jruby1_7_22; | |
in | |
stdenv.mkDerivation { | |
name = "micropush-ci"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class KeymasterPostLoginFilter(store: SessionStore)(implicit secretStoreApi: SecretStoreApi) | |
extends Filter[SessionIdRequest, Response, IdentifyRequest[Auth], IdentifyResponse[Tokens]] { | |
def apply(req: SessionIdRequest, | |
service: KeymasterIdentityProvider[IdentifyRequest[Auth], IdentifyResponse[Tokens]]): Future[Response] = { | |
for { | |
// this is where a `map would be nice on IdentifyRequest | |
// it would just look like `req.map(auth => transform(BasicRequest))` | |
// which we could expose via the IdentityService as a `.to[A]` method which calls the `map` | |
// so it would be `service.requestTo[BasicRequest](req)` | |
// anyway, using the `.transform` method, it should look like this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def consulResponse(s: Secrets): ConsulResponse = | |
ConsulResponse(...., Base64Encode(s.toJson), ...) | |
def mockConsulService(secrets: Secrets): Service[Request, Response] = { | |
new Service[Request, Response] { | |
def apply(req: Request): Future[Response] = { | |
val res = Response(Status.Ok) | |
(req.method, req.path) match { | |
case (Get, Root / "/v1/k1") => res.contentString = consulResponse(secrets).toJson |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// define the ADT | |
trait Tag { | |
val id: Byte | |
} | |
case object Empty extends Tag { | |
val id = -1.toByte | |
} | |
case object Initial extends Tag { | |
val id = 0.toByte | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Binder[A] { | |
def name(a: A): String | |
def hosts(a: A): String | |
} | |
implicit object LoginManagerBinder extends Binder[LoginManager] { | |
def name(manager: LoginManager): String = | |
manager.name | |
def hosts(manager: LoginManager): String = | |
manager.host |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scala> import io.circe._, io.circe.generic.auto._, io.circe.jawn._, io.circe.syntax._ | |
import io.circe._ | |
import io.circe.generic.auto._ | |
import io.circe.jawn._ | |
import io.circe.syntax._ | |
scala> import io.circe._ | |
import io.circe._ | |
scala> import io.circe.generic.auto._ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait LoginProvider { | |
val loginPath: Path // listen for POST on this | |
val location: String | |
def redirect: Response = | |
tap(Response(Status.Found))(_.location = location) | |
} | |
case class InternalLoginProvider(path: Path, hosts: String, loginPath: Path) extends LoginProvider { | |
val location = path.toString | |
val server = Http.newClient(hosts) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/******* Option-1: **********/ | |
/** | |
* Keymaster Config: | |
* | |
* "keymaster" { | |
* "upstreamEndpoints" : { | |
* identityProvider" : { | |
* "hosts" : "localhost:8081", // CSV of servers | |
* "path" : "/identityProvider" // use this path upstream |