| 1 |
package ecs |
| 2 |
|
| 3 |
import ( |
| 4 |
"github.com/denverdino/aliyungo/common" |
| 5 |
"github.com/denverdino/aliyungo/util" |
| 6 |
) |
| 7 |
|
| 8 |
type NicType string |
| 9 |
type Direction string |
| 10 |
|
| 11 |
const ( |
| 12 |
NicTypeInternet = NicType("internet") |
| 13 |
NicTypeIntranet = NicType("intranet") |
| 14 |
|
| 15 |
DirectionIngress = Direction("ingress") |
| 16 |
DirectionEgress = Direction("egress") |
| 17 |
DirectionAll = Direction("all") |
| 18 |
) |
| 19 |
|
| 20 |
type IpProtocol string |
| 21 |
|
| 22 |
const ( |
| 23 |
IpProtocolAll = IpProtocol("all") |
| 24 |
IpProtocolTCP = IpProtocol("tcp") |
| 25 |
IpProtocolUDP = IpProtocol("udp") |
| 26 |
IpProtocolICMP = IpProtocol("icmp") |
| 27 |
IpProtocolGRE = IpProtocol("gre") |
| 28 |
) |
| 29 |
|
| 30 |
type PermissionPolicy string |
| 31 |
|
| 32 |
const ( |
| 33 |
PermissionPolicyAccept = PermissionPolicy("accept") |
| 34 |
PermissionPolicyDrop = PermissionPolicy("drop") |
| 35 |
) |
| 36 |
|
| 37 |
type GroupInnerAccessPolicy string |
| 38 |
|
| 39 |
const ( |
| 40 |
GroupInnerAccept = GroupInnerAccessPolicy("Accept") |
| 41 |
GroupInnerDrop = GroupInnerAccessPolicy("Drop") |
| 42 |
) |
| 43 |
|
| 44 |
type DescribeSecurityGroupAttributeArgs struct { |
| 45 |
SecurityGroupId string |
| 46 |
RegionId common.Region |
| 47 |
NicType NicType |
| 48 |
Direction Direction |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
type PermissionType struct { |
| 54 |
IpProtocol IpProtocol |
| 55 |
PortRange string |
| 56 |
SourceCidrIp string |
| 57 |
SourceGroupId string |
| 58 |
SourceGroupOwnerAccount string |
| 59 |
DestCidrIp string |
| 60 |
DestGroupId string |
| 61 |
DestGroupOwnerAccount string |
| 62 |
Policy PermissionPolicy |
| 63 |
NicType NicType |
| 64 |
Priority int |
| 65 |
Direction string |
| 66 |
Description string |
| 67 |
} |
| 68 |
|
| 69 |
type DescribeSecurityGroupAttributeResponse struct { |
| 70 |
common.Response |
| 71 |
|
| 72 |
SecurityGroupId string |
| 73 |
SecurityGroupName string |
| 74 |
RegionId common.Region |
| 75 |
Description string |
| 76 |
Permissions struct { |
| 77 |
Permission []PermissionType |
| 78 |
} |
| 79 |
VpcId string |
| 80 |
InnerAccessPolicy GroupInnerAccessPolicy |
| 81 |
} |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
func (client *Client) DescribeSecurityGroupAttribute(args *DescribeSecurityGroupAttributeArgs) (response *DescribeSecurityGroupAttributeResponse, err error) { |
| 86 |
response = &DescribeSecurityGroupAttributeResponse{} |
| 87 |
err = client.Invoke("DescribeSecurityGroupAttribute", args, response) |
| 88 |
if err != nil { |
| 89 |
return nil, err |
| 90 |
} |
| 91 |
return response, nil |
| 92 |
} |
| 93 |
|
| 94 |
type DescribeSecurityGroupsArgs struct { |
| 95 |
RegionId common.Region |
| 96 |
VpcId string |
| 97 |
common.Pagination |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
type SecurityGroupItemType struct { |
| 103 |
SecurityGroupId string |
| 104 |
SecurityGroupName string |
| 105 |
Description string |
| 106 |
VpcId string |
| 107 |
CreationTime util.ISO6801Time |
| 108 |
} |
| 109 |
|
| 110 |
type DescribeSecurityGroupsResponse struct { |
| 111 |
common.Response |
| 112 |
common.PaginationResult |
| 113 |
|
| 114 |
RegionId common.Region |
| 115 |
SecurityGroups struct { |
| 116 |
SecurityGroup []SecurityGroupItemType |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
func (client *Client) DescribeSecurityGroups(args *DescribeSecurityGroupsArgs) (securityGroupItems []SecurityGroupItemType, pagination *common.PaginationResult, err error) { |
| 124 |
response, err := client.DescribeSecurityGroupsWithRaw(args) |
| 125 |
if err != nil { |
| 126 |
return nil, nil, err |
| 127 |
} |
| 128 |
|
| 129 |
return response.SecurityGroups.SecurityGroup, &response.PaginationResult, nil |
| 130 |
} |
| 131 |
|
| 132 |
func (client *Client) DescribeSecurityGroupsWithRaw(args *DescribeSecurityGroupsArgs) (response *DescribeSecurityGroupsResponse, err error) { |
| 133 |
args.Validate() |
| 134 |
response = &DescribeSecurityGroupsResponse{} |
| 135 |
|
| 136 |
err = client.Invoke("DescribeSecurityGroups", args, response) |
| 137 |
|
| 138 |
if err != nil { |
| 139 |
return nil, err |
| 140 |
} |
| 141 |
|
| 142 |
return response, nil |
| 143 |
} |
| 144 |
|
| 145 |
type CreateSecurityGroupArgs struct { |
| 146 |
RegionId common.Region |
| 147 |
SecurityGroupName string |
| 148 |
Description string |
| 149 |
VpcId string |
| 150 |
ClientToken string |
| 151 |
} |
| 152 |
|
| 153 |
type CreateSecurityGroupResponse struct { |
| 154 |
common.Response |
| 155 |
|
| 156 |
SecurityGroupId string |
| 157 |
} |
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
func (client *Client) CreateSecurityGroup(args *CreateSecurityGroupArgs) (securityGroupId string, err error) { |
| 163 |
response := CreateSecurityGroupResponse{} |
| 164 |
err = client.Invoke("CreateSecurityGroup", args, &response) |
| 165 |
if err != nil { |
| 166 |
return "", err |
| 167 |
} |
| 168 |
return response.SecurityGroupId, err |
| 169 |
} |
| 170 |
|
| 171 |
type DeleteSecurityGroupArgs struct { |
| 172 |
RegionId common.Region |
| 173 |
SecurityGroupId string |
| 174 |
} |
| 175 |
|
| 176 |
type DeleteSecurityGroupResponse struct { |
| 177 |
common.Response |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
func (client *Client) DeleteSecurityGroup(regionId common.Region, securityGroupId string) error { |
| 184 |
args := DeleteSecurityGroupArgs{ |
| 185 |
RegionId: regionId, |
| 186 |
SecurityGroupId: securityGroupId, |
| 187 |
} |
| 188 |
response := DeleteSecurityGroupResponse{} |
| 189 |
err := client.Invoke("DeleteSecurityGroup", &args, &response) |
| 190 |
return err |
| 191 |
} |
| 192 |
|
| 193 |
type ModifySecurityGroupAttributeArgs struct { |
| 194 |
RegionId common.Region |
| 195 |
SecurityGroupId string |
| 196 |
SecurityGroupName string |
| 197 |
Description string |
| 198 |
} |
| 199 |
|
| 200 |
type ModifySecurityGroupAttributeResponse struct { |
| 201 |
common.Response |
| 202 |
} |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
func (client *Client) ModifySecurityGroupAttribute(args *ModifySecurityGroupAttributeArgs) error { |
| 208 |
response := ModifySecurityGroupAttributeResponse{} |
| 209 |
err := client.Invoke("ModifySecurityGroupAttribute", args, &response) |
| 210 |
return err |
| 211 |
} |
| 212 |
|
| 213 |
type ModifySecurityGroupPolicyArgs struct { |
| 214 |
RegionId common.Region |
| 215 |
SecurityGroupId string |
| 216 |
InnerAccessPolicy GroupInnerAccessPolicy |
| 217 |
} |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
func (client *Client) ModifySecurityGroupPolicy(args *ModifySecurityGroupPolicyArgs) error { |
| 223 |
response := common.Response{} |
| 224 |
err := client.Invoke("ModifySecurityGroupPolicy", args, &response) |
| 225 |
return err |
| 226 |
} |
| 227 |
|
| 228 |
type AuthorizeSecurityGroupArgs struct { |
| 229 |
SecurityGroupId string |
| 230 |
RegionId common.Region |
| 231 |
IpProtocol IpProtocol |
| 232 |
PortRange string |
| 233 |
SourceGroupId string |
| 234 |
SourceGroupOwnerAccount string |
| 235 |
SourceGroupOwnerID string |
| 236 |
SourceCidrIp string |
| 237 |
Policy PermissionPolicy |
| 238 |
Priority int |
| 239 |
NicType NicType |
| 240 |
} |
| 241 |
|
| 242 |
type AuthorizeSecurityGroupResponse struct { |
| 243 |
common.Response |
| 244 |
} |
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
func (client *Client) AuthorizeSecurityGroup(args *AuthorizeSecurityGroupArgs) error { |
| 250 |
response := AuthorizeSecurityGroupResponse{} |
| 251 |
err := client.Invoke("AuthorizeSecurityGroup", args, &response) |
| 252 |
return err |
| 253 |
} |
| 254 |
|
| 255 |
type RevokeSecurityGroupArgs struct { |
| 256 |
AuthorizeSecurityGroupArgs |
| 257 |
} |
| 258 |
|
| 259 |
type RevokeSecurityGroupResponse struct { |
| 260 |
common.Response |
| 261 |
} |
| 262 |
|
| 263 |
|
| 264 |
func (client *Client) RevokeSecurityGroup(args *RevokeSecurityGroupArgs) error { |
| 265 |
response := RevokeSecurityGroupResponse{} |
| 266 |
err := client.Invoke("RevokeSecurityGroup", args, &response) |
| 267 |
return err |
| 268 |
} |
| 269 |
|
| 270 |
type AuthorizeSecurityGroupEgressArgs struct { |
| 271 |
SecurityGroupId string |
| 272 |
RegionId common.Region |
| 273 |
IpProtocol IpProtocol |
| 274 |
PortRange string |
| 275 |
DestGroupId string |
| 276 |
DestGroupOwnerAccount string |
| 277 |
DestGroupOwnerId string |
| 278 |
DestCidrIp string |
| 279 |
Policy PermissionPolicy |
| 280 |
Priority int |
| 281 |
NicType NicType |
| 282 |
} |
| 283 |
|
| 284 |
type AuthorizeSecurityGroupEgressResponse struct { |
| 285 |
common.Response |
| 286 |
} |
| 287 |
|
| 288 |
|
| 289 |
|
| 290 |
|
| 291 |
func (client *Client) AuthorizeSecurityGroupEgress(args *AuthorizeSecurityGroupEgressArgs) error { |
| 292 |
response := AuthorizeSecurityGroupEgressResponse{} |
| 293 |
err := client.Invoke("AuthorizeSecurityGroupEgress", args, &response) |
| 294 |
return err |
| 295 |
} |
| 296 |
|
| 297 |
type RevokeSecurityGroupEgressArgs struct { |
| 298 |
AuthorizeSecurityGroupEgressArgs |
| 299 |
} |
| 300 |
|
| 301 |
type RevokeSecurityGroupEgressResponse struct { |
| 302 |
common.Response |
| 303 |
} |
| 304 |
|
| 305 |
|
| 306 |
func (client *Client) RevokeSecurityGroupEgress(args *RevokeSecurityGroupEgressArgs) error { |
| 307 |
response := RevokeSecurityGroupEgressResponse{} |
| 308 |
err := client.Invoke("RevokeSecurityGroupEgress", args, &response) |
| 309 |
return err |
| 310 |
} |