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

feat(cli): add lacework generate cloud-account oci subcommand #1359

Merged
merged 14 commits into from
Sep 4, 2023
Merged
17 changes: 17 additions & 0 deletions cli/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"net/mail"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -44,9 +45,11 @@ func init() {
initGenerateAwsTfCommandFlags()
initGenerateGcpTfCommandFlags()
initGenerateAzureTfCommandFlags()
initGenerateOciTfCommandFlags()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
initGenerateOciTfCommandFlags()

Can you remove this. These lines are deprecated and will be removed in future. This is the old location for these commands lacework cloud-account iac-generate aws etc.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooo what's the new location @jon-stewart

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

iacGenerateTfCommand.AddCommand(generateAwsTfCommand)
iacGenerateTfCommand.AddCommand(generateGcpTfCommand)
iacGenerateTfCommand.AddCommand(generateAzureTfCommand)
iacGenerateTfCommand.AddCommand(generateOciTfCommand)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
iacGenerateTfCommand.AddCommand(generateOciTfCommand)

Deprecated

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!


// aws subcommands
generateAwsTfCommand.AddCommand(generateAwsControlTowerTfCommand)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you do a favour and move this line to generate_cloud_account.go:init.

@dmurray-lacework to double check this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Expand Down Expand Up @@ -252,6 +255,20 @@ func validateStringWithRegex(val interface{}, regex string, errorString string)
return nil
}

func validateEmailAddress(val interface{}) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you move this into the internal libs, not sure if there is a suitable existing file. This code could be used in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea, will do!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

switch value := val.(type) {
case string:
// This validates the email format against RFC 5322
_, err := mail.ParseAddress(value)
kolbeinn marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return errors.Wrap(err, "supplied email address is not a valid email address format")
}
default:
return errors.New("value must be a string")
}
return nil
}

// Used to test if path supplied for output exists
func validPathExists(val interface{}) error {
switch value := val.(type) {
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/generate_cloud_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ func init() {
// initGenerateAwsTfCommandFlags()
// initGenerateGcpTfCommandFlags()
// initGenerateAzureTfCommandFlags()
// initGenerateOciTfCommandFlags()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// initGenerateOciTfCommandFlags()
initGenerateOciTfCommandFlags()

Setup flags here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


generateCloudAccountCommand.AddCommand(generateAwsTfCommand)
generateCloudAccountCommand.AddCommand(generateGcpTfCommand)
generateCloudAccountCommand.AddCommand(generateAzureTfCommand)
generateCloudAccountCommand.AddCommand(generateOciTfCommand)
}
Loading