44 "encoding/json"
55 "errors"
66 "fmt"
7- "os"
87 "strconv"
98 "strings"
109
@@ -67,7 +66,7 @@ func (priceInfoHandler *AwsPriceInfoHandler) ListProductFamily(regionName string
6766 return result , nil
6867}
6968
70- func (priceInfoHandler * AwsPriceInfoHandler ) GetPriceInfo (productFamily string , regionName string , filterList []irs.KeyValue ) (string , error ) {
69+ func (priceInfoHandler * AwsPriceInfoHandler ) GetPriceInfo (productFamily string , regionName string , filterList []irs.KeyValue , simpleVMSpecInfo bool ) (string , error ) {
7170 currentRegion := regionName
7271 if currentRegion == "" {
7372 currentRegion = priceInfoHandler .Region .Region
@@ -166,7 +165,7 @@ func (priceInfoHandler *AwsPriceInfoHandler) GetPriceInfo(productFamily string,
166165 if productFamilyVal != "Compute Instance" && productFamilyVal != "Compute Instance (bare metal)" {
167166 continue
168167 }
169- productInfo , err := ExtractProductInfo (awsPrice , productFamilyVal )
168+ productInfo , err := ExtractProductInfo (awsPrice , productFamilyVal , simpleVMSpecInfo )
170169 if err != nil {
171170 cblogger .Error (err )
172171 continue
@@ -402,7 +401,7 @@ func setProductsInputRequestFilter(filterList []irs.KeyValue) ([]*pricing.Filter
402401 return requestFilters , nil
403402}
404403
405- func ExtractProductInfo (jsonValue aws.JSONValue , productFamily string ) (irs.ProductInfo , error ) {
404+ func ExtractProductInfo (jsonValue aws.JSONValue , productFamily string , simpleVMSpecInfo bool ) (irs.ProductInfo , error ) {
406405 var productInfo irs.ProductInfo
407406
408407 jsonString , err := json .MarshalIndent (jsonValue ["product" ].(map [string ]interface {})["attributes" ], "" , " " )
@@ -412,7 +411,7 @@ func ExtractProductInfo(jsonValue aws.JSONValue, productFamily string) (irs.Prod
412411 }
413412 switch productFamily {
414413 case "Compute Instance" , "Compute Instance (bare metal)" :
415- err := setVMspecInfo (& productInfo , string (jsonString ))
414+ err := setVMspecInfo (& productInfo , string (jsonString ), simpleVMSpecInfo )
416415 if err != nil {
417416 return productInfo , err
418417 }
@@ -438,7 +437,7 @@ func ExtractProductInfo(jsonValue aws.JSONValue, productFamily string) (irs.Prod
438437 return productInfo , nil
439438}
440439
441- func setVMspecInfo (productInfo * resources.ProductInfo , jsonValueString string ) error {
440+ func setVMspecInfo (productInfo * resources.ProductInfo , jsonValueString string , simpleVMSpecInfo bool ) error {
442441 var jsonData map [string ]string
443442 if err := json .Unmarshal ([]byte (jsonValueString ), & jsonData ); err != nil {
444443 return fmt .Errorf ("failed to parse JSON: %w" , err )
@@ -449,9 +448,7 @@ func setVMspecInfo(productInfo *resources.ProductInfo, jsonValueString string) e
449448 return errors .New ("missing required field: instanceType" )
450449 }
451450
452- simpleMode := strings .ToUpper (os .Getenv ("VMSPECINFO_SIMPLE_MODE_IN_PRICEINFO" )) == "ON"
453-
454- if simpleMode {
451+ if simpleVMSpecInfo {
455452 productInfo .VMSpecName = instanceType
456453 return nil
457454 }
0 commit comments