|
39 | 39 | _ = namegenerator.GetRandomName |
40 | 40 | ) |
41 | 41 |
|
| 42 | +type ACLRuleProtocol string |
| 43 | + |
| 44 | +const ( |
| 45 | + ACLRuleProtocolANY = ACLRuleProtocol("ANY") |
| 46 | + ACLRuleProtocolTCP = ACLRuleProtocol("TCP") |
| 47 | + ACLRuleProtocolUDP = ACLRuleProtocol("UDP") |
| 48 | + ACLRuleProtocolICMP = ACLRuleProtocol("ICMP") |
| 49 | +) |
| 50 | + |
| 51 | +func (enum ACLRuleProtocol) String() string { |
| 52 | + if enum == "" { |
| 53 | + // return default value if empty |
| 54 | + return "ANY" |
| 55 | + } |
| 56 | + return string(enum) |
| 57 | +} |
| 58 | + |
| 59 | +func (enum ACLRuleProtocol) Values() []ACLRuleProtocol { |
| 60 | + return []ACLRuleProtocol{ |
| 61 | + "ANY", |
| 62 | + "TCP", |
| 63 | + "UDP", |
| 64 | + "ICMP", |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +func (enum ACLRuleProtocol) MarshalJSON() ([]byte, error) { |
| 69 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 70 | +} |
| 71 | + |
| 72 | +func (enum *ACLRuleProtocol) UnmarshalJSON(data []byte) error { |
| 73 | + tmp := "" |
| 74 | + |
| 75 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 76 | + return err |
| 77 | + } |
| 78 | + |
| 79 | + *enum = ACLRuleProtocol(ACLRuleProtocol(tmp).String()) |
| 80 | + return nil |
| 81 | +} |
| 82 | + |
| 83 | +type Action string |
| 84 | + |
| 85 | +const ( |
| 86 | + ActionUnknownAction = Action("unknown_action") |
| 87 | + ActionAccept = Action("accept") |
| 88 | + ActionDrop = Action("drop") |
| 89 | +) |
| 90 | + |
| 91 | +func (enum Action) String() string { |
| 92 | + if enum == "" { |
| 93 | + // return default value if empty |
| 94 | + return "unknown_action" |
| 95 | + } |
| 96 | + return string(enum) |
| 97 | +} |
| 98 | + |
| 99 | +func (enum Action) Values() []Action { |
| 100 | + return []Action{ |
| 101 | + "unknown_action", |
| 102 | + "accept", |
| 103 | + "drop", |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +func (enum Action) MarshalJSON() ([]byte, error) { |
| 108 | + return []byte(fmt.Sprintf(`"%s"`, enum)), nil |
| 109 | +} |
| 110 | + |
| 111 | +func (enum *Action) UnmarshalJSON(data []byte) error { |
| 112 | + tmp := "" |
| 113 | + |
| 114 | + if err := json.Unmarshal(data, &tmp); err != nil { |
| 115 | + return err |
| 116 | + } |
| 117 | + |
| 118 | + *enum = Action(Action(tmp).String()) |
| 119 | + return nil |
| 120 | +} |
| 121 | + |
42 | 122 | type ListPrivateNetworksRequestOrderBy string |
43 | 123 |
|
44 | 124 | const ( |
@@ -342,6 +422,38 @@ type Route struct { |
342 | 422 | Region scw.Region `json:"region"` |
343 | 423 | } |
344 | 424 |
|
| 425 | +// ACLRule: acl rule. |
| 426 | +type ACLRule struct { |
| 427 | + // Protocol: protocol to which this rule applies. |
| 428 | + // Default value: ANY |
| 429 | + Protocol ACLRuleProtocol `json:"protocol"` |
| 430 | + |
| 431 | + // Source: source IP range to which this rule applies (CIDR notation with subnet mask). |
| 432 | + Source scw.IPNet `json:"source"` |
| 433 | + |
| 434 | + // SrcPortLow: starting port of the source port range to which this rule applies (inclusive). |
| 435 | + SrcPortLow uint32 `json:"src_port_low"` |
| 436 | + |
| 437 | + // SrcPortHigh: ending port of the source port range to which this rule applies (inclusive). |
| 438 | + SrcPortHigh uint32 `json:"src_port_high"` |
| 439 | + |
| 440 | + // Destination: destination IP range to which this rule applies (CIDR notation with subnet mask). |
| 441 | + Destination scw.IPNet `json:"destination"` |
| 442 | + |
| 443 | + // DstPortLow: starting port of the destination port range to which this rule applies (inclusive). |
| 444 | + DstPortLow uint32 `json:"dst_port_low"` |
| 445 | + |
| 446 | + // DstPortHigh: ending port of the destination port range to which this rule applies (inclusive). |
| 447 | + DstPortHigh uint32 `json:"dst_port_high"` |
| 448 | + |
| 449 | + // Action: policy to apply to the packet. |
| 450 | + // Default value: unknown_action |
| 451 | + Action Action `json:"action"` |
| 452 | + |
| 453 | + // Description: rule description. |
| 454 | + Description *string `json:"description"` |
| 455 | +} |
| 456 | + |
345 | 457 | // RouteWithNexthop: route with nexthop. |
346 | 458 | type RouteWithNexthop struct { |
347 | 459 | // Route: route. |
@@ -536,6 +648,26 @@ type EnableRoutingRequest struct { |
536 | 648 | VpcID string `json:"-"` |
537 | 649 | } |
538 | 650 |
|
| 651 | +// GetACLRequest: get acl request. |
| 652 | +type GetACLRequest struct { |
| 653 | + // Region: region to target. If none is passed will use default region from the config. |
| 654 | + Region scw.Region `json:"-"` |
| 655 | + |
| 656 | + // VpcID: ID of the Network ACL's VPC. |
| 657 | + VpcID string `json:"-"` |
| 658 | + |
| 659 | + // IsIPv6: defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type. |
| 660 | + IsIPv6 bool `json:"is_ipv6"` |
| 661 | +} |
| 662 | + |
| 663 | +// GetACLResponse: get acl response. |
| 664 | +type GetACLResponse struct { |
| 665 | + Rules []*ACLRule `json:"rules"` |
| 666 | + |
| 667 | + // DefaultPolicy: default value: unknown_action |
| 668 | + DefaultPolicy Action `json:"default_policy"` |
| 669 | +} |
| 670 | + |
539 | 671 | // GetPrivateNetworkRequest: get private network request. |
540 | 672 | type GetPrivateNetworkRequest struct { |
541 | 673 | // Region: region to target. If none is passed will use default region from the config. |
@@ -806,6 +938,33 @@ type RoutesWithNexthopAPIListRoutesWithNexthopRequest struct { |
806 | 938 | IsIPv6 *bool `json:"-"` |
807 | 939 | } |
808 | 940 |
|
| 941 | +// SetACLRequest: set acl request. |
| 942 | +type SetACLRequest struct { |
| 943 | + // Region: region to target. If none is passed will use default region from the config. |
| 944 | + Region scw.Region `json:"-"` |
| 945 | + |
| 946 | + // VpcID: ID of the Network ACL's VPC. |
| 947 | + VpcID string `json:"-"` |
| 948 | + |
| 949 | + // Rules: list of Network ACL rules. |
| 950 | + Rules []*ACLRule `json:"rules"` |
| 951 | + |
| 952 | + // IsIPv6: defines whether this set of ACL rules is for IPv6 (false = IPv4). Each Network ACL can have rules for only one IP type. |
| 953 | + IsIPv6 bool `json:"is_ipv6"` |
| 954 | + |
| 955 | + // DefaultPolicy: action to take for packets which do not match any rules. |
| 956 | + // Default value: unknown_action |
| 957 | + DefaultPolicy Action `json:"default_policy"` |
| 958 | +} |
| 959 | + |
| 960 | +// SetACLResponse: set acl response. |
| 961 | +type SetACLResponse struct { |
| 962 | + Rules []*ACLRule `json:"rules"` |
| 963 | + |
| 964 | + // DefaultPolicy: default value: unknown_action |
| 965 | + DefaultPolicy Action `json:"default_policy"` |
| 966 | +} |
| 967 | + |
809 | 968 | // SetSubnetsRequest: set subnets request. |
810 | 969 | type SetSubnetsRequest struct { |
811 | 970 | // Region: region to target. If none is passed will use default region from the config. |
@@ -1605,6 +1764,77 @@ func (s *API) DeleteRoute(req *DeleteRouteRequest, opts ...scw.RequestOption) er |
1605 | 1764 | return nil |
1606 | 1765 | } |
1607 | 1766 |
|
| 1767 | +// GetACL: Retrieve a list of ACL rules for a VPC, specified by its VPC ID. |
| 1768 | +func (s *API) GetACL(req *GetACLRequest, opts ...scw.RequestOption) (*GetACLResponse, error) { |
| 1769 | + var err error |
| 1770 | + |
| 1771 | + if req.Region == "" { |
| 1772 | + defaultRegion, _ := s.client.GetDefaultRegion() |
| 1773 | + req.Region = defaultRegion |
| 1774 | + } |
| 1775 | + |
| 1776 | + query := url.Values{} |
| 1777 | + parameter.AddToQuery(query, "is_ipv6", req.IsIPv6) |
| 1778 | + |
| 1779 | + if fmt.Sprint(req.Region) == "" { |
| 1780 | + return nil, errors.New("field Region cannot be empty in request") |
| 1781 | + } |
| 1782 | + |
| 1783 | + if fmt.Sprint(req.VpcID) == "" { |
| 1784 | + return nil, errors.New("field VpcID cannot be empty in request") |
| 1785 | + } |
| 1786 | + |
| 1787 | + scwReq := &scw.ScalewayRequest{ |
| 1788 | + Method: "GET", |
| 1789 | + Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/vpc/" + fmt.Sprint(req.VpcID) + "/acl-rules", |
| 1790 | + Query: query, |
| 1791 | + } |
| 1792 | + |
| 1793 | + var resp GetACLResponse |
| 1794 | + |
| 1795 | + err = s.client.Do(scwReq, &resp, opts...) |
| 1796 | + if err != nil { |
| 1797 | + return nil, err |
| 1798 | + } |
| 1799 | + return &resp, nil |
| 1800 | +} |
| 1801 | + |
| 1802 | +// SetACL: Set the list of ACL rules and the default routing policy for a VPC. |
| 1803 | +func (s *API) SetACL(req *SetACLRequest, opts ...scw.RequestOption) (*SetACLResponse, error) { |
| 1804 | + var err error |
| 1805 | + |
| 1806 | + if req.Region == "" { |
| 1807 | + defaultRegion, _ := s.client.GetDefaultRegion() |
| 1808 | + req.Region = defaultRegion |
| 1809 | + } |
| 1810 | + |
| 1811 | + if fmt.Sprint(req.Region) == "" { |
| 1812 | + return nil, errors.New("field Region cannot be empty in request") |
| 1813 | + } |
| 1814 | + |
| 1815 | + if fmt.Sprint(req.VpcID) == "" { |
| 1816 | + return nil, errors.New("field VpcID cannot be empty in request") |
| 1817 | + } |
| 1818 | + |
| 1819 | + scwReq := &scw.ScalewayRequest{ |
| 1820 | + Method: "PUT", |
| 1821 | + Path: "/vpc/v2/regions/" + fmt.Sprint(req.Region) + "/vpc/" + fmt.Sprint(req.VpcID) + "/acl-rules", |
| 1822 | + } |
| 1823 | + |
| 1824 | + err = scwReq.SetBody(req) |
| 1825 | + if err != nil { |
| 1826 | + return nil, err |
| 1827 | + } |
| 1828 | + |
| 1829 | + var resp SetACLResponse |
| 1830 | + |
| 1831 | + err = s.client.Do(scwReq, &resp, opts...) |
| 1832 | + if err != nil { |
| 1833 | + return nil, err |
| 1834 | + } |
| 1835 | + return &resp, nil |
| 1836 | +} |
| 1837 | + |
1608 | 1838 | type RoutesWithNexthopAPI struct { |
1609 | 1839 | client *scw.Client |
1610 | 1840 | } |
|
0 commit comments