Skip to content

Commit

Permalink
fixes GEN 2 cloudfunctions function not getting listed (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshmore658 committed May 2, 2024
1 parent 89d7599 commit 1648ae5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion gcp/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"google.golang.org/api/billingbudgets/v1"
"google.golang.org/api/cloudasset/v1"
"google.golang.org/api/cloudbilling/v1"
"google.golang.org/api/cloudfunctions/v1"
"google.golang.org/api/cloudfunctions/v2"
"google.golang.org/api/cloudidentity/v1"
"google.golang.org/api/cloudkms/v1"
"google.golang.org/api/cloudresourcemanager/v1"
Expand Down
20 changes: 12 additions & 8 deletions gcp/table_gcp_cloudfunctions_function.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ import (
"github.com/turbot/steampipe-plugin-sdk/v5/grpc/proto"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin"
"github.com/turbot/steampipe-plugin-sdk/v5/plugin/transform"

"google.golang.org/api/cloudfunctions/v1"
"google.golang.org/api/cloudfunctions/v2"
)

func tableGcpCloudfunctionFunction(ctx context.Context) *plugin.Table {
Expand Down Expand Up @@ -131,7 +130,7 @@ func tableGcpCloudfunctionFunction(ctx context.Context) *plugin.Table {
},
{
Name: "source_upload_url",
Description: "The Google Cloud Storage signed URL used for source uploading, generated by google.cloud.functions.v1.GenerateUploadUrl",
Description: "The Google Cloud Storage signed URL used for source uploading, generated by google.cloud.functions.v1/v2.GenerateUploadUrl",
Type: proto.ColumnType_STRING,
},
{
Expand Down Expand Up @@ -273,7 +272,7 @@ func getCloudFunction(ctx context.Context, d *plugin.QueryData, h *plugin.Hydrat
name := d.EqualsQuals["name"].GetStringValue()
location := d.EqualsQuals["location"].GetStringValue()

// API https://cloud.google.com/functions/docs/reference/rest/v1/projects.locations.functions/get
// API https://cloud.google.com/functions/docs/reference/rest/v2/projects.locations.functions/get
cloudFunction, err := service.Projects.Locations.Functions.Get("projects/" + project + "/locations/" + location + "/functions/" + name).Do()
if err != nil {
return nil, err
Expand All @@ -292,7 +291,7 @@ func getGcpCloudFunctionIamPolicy(ctx context.Context, d *plugin.QueryData, h *p
return nil, err
}

function := h.Item.(*cloudfunctions.CloudFunction)
function := h.Item.(*cloudfunctions.Function)

resp, err := service.Projects.Locations.Functions.GetIamPolicy(function.Name).Do()
if err != nil {
Expand All @@ -309,7 +308,7 @@ func getGcpCloudFunctionIamPolicy(ctx context.Context, d *plugin.QueryData, h *p
//// TRANSFORM FUNCTIONS

func gcpCloudFunctionTurbotData(_ context.Context, d *transform.TransformData) (interface{}, error) {
function := d.HydrateItem.(*cloudfunctions.CloudFunction)
function := d.HydrateItem.(*cloudfunctions.Function)
param := d.Param.(string)

project := strings.Split(function.Name, "/")[1]
Expand All @@ -332,8 +331,13 @@ func locationFromFunctionName(_ context.Context, d *transform.TransformData) (in
}

func cloudFunctionSelfLink(_ context.Context, d *transform.TransformData) (interface{}, error) {
data := d.HydrateItem.(*cloudfunctions.CloudFunction)
selfLink := "https://cloudfunctions.googleapis.com/v1/" + data.Name
cloudFunctionAttributeData := d.HydrateItem.(*cloudfunctions.Function)
var selfLink string
if cloudFunctionAttributeData.Environment == "GEN_1" {
selfLink = "https://cloudfunctions.googleapis.com/v1/" + cloudFunctionAttributeData.Name
} else {
selfLink = "https://cloudfunctions.googleapis.com/v2/" + cloudFunctionAttributeData.Name
}

return selfLink, nil
}

0 comments on commit 1648ae5

Please sign in to comment.