Skip to content

Commit e887726

Browse files
committed
Adding support for GetSecurityGroupByName
Signed-off-by: Sameer Shaikh <[email protected]>
1 parent 2dc2601 commit e887726

File tree

4 files changed

+15
-51
lines changed

4 files changed

+15
-51
lines changed

common/messages/messages_en.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -177,20 +177,6 @@ var messagesEn = map[string]util.Message{
177177
RC: 500,
178178
Action: "Unable to list subnet. Run 'ibmcloud is subnets' to list available subnets in your account.",
179179
},
180-
"NextSubnetPageParsingError": {
181-
Code: "NextSubnetPageParsingError",
182-
Description: "The next field '%s' specified in the next parameter of the list subnet call could not be parsed.",
183-
Type: util.RetrivalFailed,
184-
RC: 500,
185-
Action: "Please verify that the next field is correct.",
186-
},
187-
"StartSubnetIDEmpty": {
188-
Code: "StartSubnetIDEmpty",
189-
Description: "The start '%s' specified in the next parameter of the list subnet call is empty.",
190-
Type: util.RetrivalFailed,
191-
RC: 500,
192-
Action: "Please verify that the start field is correct.",
193-
},
194180
"SubnetFindFailedWithZoneAndSubnetID": {
195181
Code: "SubnetFindFailedWithZoneAndSubnetID",
196182
Description: "A subnet with the specified zone '%s' and available cluster subnet list '%s' could not be found.",
@@ -205,20 +191,6 @@ var messagesEn = map[string]util.Message{
205191
RC: 500,
206192
Action: "Unable to list securityGroup. Run 'ibmcloud is securityGroups' to list available securityGroups in your account.",
207193
},
208-
"NextSecurityGroupPageParsingError": {
209-
Code: "NextSecurityGroupPageParsingError",
210-
Description: "The next field '%s' specified in the next parameter of the list securityGroup call could not be parsed.",
211-
Type: util.RetrivalFailed,
212-
RC: 500,
213-
Action: "Please verify that the next field is correct.",
214-
},
215-
"StartSecurityGroupIDEmpty": {
216-
Code: "StartSecurityGroupIDEmpty",
217-
Description: "The start '%s' specified in the next parameter of the list securityGroup call is empty.",
218-
Type: util.RetrivalFailed,
219-
RC: 500,
220-
Action: "Please verify that the start field is correct.",
221-
},
222194
"SecurityGroupFindFailedWithVPCAndSecurityGroupName": {
223195
Code: "SecurityGroupFindFailedWithVPCAndSecurityGroupName",
224196
Description: "A securityGroup with the specified cluster securityGroup name '%s' could not be found.",

file/provider/get_security_group.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
func (vpcs *VPCSession) GetSecurityGroupForVolumeAccessPoint(securityGroupRequest provider.SecurityGroupRequest) (string, error) {
3232
vpcs.Logger.Info("Entry of GetSecurityGroupForVolumeAccessPoint method...", zap.Reflect("securityGroupRequest", securityGroupRequest))
3333
defer vpcs.Logger.Info("Exit from GetSecurityGroupForVolumeAccessPoint method...")
34-
var err error
3534

3635
// Get SecurityGroup by VPC and name. This is inefficient operation which requires iteration over SecurityGroup list
3736
securityGroup, err := vpcs.getSecurityGroupByVPCAndSecurityGroupName(securityGroupRequest)
@@ -57,14 +56,12 @@ func (vpcs *VPCSession) getSecurityGroupByVPCAndSecurityGroupName(securityGroupR
5756

5857
if err != nil {
5958
// API call is failed
60-
userErr := userError.GetUserError("ListSecurityGroupsFailed", err)
61-
return "", userErr
59+
return "", userError.GetUserError("ListSecurityGroupsFailed", err)
6260
}
6361

6462
// Iterate over the SecurityGroup list for given volume
6563
if securityGroups != nil {
66-
securityGroupList := securityGroups.SecurityGroups
67-
for _, securityGroupItem := range securityGroupList {
64+
for _, securityGroupItem := range securityGroups.SecurityGroups {
6865
// Check if securityGroup is matching with requested input securityGroup name
6966
if strings.EqualFold(securityGroupRequest.Name, securityGroupItem.Name) {
7067
vpcs.Logger.Info("Successfully found securityGroup", zap.Reflect("securityGroupItem", securityGroupItem))
@@ -80,23 +77,22 @@ func (vpcs *VPCSession) getSecurityGroupByVPCAndSecurityGroupName(securityGroupR
8077
startUrl, err := url.Parse(securityGroups.Next.Href)
8178
if err != nil {
8279
// API call is failed
83-
userErr := userError.GetUserError("NextSecurityGroupPageParsingError", err, securityGroups.Next.Href)
84-
return "", userErr
80+
vpcs.Logger.Error("The next parameter of the securityGroup list could not be parsed.", zap.Reflect("Next", securityGroups.Next.Href), zap.Error(err))
81+
return "", userError.GetUserError(string("SecurityGroupFindFailedWithVPCAndSecurityGroupName"), err, securityGroupRequest.Name)
8582
}
8683

8784
vpcs.Logger.Info("startUrl", zap.Reflect("startUrl", startUrl))
8885
start = startUrl.Query().Get("start") //parse query param into map
8986
if start == "" {
9087
// API call is failed
91-
userErr := userError.GetUserError("StartSecurityGroupIDEmpty", err, startUrl)
92-
return "", userErr
88+
vpcs.Logger.Error("The start specified in the next parameter of the securityGroup list is empty.", zap.Reflect("startUrl", startUrl))
89+
return "", userError.GetUserError(string("SecurityGroupFindFailedWithVPCAndSecurityGroupName"), errors.New("no securityGroup found"), securityGroupRequest.Name)
9390
}
9491

9592
}
9693
}
9794

9895
// No volume SecurityGroup found in the list. So return error
99-
userErr := userError.GetUserError(string("SecurityGroupFindFailedWithVPCAndSecurityGroupName"), errors.New("no securityGroup found"), securityGroupRequest.Name)
10096
vpcs.Logger.Error("SecurityGroup not found", zap.Error(err))
101-
return "", userErr
97+
return "", userError.GetUserError(string("SecurityGroupFindFailedWithVPCAndSecurityGroupName"), errors.New("no securityGroup found"), securityGroupRequest.Name)
10298
}

file/provider/get_subnet.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
func (vpcs *VPCSession) GetSubnetForVolumeAccessPoint(subnetRequest provider.SubnetRequest) (string, error) {
3232
vpcs.Logger.Info("Entry of GetSubnetForVolumeAccessPoint method...", zap.Reflect("subnetRequest", subnetRequest))
3333
defer vpcs.Logger.Info("Exit from GetSubnetForVolumeAccessPoint method...")
34-
var err error
3534

3635
// Get Subnet by zone and cluster subnet list. This is inefficient operation which requires iteration over subnet list
3736
subnet, err := vpcs.getSubnetByZoneAndSubnetID(subnetRequest)
@@ -58,14 +57,12 @@ func (vpcs *VPCSession) getSubnetByZoneAndSubnetID(subnetRequest provider.Subnet
5857

5958
if err != nil {
6059
// API call is failed
61-
userErr := userError.GetUserError("ListSubnetsFailed", err)
62-
return "", userErr
60+
return "", userError.GetUserError("ListSubnetsFailed", err)
6361
}
6462

6563
// Iterate over the subnet list for given volume
6664
if subnets != nil {
67-
subnetList := subnets.Subnets
68-
for _, subnetItem := range subnetList {
65+
for _, subnetItem := range subnets.Subnets {
6966
// Check if subnet is matching with requested input subnet-list
7067
if strings.Contains(subnetRequest.SubnetIDList, subnetItem.ID) {
7168
vpcs.Logger.Info("Successfully found subnet", zap.Reflect("subnetItem", subnetItem))
@@ -81,23 +78,22 @@ func (vpcs *VPCSession) getSubnetByZoneAndSubnetID(subnetRequest provider.Subnet
8178
startUrl, err := url.Parse(subnets.Next.Href)
8279
if err != nil {
8380
// API call is failed
84-
userErr := userError.GetUserError("NextSubnetPageParsingError", err, subnets.Next.Href)
85-
return "", userErr
81+
vpcs.Logger.Error("The next parameter of the subnet list could not be parsed.", zap.Reflect("Next", subnets.Next.Href), zap.Error(err))
82+
return "", userError.GetUserError(string("SubnetFindFailedWithZoneAndSubnetID"), err, subnetRequest.ZoneName, subnetRequest.SubnetIDList)
8683
}
8784

8885
vpcs.Logger.Info("startUrl", zap.Reflect("startUrl", startUrl))
8986
start = startUrl.Query().Get("start") //parse query param into map
9087
if start == "" {
9188
// API call is failed
92-
userErr := userError.GetUserError("StartSubnetIDEmpty", err, startUrl)
93-
return "", userErr
89+
vpcs.Logger.Error("The start specified in the next parameter of the subnet list is empty.", zap.Reflect("start", startUrl))
90+
return "", userError.GetUserError(string("SubnetFindFailedWithZoneAndSubnetID"), errors.New("no subnet found"), subnetRequest.ZoneName, subnetRequest.SubnetIDList)
9491
}
9592

9693
}
9794
}
9895

9996
// No volume Subnet found in the list. So return error
100-
userErr := userError.GetUserError(string("SubnetFindFailedWithZoneAndSubnetID"), errors.New("no subnet found"), subnetRequest.ZoneName, subnetRequest.SubnetIDList)
10197
vpcs.Logger.Error("Subnet not found", zap.Error(err))
102-
return "", userErr
98+
return "", userError.GetUserError(string("SubnetFindFailedWithZoneAndSubnetID"), errors.New("no subnet found"), subnetRequest.ZoneName, subnetRequest.SubnetIDList)
10399
}

file/provider/util.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var skipErrorCodes = map[string]bool{
7070
"InvalidArgument": true,
7171
"shares_status_pending": false,
7272
"internal_error": false,
73-
"invalid_route": false,
73+
"invalid_route": true,
7474
"service_error": false,
7575
}
7676

0 commit comments

Comments
 (0)