acl.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package models
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. type AclID string
  7. func (aID AclID) String() string {
  8. return string(aID)
  9. }
  10. func (a *Acl) GetID(netID NetworkID, name string) {
  11. a.ID = AclID(fmt.Sprintf("%s.%s", netID.String(), name))
  12. }
  13. func FormatAclID(netID NetworkID, name string) AclID {
  14. return AclID(fmt.Sprintf("%s.%s", netID.String(), name))
  15. }
  16. // AllowedTrafficDirection - allowed direction of traffic
  17. type AllowedTrafficDirection int
  18. const (
  19. // TrafficDirectionUni implies traffic is only allowed in one direction (src --> dst)
  20. TrafficDirectionUni AllowedTrafficDirection = iota
  21. // TrafficDirectionBi implies traffic is allowed both direction (src <--> dst )
  22. TrafficDirectionBi
  23. )
  24. type AclPolicyType string
  25. const (
  26. UserPolicy AclPolicyType = "user-policy"
  27. DevicePolicy AclPolicyType = "device-policy"
  28. )
  29. type AclPolicyTag struct {
  30. ID AclGroupType `json:"id"`
  31. Value string `json:"value"`
  32. }
  33. type AclGroupType string
  34. const (
  35. UserAclID AclGroupType = "user"
  36. UserGroupAclID AclGroupType = "user-group"
  37. UserRoleAclID AclGroupType = "user-role"
  38. DeviceAclID AclGroupType = "tag"
  39. NetmakerIPAclID AclGroupType = "ip"
  40. NetmakerSubNetRangeAClID AclGroupType = "ipset"
  41. )
  42. func (g AclGroupType) String() string {
  43. return string(g)
  44. }
  45. type UpdateAclRequest struct {
  46. Acl
  47. NewName string `json:"new_name"`
  48. }
  49. type AclPolicy struct {
  50. TypeID AclPolicyType
  51. PrefixTagUser AclGroupType
  52. }
  53. type Acl struct {
  54. ID AclID `json:"id"`
  55. Default bool `json:"default"`
  56. Name string `json:"name"`
  57. NetworkID NetworkID `json:"network_id"`
  58. RuleType AclPolicyType `json:"policy_type"`
  59. Src []AclPolicyTag `json:"src_type"`
  60. Dst []AclPolicyTag `json:"dst_type"`
  61. AllowedDirection AllowedTrafficDirection `json:"allowed_traffic_direction"`
  62. Enabled bool `json:"enabled"`
  63. CreatedBy string `json:"created_by"`
  64. CreatedAt time.Time `json:"created_at"`
  65. }
  66. type AclPolicyTypes struct {
  67. RuleTypes []AclPolicyType `json:"policy_types"`
  68. SrcGroupTypes []AclGroupType `json:"src_grp_types"`
  69. DstGroupTypes []AclGroupType `json:"dst_grp_types"`
  70. }