secgrouprule.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package bingocloud
  15. import (
  16. "fmt"
  17. "yunion.io/x/cloudmux/pkg/cloudprovider"
  18. "yunion.io/x/pkg/util/secrules"
  19. )
  20. type IPPermissions struct {
  21. direction secrules.TSecurityRuleDirection
  22. BoundType string `json:"boundType"`
  23. Description string `json:"description"`
  24. FromPort int `json:"fromPort"`
  25. IPProtocol string `json:"ipProtocol"`
  26. Groups []struct {
  27. GroupId string
  28. GroupName string
  29. } `json:"groups"`
  30. IPRanges []struct {
  31. CIDRIP string `json:"cidrIp"`
  32. } `json:"ipRanges"`
  33. L2Accept string `json:"l2Accept"`
  34. PermissionId string `json:"permissionId"`
  35. Policy string `json:"policy"`
  36. ToPort int `json:"toPort"`
  37. }
  38. func (self *IPPermissions) GetGlobalId() string {
  39. return self.PermissionId
  40. }
  41. func (self *IPPermissions) GetDescription() string {
  42. return self.Description
  43. }
  44. func (self *IPPermissions) GetAction() secrules.TSecurityRuleAction {
  45. if self.Policy == "DROP" {
  46. return secrules.SecurityRuleDeny
  47. }
  48. return secrules.SecurityRuleAllow
  49. }
  50. func (self *IPPermissions) GetProtocol() string {
  51. protocol := secrules.PROTO_ANY
  52. if self.IPProtocol != "all" {
  53. protocol = self.IPProtocol
  54. }
  55. return protocol
  56. }
  57. func (self *IPPermissions) GetPorts() string {
  58. if self.GetProtocol() == secrules.PROTO_TCP || self.GetProtocol() == secrules.PROTO_UDP {
  59. return fmt.Sprintf("%d-%d", self.FromPort, self.ToPort)
  60. }
  61. return ""
  62. }
  63. func (self *IPPermissions) GetPriority() int {
  64. return 0
  65. }
  66. func (self *IPPermissions) GetCIDRs() []string {
  67. nets := []string{}
  68. for _, ip := range self.IPRanges {
  69. nets = append(nets, ip.CIDRIP)
  70. }
  71. return nets
  72. }
  73. func (self *IPPermissions) GetDirection() secrules.TSecurityRuleDirection {
  74. return self.direction
  75. }
  76. func (self *IPPermissions) Delete() error {
  77. return cloudprovider.ErrNotImplemented
  78. }
  79. func (self *IPPermissions) Update(opts *cloudprovider.SecurityGroupRuleUpdateOptions) error {
  80. return cloudprovider.ErrNotImplemented
  81. }