Skip to content

Instantly share code, notes, and snippets.

// this is with POC (plain old curry)
// () => Filter
val loginPostService = new ExceptionFilter andThen
new ServiceFilter(serviceMatcher) andThen
new SessionIdFilter(sessionStore) andThen
new KeymasterLoginFilter(sessionStore) andThen
new KeymasterIdentityProvider(keymasterClient, Path(keymasterIdentityProviderPath))
// (ServerConfig) => Filter
private def secretTryFromString(s: String): Try[Secret] = {
Parse.parseOptions(s) match {
case Some(json) => SecretEncoder.EncodeJson.decode(json)
case None => Failure(s"unable to decode secret from string $s")
}
}
def getValue[A,B](k: String): Future[Try[String]] = {
getConsulResponse(k).map(str =>
str.decodeOption[ConsulResponse] match {
def secrets: Secrets ={
val s = cacheBuffer.last
if (s.current.expired) rotateSecrets.last
else s
}
/**
*Checks if the secret is knows. Rotates if the secret is the new secret.
**/
def find(f: Secret=>Boolean): Option[Secret] = {
val lastSecrets = cacheBuffer.last
# the Request protocol is simple:
#
# [Method] [Path] [Version]
# Host: [Hostname]
# <new line>
# [Body]
# <new lines>
#
# here is an example of GET (which has an empty body, because GET usually means retrieve something from the server):
GET / HTTP/1.1
// ServiceRouter1[ServiceIdentifier] => ...
// Map[ServiceIdentifier, Httpx.Client]
// (ServiceRouter / SessionIdRouter / IdentityRouter / AccessRouter) {(service, session, identity, access) => ...}
//
// ServiceRouter2[UpstreamService]
// case class UpstreamService(id: ServiceIdentifier) {
// val service = Httpx.newClient()
// val endpoint = authFilterChain andThen service
// }
// authFilterChain = SessionIdFilter andThen IdentityFilter andThen ...
service(req) handle {
case AccessDenied => ???
case SessionStoreError(msg) => ???
...
}
import com.twitter.finagle.memcached
case object FailingMock extends memcached.MockClient {
override def add(key: String, flags: Int, expiry: Time, value: Buf): Future[Boolean] =
Future.exception(new Exception("oopsie"))
}
@trane
trane / code_and_bench.scala
Created September 30, 2015 00:41
some super simple micro benchmarks, only looking for large differences
object SecretEncoder {
import io.circe._
import io.circe.generic.semiauto._
/**
* Helper method for creating new [[com.lookout.borderpatrol.sessionx.SecretEncoder SecretEncoder]] instances
*/
def apply[A](f: Secret => A, g: A => Try[Secret]): SecretEncoder[A] =
new SecretEncoder[A] {
def encode(secret: Secret): A = f(secret)
def decode(a: A): Try[Secret] = g(a)
in/prepare-boot-drive-from-iso ~/Downloads/nixos-minimal-15.09.431.52a8811-x86_64-linux.iso /dev/disk2
This will replace all your data on /dev/disk2. Are you sure you want to proceed? (yes|no) yes
Reading Master Boot Record (MBR : 0)…
Reading NIXOS_ISO (Apple_ISO : 1)…
..................................................................................................................................................
Reading (Type EF : 2)…
.......................................................................................................................................................
Reading NIXOS_ISO (Apple_ISO : 3)…
.............................................................................................................................................................
Elapsed Time: 3.591s
import com.twitter.app._
import java.net.InetSocketAddress
object Main extends App {
// set default values for this flag, if it isn't passed in at command line
val memcachedF = flag("memcached", Seq(new InetSocketAddress(0)), "memcached addresses")
// print out the current value of the memcached flag (at this point, it's just the default value)
println(s"1. memcacheds from defaults: ${memcachedF()}")