Skip to content

Commit

Permalink
Merge pull request #1095 from MZC-CSC/feature_aws_filter_swy_240130
Browse files Browse the repository at this point in the history
AWS Matching the corresponding ProductFamily values
  • Loading branch information
powerkimhub authored Feb 26, 2024
2 parents df3bf37 + 535472e commit 4cb80c8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,55 @@ func ReplaceEmptyWithNA(obj interface{}) {
}
}
}

// ProductInfo 구조체의 Compute Instance 해당 값만 출력
func ReplaceEmptyWithNAforComputeInstance(obj interface{}) {
val := reflect.ValueOf(obj).Elem()
for _, fieldName := range []string{"InstanceType", "Vcpu", "Memory", "Storage", "Gpu", "GpuMemory", "OperatingSystem", "PreInstalledSw"} {
field := val.FieldByName(fieldName)
switch field.Kind() {
case reflect.String:
if field.String() == "" {
field.SetString("NA")
}
case reflect.Ptr:
if field.IsNil() {
// If the field is a pointer and is nil, set it to "NA"
field.Set(reflect.New(field.Type().Elem()))
field.Elem().SetString("NA")
}
}
}
}

// ProductInfo 구조체의 Storage 해당 값만 출력
func ReplaceEmptyWithNAforStorage(obj interface{}) {
val := reflect.ValueOf(obj).Elem()
for _, fieldName := range []string{"VolumeType", "StorageMedia", "MaxVolumeSize", "MaxIOPSVolume", "MaxThroughputVolume"} {
field := val.FieldByName(fieldName)
switch field.Kind() {
case reflect.String:
if field.String() == "" {
field.SetString("NA")
}
case reflect.Ptr:
if field.IsNil() {
// If the field is a pointer and is nil, set it to "NA"
field.Set(reflect.New(field.Type().Elem()))
field.Elem().SetString("NA")
}
}
}
}

// ProductInfo 구조체의 Load Balancer-Network 해당 값만 출력
func ReplaceEmptyWithNAforLoadBalancerNetwork(obj interface{}) {
val := reflect.ValueOf(obj).Elem()
for i := 0; i < val.NumField(); i++ {
field := val.Field(i)

if field.Kind() == reflect.String {
// 빈 문자열 필드 무시
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (priceInfoHandler *AwsPriceInfoHandler) GetPriceInfo(productFamily string,
cblogger.Info("get Products response", priceInfos)

for _, awsPrice := range priceInfos.PriceList {
productInfo, err := ExtractProductInfo(awsPrice)
productInfo, err := ExtractProductInfo(awsPrice, productFamily)

if err != nil {
cblogger.Error(err)
Expand Down Expand Up @@ -254,16 +254,25 @@ func (priceInfoHandler *AwsPriceInfoHandler) GetPriceInfo(productFamily string,
}

// 가져온 결과에서 product 추출
func ExtractProductInfo(jsonValue aws.JSONValue) (irs.ProductInfo, error) {
func ExtractProductInfo(jsonValue aws.JSONValue, productFamily string) (irs.ProductInfo, error) {
var productInfo irs.ProductInfo

jsonString, err := json.MarshalIndent(jsonValue["product"].(map[string]interface{})["attributes"], "", " ")
if err != nil {
cblogger.Error(err)
return productInfo, err
}
switch productFamily {
case "Compute Instance":
ReplaceEmptyWithNAforComputeInstance(&productInfo)
case "Storage":
ReplaceEmptyWithNAforStorage(&productInfo)
case "Load Balancer-Network":
ReplaceEmptyWithNAforLoadBalancerNetwork(&productInfo)
default:
ReplaceEmptyWithNA(&productInfo)
}

ReplaceEmptyWithNA(&productInfo)
err = json.Unmarshal(jsonString, &productInfo)
if err != nil {
cblogger.Error(err)
Expand Down

0 comments on commit 4cb80c8

Please sign in to comment.