Skip to content

Commit

Permalink
fix: updates for go modules (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody authored Feb 16, 2024
1 parent f9b6039 commit ff0be2f
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 18 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/go-lint.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: go-lint
on:
pull_request:
branches:
- master
paths:
- ".github/workflows/go-lint.yaml"
- "modules/project_cleanup/function_source/**"
permissions:
contents: read

concurrency:
group: '$${{ github.workflow }}-$${{ github.head_ref || github.ref }}'
cancel-in-progress: true

jobs:
golangci:
name: ${{ matrix.folder }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
folder: [modules/project_cleanup/function_source]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version-file: ${{ matrix.folder }}/go.mod
cache-dependency-path: ${{ matrix.folder }}/go.sum
- name: golangci-lint
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3.7.0
with:
version: latest
working-directory: ${{ matrix.folder }}
args: --timeout=5m
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ credentials.json
.vscode/
*.pyc
.kitchen
go.work.sum

examples/**/*.zip
examples/**/terraform.tfvars
Expand Down
6 changes: 6 additions & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.21

use (
./modules/project_cleanup/function_source
./test/integration
)
37 changes: 19 additions & 18 deletions modules/project_cleanup/function_source/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
cloudresourcemanager3 "google.golang.org/api/cloudresourcemanager/v3"
"google.golang.org/api/compute/v1"
"google.golang.org/api/googleapi"
"google.golang.org/api/option"
"google.golang.org/api/servicemanagement/v1"
)

Expand Down Expand Up @@ -241,57 +242,57 @@ func getCorrectOrganizationIdOrTerminateExecution() string {
return targetOrganizationIdString
}

func getServiceManagementServiceOrTerminateExecution(client *http.Client) *servicemanagement.APIService {
service, err := servicemanagement.New(client)
func getServiceManagementServiceOrTerminateExecution(ctx context.Context, client *http.Client) *servicemanagement.APIService {
service, err := servicemanagement.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
logger.Fatalf("Failed to get service management API client with error [%s], terminate execution", err.Error())
}
return service
}

func getResourceManagerServiceOrTerminateExecution(client *http.Client) *cloudresourcemanager.Service {
func getResourceManagerServiceOrTerminateExecution(ctx context.Context, client *http.Client) *cloudresourcemanager.Service {
logger.Println("Try to get Cloud Resource Manager")
cloudResourceManagerService, err := cloudresourcemanager.New(client)
cloudResourceManagerService, err := cloudresourcemanager.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
logger.Fatalf("Failed to get Cloud Resource Manager with error [%s], terminate execution", err.Error())
}
logger.Println("Got Cloud Resource Manager")
return cloudResourceManagerService
}

func getFolderServiceOrTerminateExecution(client *http.Client) *cloudresourcemanager2.FoldersService {
func getFolderServiceOrTerminateExecution(ctx context.Context, client *http.Client) *cloudresourcemanager2.FoldersService {
logger.Println("Try to get Folders Service")
cloudResourceManagerService, err := cloudresourcemanager2.New(client)
cloudResourceManagerService, err := cloudresourcemanager2.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
logger.Fatalf("Failed to get Folders Service with error [%s], terminate execution", err.Error())
}
logger.Println("Got Folders Service")
return cloudResourceManagerService.Folders
}

func getTagKeysServiceOrTerminateExecution(client *http.Client) *cloudresourcemanager3.TagKeysService {
func getTagKeysServiceOrTerminateExecution(ctx context.Context, client *http.Client) *cloudresourcemanager3.TagKeysService {
logger.Println("Try to get TagKeys Service")
cloudResourceManagerService, err := cloudresourcemanager3.New(client)
cloudResourceManagerService, err := cloudresourcemanager3.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
logger.Fatalf("Failed to get TagKeys Service with error [%s], terminate execution", err.Error())
}
logger.Println("Got TagKeys Service")
return cloudResourceManagerService.TagKeys
}

func getTagValuesServiceOrTerminateExecution(client *http.Client) *cloudresourcemanager3.TagValuesService {
func getTagValuesServiceOrTerminateExecution(ctx context.Context, client *http.Client) *cloudresourcemanager3.TagValuesService {
logger.Println("Try to get TagValues Service")
cloudResourceManagerService, err := cloudresourcemanager3.New(client)
cloudResourceManagerService, err := cloudresourcemanager3.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
logger.Fatalf("Failed to get TagValues Service with error [%s], terminate execution", err.Error())
}
logger.Println("Got TagValues Service")
return cloudResourceManagerService.TagValues
}

func getFirewallPoliciesServiceOrTerminateExecution(client *http.Client) *compute.FirewallPoliciesService {
func getFirewallPoliciesServiceOrTerminateExecution(ctx context.Context, client *http.Client) *compute.FirewallPoliciesService {
logger.Println("Try to get Firewall Policies Service")
computeService, err := compute.New(client)
computeService, err := compute.NewService(ctx, option.WithHTTPClient(client))
if err != nil {
logger.Fatalf("Failed to get Firewall Policies Service with error [%s], terminate execution", err.Error())
}
Expand All @@ -311,12 +312,12 @@ func initializeGoogleClient(ctx context.Context) *http.Client {

func invoke(ctx context.Context) {
client := initializeGoogleClient(ctx)
cloudResourceManagerService := getResourceManagerServiceOrTerminateExecution(client)
folderService := getFolderServiceOrTerminateExecution(client)
tagKeyService := getTagKeysServiceOrTerminateExecution(client)
tagValuesService := getTagValuesServiceOrTerminateExecution(client)
firewallPoliciesService := getFirewallPoliciesServiceOrTerminateExecution(client)
endpointService := getServiceManagementServiceOrTerminateExecution(client)
cloudResourceManagerService := getResourceManagerServiceOrTerminateExecution(ctx, client)
folderService := getFolderServiceOrTerminateExecution(ctx, client)
tagKeyService := getTagKeysServiceOrTerminateExecution(ctx, client)
tagValuesService := getTagValuesServiceOrTerminateExecution(ctx, client)
firewallPoliciesService := getFirewallPoliciesServiceOrTerminateExecution(ctx, client)
endpointService := getServiceManagementServiceOrTerminateExecution(ctx, client)

removeLien := func(name string) {
logger.Printf("Try to remove lien [%s]", name)
Expand Down

0 comments on commit ff0be2f

Please sign in to comment.