-
Notifications
You must be signed in to change notification settings - Fork 47
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
Reworked Go func to del old projects #20
Reworked Go func to del old projects #20
Conversation
paulpalamarchuk
commented
Nov 1, 2019
•
edited by aaron-lane
Loading
edited by aaron-lane
- Fix Add infrastructure for cleaning up old test projects GoogleCloudPlatform/cloud-foundation-toolkit#400
f30cea8
to
54694ae
Compare
"fmt" | ||
"golang.org/x/net/context" | ||
"golang.org/x/oauth2/google" | ||
"google.golang.org/api/cloudresourcemanager/v1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix import ordering, custom packages should be below standard one
if err != nil { | ||
logger.Fatal(fmt.Sprintf("Could not convert %s to integer", maxAgeInHoursStr)) | ||
return err | ||
const LifecycleStateActiveRequested = "ACTIVE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
put in in one const() block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved
ageFilter := func(project *cloudresourcemanager.Project) bool { | ||
projectCreatedAt, err := time.Parse(time.RFC3339, project.CreateTime) | ||
if err != nil { | ||
logger.Println(fmt.Sprintf("Fail to parse CreateTime for [%s], skip it. Error [%s]", project.Name, err.Error())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use logger.Printf for formatting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
224aa71
to
538ab28
Compare
@paulpalamarchuk Is this ready for review? We need to get this done ASAP. |
logger.Println("Try to get Cloud Resource Manager") | ||
cloudResourceManagerService, err := cloudresourcemanager.New(client) | ||
if err != nil { | ||
logger.Println("Fail to get Cloud Resource Manager, terminate execution") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use https://golang.org/pkg/log/#Fatalf instead 2 lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
client, err := google.DefaultClient(ctx, cloudresourcemanager.CloudPlatformScope) | ||
if err != nil { | ||
logger.Println("Fail to initialize Google client, terminate execution") | ||
logger.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
cloudResourceManagerService, err := cloudresourcemanager2.New(client) | ||
if err != nil { | ||
logger.Println("Fail to get Folders Service, terminate execution") | ||
logger.Fatal(err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
removeProjectsInFolder(folderId) | ||
return nil | ||
}); err != nil { | ||
logger.Fatal(fmt.Sprintf("Fail to get subfolders for the forlder with id [%s], error [%s]", folderId, err.Error())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
538ab28
to
52d39d5
Compare
@morgante PR ready for review |
52d39d5
to
1592406
Compare
1592406
to
89e6494
Compare
|
||
variable "target_excluded_labels" { | ||
type = map(string) | ||
description = "Map of project lablels that won't be deleted." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description = "Map of project lablels that won't be deleted." | |
description = "Map of project labels that won't be deleted." |
|
||
variable "target_included_labels" { | ||
type = map(string) | ||
description = "Map of project lablels that will be deleted." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
description = "Map of project lablels that will be deleted." | |
description = "Map of project labels that will be deleted." |
@@ -1,115 +0,0 @@ | |||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't remove go.sum
.