securitygroup.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 cloudprovider
  15. import (
  16. "fmt"
  17. "strings"
  18. "yunion.io/x/pkg/util/secrules"
  19. )
  20. type SecurityGroupReference struct {
  21. Id string
  22. Name string
  23. }
  24. type SecurityGroupCreateInput struct {
  25. Name string
  26. Desc string
  27. VpcId string
  28. ProjectId string
  29. Tags map[string]string
  30. }
  31. type SecurityGroupRuleCreateOptions struct {
  32. Desc string
  33. Priority int
  34. Protocol string
  35. Ports string
  36. Direction secrules.TSecurityRuleDirection
  37. CIDR string
  38. Action secrules.TSecurityRuleAction
  39. }
  40. type SecurityGroupRuleUpdateOptions struct {
  41. CIDR string
  42. Action secrules.TSecurityRuleAction
  43. Desc string
  44. Ports string
  45. Protocol string
  46. Priority int
  47. }
  48. func (rule *SecurityGroupRuleCreateOptions) String() string {
  49. ret := fmt.Sprintf("%s_%s_%s", rule.Direction, rule.Action, rule.Protocol)
  50. if len(rule.CIDR) > 0 {
  51. ret += "_" + rule.CIDR
  52. }
  53. if len(rule.Ports) > 0 {
  54. ret += "_" + rule.Ports
  55. }
  56. ret = strings.ReplaceAll(ret, ".", "_")
  57. ret = strings.ReplaceAll(ret, ",", "_")
  58. return ret
  59. }