Skip to content

Commit

Permalink
[KT Classic] Update RegionZone - Add Validation check
Browse files Browse the repository at this point in the history
  • Loading branch information
innodreamer committed Sep 30, 2024
1 parent 2fec698 commit e9f4f09
Showing 1 changed file with 37 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package resources

import (
"fmt"
"sync"
"strings"
// "errors"
Expand Down Expand Up @@ -203,18 +204,30 @@ func (regionZoneHandler *KtCloudRegionZoneHandler) ListOrgZone() (string, error)

func (regionZoneHandler KtCloudRegionZoneHandler) getZoneInfoList(regionCode string) ([]irs.ZoneInfo, error) {
cblogger.Info("KT Cloud VPC Driver: called getZoneInfoList()!!")
InitLog()
callLogInfo := GetCallLogScheme(regionZoneHandler.RegionInfo.Zone, call.REGIONZONE, regionCode, "getZoneInfoList()")

if strings.EqualFold(regionCode, "") {
rtnErr := logAndReturnError(callLogInfo, "Invalid RegionCode!!", "")
return nil, rtnErr
newErr := fmt.Errorf("Invalid RegionCode!!")
cblogger.Error(newErr.Error())
return nil, newErr
}

if strings.EqualFold(regionZoneHandler.CredentialInfo.ClientId, "") {
newErr := fmt.Errorf("Invalid ClientId!!")
cblogger.Error(newErr.Error())
return nil, newErr
}

if strings.EqualFold(regionZoneHandler.CredentialInfo.ClientSecret, "") {
newErr := fmt.Errorf("Invalid ClientSecret!!")
cblogger.Error(newErr.Error())
return nil, newErr
}

ktZoneList, err := regionZoneHandler.getKtZoneList(regionCode)
if err != nil {
rtnErr := logAndReturnError(callLogInfo, "Failed to Get KT Cloud ZoneList :", err)
return nil, rtnErr
newErr := fmt.Errorf("Failed to Get KT Cloud ZoneList : [%v]", err)
cblogger.Error(newErr.Error())
return nil, newErr
}

var zoneInfoList []irs.ZoneInfo
Expand All @@ -235,12 +248,23 @@ func (regionZoneHandler KtCloudRegionZoneHandler) getZoneInfoList(regionCode str

func (regionZoneHandler KtCloudRegionZoneHandler) getKtZoneList(regionCode string) ([]ktsdk.Zone, error) {
cblogger.Info("KT Cloud Driver: called getKtZoneList()!!")
InitLog()
callLogInfo := GetCallLogScheme(regionZoneHandler.RegionInfo.Zone, call.REGIONZONE, regionCode, "getKtZoneList()")

if strings.EqualFold(regionCode, "") {
rtnErr := logAndReturnError(callLogInfo, "Invalid RegionCode!!", "")
return nil, rtnErr
newErr := fmt.Errorf("Invalid RegionCode!!")
cblogger.Error(newErr.Error())
return nil, newErr
}

if strings.EqualFold(regionZoneHandler.CredentialInfo.ClientId, "") {
newErr := fmt.Errorf("Invalid ClientId!!")
cblogger.Error(newErr.Error())
return nil, newErr
}

if strings.EqualFold(regionZoneHandler.CredentialInfo.ClientSecret, "") {
newErr := fmt.Errorf("Invalid ClientSecret!!")
cblogger.Error(newErr.Error())
return nil, newErr
}

var zoneList []ktsdk.Zone
Expand All @@ -258,8 +282,9 @@ func (regionZoneHandler KtCloudRegionZoneHandler) getKtZoneList(regionCode strin
// ZONE info. inquiry with at least one 'VM' : false
response, err := cs.ListZones(true, "", "", "")
if err != nil {
rtnErr := logAndReturnError(callLogInfo, "Failed to Get Available Zone List :", err)
return nil, rtnErr
newErr := fmt.Errorf("Failed to Get Available Zone List : [%v]", err)
cblogger.Error(newErr.Error())
return nil, newErr
}

for _, zone := range response.Listzonesresponse.Zone {
Expand Down

0 comments on commit e9f4f09

Please sign in to comment.