Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes GEN 2 cloudfunctions function not getting listed #568

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion gcp/service.go
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
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
}