Advertisement
Guest User

Untitled

a guest
Apr 25th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. import scala.pickling.Defaults._
  2. import scala.pickling.json.{JSONPickleBuilder, JSONPickleFormat, JsonFormats}
  3. import scala.pickling.{Output, PBuilder, PickleTools, StringOutput}
  4.  
  5. implicit val pickleFormat: JSONPickleFormat = new JSONPickleFormat {
  6. override def createBuilder() = new JSONPickleBuilder(this, new StringOutput) with PickleTools {
  7. hintStaticallyElidedType()
  8. }
  9. override def createBuilder(out: Output[String]): PBuilder = new JSONPickleBuilder(this, out) with PickleTools {
  10. hintStaticallyElidedType()
  11. }
  12. }
  13.  
  14. case class KeyFilePair(priv: String, pub: String, keyPass: String) {
  15. def this(priv: String) = this(priv, priv+".pub", "")
  16. }
  17. case class Auth(user: String, authType: String, password: String, keyPair: KeyFilePair)
  18. case class Cloud(vendor: String, apiFile: String)
  19. case class DynamicServer(cloud: Cloud, region: String, auth: Auth, size: String)
  20. case class StaticServer(ip: String, sshPort: Int, auth: Auth)
  21.  
  22. case class Config(name: String,
  23. localPort: Int,
  24. serverPorts: Seq[Int], //multi port for temp tcp reset
  25. serverType: String, //dynamic static
  26. dynamicServer: DynamicServer,
  27. staticServer: StaticServer
  28. )
  29.  
  30. val keyPair = new KeyFilePair("sshkey")
  31. val auth = Auth("root", "pubkey", "", keyPair)
  32. val cloud = Cloud("digitalocean", "do.conf")
  33. val dynamicServer = DynamicServer(cloud,"nyc3", auth,"512mb")
  34. val conf =new Config("ditalocean-nyc3", 1080, Seq(443, 1984), "dynamic", dynamicServer, null)
  35.  
  36. scala> conf.pickle.value
  37. res5: String =
  38. {
  39. "name": "ditalocean-nyc3",
  40. "localPort": 1080,
  41. "serverPorts": {
  42. "$type": "scala.collection.Seq[scala.Int]",
  43. "elems": [
  44. 443,
  45. 1984
  46. ]
  47. },
  48. "serverType": "dynamic",
  49. "dynamicServer": {
  50. "cloud": {
  51. "vendor": "digitalocean",
  52. "apiFile": "do.conf"
  53. },
  54. "region": "nyc3",
  55. "auth": {
  56. "user": "root",
  57. "authType": "pubkey",
  58. "password": "",
  59. "keyPair": {
  60. "priv": "sshkey",
  61. "pub": "sshkey.pub",
  62. "keyPass": ""
  63. }
  64. },
  65. "size": "512mb"
  66. },
  67. "staticServer": null
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement