structs.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package models
  2. import jwt "github.com/dgrijalva/jwt-go"
  3. type AuthParams struct {
  4. MacAddress string `json:"macaddress"`
  5. Password string `json:"password"`
  6. }
  7. type User struct {
  8. UserName string `json:"username" bson:"username" validate:"min=3,max=40,regexp=^(([a-zA-Z,\-,\.]*)|([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4})){3,40}$"`
  9. Password string `json:"password" bson:"password" validate:"required,min=5"`
  10. Networks []string `json:"networks" bson:"networks"`
  11. IsAdmin bool `json:"isadmin" bson:"isadmin"`
  12. }
  13. type UserAuthParams struct {
  14. UserName string `json:"username"`
  15. Password string `json:"password"`
  16. }
  17. type UserClaims struct {
  18. IsAdmin bool
  19. UserName string
  20. Networks []string
  21. jwt.StandardClaims
  22. }
  23. type SuccessfulUserLoginResponse struct {
  24. UserName string
  25. AuthToken string
  26. }
  27. // Claims is a struct that will be encoded to a JWT.
  28. // jwt.StandardClaims is an embedded type to provide expiry time
  29. type Claims struct {
  30. Network string
  31. MacAddress string
  32. jwt.StandardClaims
  33. }
  34. // SuccessfulLoginResponse is struct to send the request response
  35. type SuccessfulLoginResponse struct {
  36. MacAddress string
  37. AuthToken string
  38. }
  39. type ErrorResponse struct {
  40. Code int
  41. Message string
  42. }
  43. type NodeAuth struct {
  44. Network string
  45. Password string
  46. MacAddress string
  47. }
  48. // SuccessResponse is struct for sending error message with code.
  49. type SuccessResponse struct {
  50. Code int
  51. Message string
  52. Response interface{}
  53. }
  54. type AccessKey struct {
  55. Name string `json:"name" bson:"name" validate:"omitempty,alphanum,max=20"`
  56. Value string `json:"value" bson:"value" validate:"omitempty,alphanum,max=16"`
  57. AccessString string `json:"accessstring" bson:"accessstring"`
  58. Uses int `json:"uses" bson:"uses"`
  59. }
  60. type DisplayKey struct {
  61. Name string `json:"name" bson:"name"`
  62. Uses int `json:"uses" bson:"uses"`
  63. }
  64. type GlobalConfig struct {
  65. Name string `json:"name" bson:"name"`
  66. PortGRPC string `json:"portgrpc" bson:"portgrpc"`
  67. ServerGRPC string `json:"servergrpc" bson:"servergrpc"`
  68. }
  69. type CheckInResponse struct {
  70. Success bool `json:"success" bson:"success"`
  71. NeedPeerUpdate bool `json:"needpeerupdate" bson:"needpeerupdate"`
  72. NeedConfigUpdate bool `json:"needconfigupdate" bson:"needconfigupdate"`
  73. NeedKeyUpdate bool `json:"needkeyupdate" bson:"needkeyupdate"`
  74. NeedDelete bool `json:"needdelete" bson:"needdelete"`
  75. NodeMessage string `json:"nodemessage" bson:"nodemessage"`
  76. IsPending bool `json:"ispending" bson:"ispending"`
  77. }
  78. type PeersResponse struct {
  79. PublicKey string `json:"publickey" bson:"publickey"`
  80. Endpoint string `json:"endpoint" bson:"endpoint"`
  81. Address string `json:"address" bson:"address"`
  82. Address6 string `json:"address6" bson:"address6"`
  83. LocalAddress string `json:"localaddress" bson:"localaddress"`
  84. IsEgressGateway bool `json:"isegressgateway" bson:"isegressgateway"`
  85. EgressGatewayRange string `json:"egressgatewayrange" bson:"egressgatewayrange"`
  86. ListenPort int32 `json:"listenport" bson:"listenport"`
  87. KeepAlive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"`
  88. }
  89. type ExtPeersResponse struct {
  90. PublicKey string `json:"publickey" bson:"publickey"`
  91. Endpoint string `json:"endpoint" bson:"endpoint"`
  92. Address string `json:"address" bson:"address"`
  93. Address6 string `json:"address6" bson:"address6"`
  94. LocalAddress string `json:"localaddress" bson:"localaddress"`
  95. ListenPort int32 `json:"listenport" bson:"listenport"`
  96. KeepAlive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"`
  97. }
  98. type EgressGatewayRequest struct {
  99. NodeID string `json:"nodeid" bson:"nodeid"`
  100. NetID string `json:"netid" bson:"netid"`
  101. RangeString string `json:"rangestring" bson:"rangestring"`
  102. Ranges []string `json:"ranges" bson:"ranges"`
  103. Interface string `json:"interface" bson:"interface"`
  104. PostUp string `json:"postup" bson:"postup"`
  105. PostDown string `json:"postdown" bson:"postdown"`
  106. }