Skip to content

Instantly share code, notes, and snippets.

@wuhx
Created April 25, 2016 15:26
Show Gist options
  • Save wuhx/9058fa9466a9d7004449840cdd5b289b to your computer and use it in GitHub Desktop.
Save wuhx/9058fa9466a9d7004449840cdd5b289b to your computer and use it in GitHub Desktop.
import scala.pickling.Defaults._
import scala.pickling.json.{JSONPickleBuilder, JSONPickleFormat, JsonFormats}
import scala.pickling.{Output, PBuilder, PickleTools, StringOutput}
implicit val pickleFormat: JSONPickleFormat = new JSONPickleFormat {
override def createBuilder() = new JSONPickleBuilder(this, new StringOutput) with PickleTools {
hintStaticallyElidedType()
}
override def createBuilder(out: Output[String]): PBuilder = new JSONPickleBuilder(this, out) with PickleTools {
hintStaticallyElidedType()
}
}
case class KeyFilePair(priv: String, pub: String, keyPass: String) {
def this(priv: String) = this(priv, priv+".pub", "")
}
case class Auth(user: String, authType: String, password: String, keyPair: KeyFilePair)
case class Cloud(vendor: String, apiFile: String)
case class DynamicServer(cloud: Cloud, region: String, auth: Auth, size: String)
case class StaticServer(ip: String, sshPort: Int, auth: Auth)
case class Config(name: String,
localPort: Int,
serverPorts: Seq[Int], //multi port for temp tcp reset
serverType: String, //dynamic static
dynamicServer: DynamicServer,
staticServer: StaticServer
)
val keyPair = new KeyFilePair("sshkey")
val auth = Auth("root", "pubkey", "", keyPair)
val cloud = Cloud("digitalocean", "do.conf")
val dynamicServer = DynamicServer(cloud,"nyc3", auth,"512mb")
val conf =new Config("ditalocean-nyc3", 1080, Seq(443, 1984), "dynamic", dynamicServer, null)
scala> conf.pickle.value
res5: String =
{
"name": "ditalocean-nyc3",
"localPort": 1080,
"serverPorts": {
"$type": "scala.collection.Seq[scala.Int]",
"elems": [
443,
1984
]
},
"serverType": "dynamic",
"dynamicServer": {
"cloud": {
"vendor": "digitalocean",
"apiFile": "do.conf"
},
"region": "nyc3",
"auth": {
"user": "root",
"authType": "pubkey",
"password": "",
"keyPair": {
"priv": "sshkey",
"pub": "sshkey.pub",
"keyPass": ""
}
},
"size": "512mb"
},
"staticServer": null
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment