Просмотр исходного кода

pull region out of region url

Signed-off-by: nickcurie <nick.curie64@gmail.com>
nickcurie 3 лет назад
Родитель
Сommit
a219dc9597
1 измененных файлов с 15 добавлено и 2 удалено
  1. 15 2
      pkg/cloud/gcpprovider.go

+ 15 - 2
pkg/cloud/gcpprovider.go

@@ -7,6 +7,7 @@ import (
 	"math"
 	"net/http"
 	"os"
+	"path"
 	"regexp"
 	"strconv"
 	"strings"
@@ -475,9 +476,15 @@ func (gcp *GCP) GetOrphanedResources() ([]OrphanedResource, error) {
 					return nil, fmt.Errorf("error converting string to map: %s", err)
 				}
 
+				// Converts https://www.googleapis.com/compute/v1/projects/xxxxx/zones/us-central1-c to us-central1-c
+				zone := path.Base(disk.Zone)
+				if zone == "." {
+					zone = ""
+				}
+
 				or := OrphanedResource{
 					Kind:        "disk",
-					Region:      disk.Zone,
+					Region:      zone,
 					Description: desc,
 					Size:        &disk.SizeGb,
 					DiskName:    disk.Name,
@@ -499,9 +506,15 @@ func (gcp *GCP) GetOrphanedResources() ([]OrphanedResource, error) {
 				//todo: use GCP pricing
 				cost := GCPHourlyPublicIPCost * timeutil.HoursPerMonth
 
+				// Converts https://www.googleapis.com/compute/v1/projects/xxxxx/regions/us-central1 to us-central1
+				region := path.Base(address.Region)
+				if region == "." {
+					region = ""
+				}
+
 				or := OrphanedResource{
 					Kind:   "address",
-					Region: address.Region,
+					Region: region,
 					Description: map[string]string{
 						"type": address.AddressType,
 					},