Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement