group.go 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package models
  2. import (
  3. // "../mongoconn"
  4. "go.mongodb.org/mongo-driver/bson/primitive"
  5. "time"
  6. )
  7. //Group Struct
  8. //At some point, need to replace all instances of Name with something else like Identifier
  9. type Group struct {
  10. ID primitive.ObjectID `json:"_id,omitempty" bson:"_id,omitempty"`
  11. AddressRange string `json:"addressrange" bson:"addressrange" validate:"required,addressrange_valid"`
  12. DisplayName string `json:"displayname,omitempty" bson:"displayname,omitempty" validate:"omitempty,displayname_unique,min=1,max=100"`
  13. NameID string `json:"nameid" bson:"nameid" validate:"required,nameid_valid,min=1,max=12"`
  14. NodesLastModified int64 `json:"nodeslastmodified" bson:"nodeslastmodified"`
  15. GroupLastModified int64 `json:"grouplastmodified" bson:"grouplastmodified"`
  16. DefaultInterface string `json:"defaulinterface" bson:"defaultinterface"`
  17. DefaultListenPort int32 `json:"defaultlistenport,omitempty" bson:"defaultlistenport,omitempty" validate:"omitempty,numeric,min=1024,max=65535"`
  18. DefaultPostUp string `json:"defaultpostup" bson:"defaultpostup"`
  19. DefaultPreUp string `json:"defaultpreup" bson:"defaultpreup"`
  20. KeyUpdateTimeStamp int64 `json:"keyupdatetimestamp" bson:"keyupdatetimestamp"`
  21. DefaultKeepalive int32 `json:"defaultkeepalive" bson:"defaultkeepalive" validate: "omitempty,numeric,max=1000"`
  22. DefaultSaveConfig *bool `json:"defaultsaveconfig" bson:"defaultsaveconfig"`
  23. AccessKeys []AccessKey `json:"accesskeys" bson:"accesskeys"`
  24. AllowManualSignUp *bool `json:"allowmanualsignup" bson:"allowmanualsignup"`
  25. DefaultCheckInInterval int32 `json:"checkininterval,omitempty" bson:"checkininterval,omitempty" validate:"omitempty,numeric,min=1,max=100000"`
  26. }
  27. //TODO:
  28. //Not sure if we need the below two functions. Got rid of one of the calls. May want to revisit
  29. func(group *Group) SetNodesLastModified(){
  30. group.NodesLastModified = time.Now().Unix()
  31. }
  32. func(group *Group) SetGroupLastModified(){
  33. group.GroupLastModified = time.Now().Unix()
  34. }
  35. func(group *Group) SetDefaults(){
  36. if group.DisplayName == "" {
  37. group.DisplayName = group.NameID
  38. }
  39. if group.DefaultInterface == "" {
  40. group.DefaultInterface = "nm-" + group.NameID
  41. }
  42. if group.DefaultListenPort == 0 {
  43. group.DefaultListenPort = 51821
  44. }
  45. if group.DefaultPreUp == "" {
  46. }
  47. if group.DefaultSaveConfig == nil {
  48. defaultsave := true
  49. group.DefaultSaveConfig = &defaultsave
  50. }
  51. if group.DefaultKeepalive == 0 {
  52. group.DefaultKeepalive = 20
  53. }
  54. if group.DefaultPostUp == "" {
  55. }
  56. //Check-In Interval for Nodes, In Seconds
  57. if group.DefaultCheckInInterval == 0 {
  58. group.DefaultCheckInInterval = 30
  59. }
  60. if group.AllowManualSignUp == nil {
  61. signup := false
  62. group.AllowManualSignUp = &signup
  63. }
  64. }