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

az cli client cleanup #434

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

davidgamero
Copy link
Collaborator

@davidgamero davidgamero commented Nov 22, 2024

  • move az cli methods to within the azClient
  • consume CommandRunner for az cli
  • update Ensure/Validation for AzCLI to methods that return errors so we can consume and test them directly via fakeCommandRunners
  • revert contributor role to allow acr build and push for github action

@davidgamero davidgamero marked this pull request as ready for review November 22, 2024 03:34
@@ -34,7 +34,6 @@ application and service principle, and will configure that application to trust
ctx := cmd.Context()

gh := providers.NewGhClient()
providers.EnsureAzCli()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

moved this to inside the az client constructor

var _ CommandRunner = &DefaultCommandRunner{}

func (d *DefaultCommandRunner) RunCommand(args ...string) (string, error) {
log.Debug("Running command: ", args)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

add debug log here to allow tracing command executions while debugging

@@ -10,10 +10,6 @@ deployVariables:
value: "testapp"
- name: "IMAGENAME"
Copy link
Collaborator Author

@davidgamero davidgamero Nov 23, 2024

Choose a reason for hiding this comment

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

we should rework the integration test generation to no longer be a big bash script and maybe leverage go natively. then we can integrate better defaults per-language

@Tatsinnit Tatsinnit added the enhancement New feature or request label Nov 25, 2024
@@ -141,28 +142,10 @@ func NoBlankStringValidator(s string) error {

// Validator for App name
func appNameValidator(name string) error {
if name == "" {
return fmt.Errorf("application name cannot be empty")
errors := validation.IsDNS1123Label(name)
Copy link
Member

Choose a reason for hiding this comment

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

💡 Note only please for archive sake: IsDNS1123Label tests for a string that conforms to the definition of a label in DNS (RFC 1123).

Copy link
Member

@Tatsinnit Tatsinnit left a comment

Choose a reason for hiding this comment

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

👍 Thank you so much for this and for the ping, added small notes, I think there is more history to this PR, so added few more folks, but looks good to me and surely these changes will get tested just to be sane before release.

for _, r := range name {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '-' || r == '_' || r == '.' {
if unicode.IsLetter(r) || unicode.IsDigit(r) || r == '-' || r == '.' {
Copy link
Member

Choose a reason for hiding this comment

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

💡 Suggestions only please:

validChars := unicode.IsLetter(r) || unicode.IsDigit(r) || strings.ContainsRune("-.", r)
if validChars {
    builder.WriteRune(r)
}

if err != nil {
log.Fatalf("Error validating az cli installation: %s", err.Error())
}
az.EnsureAzCliLoggedIn()
Copy link
Member

Choose a reason for hiding this comment

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

💡 Possible suggestion:

func (az *AzClient) EnsureAzCli() error {
	if err := az.ValidateAzCliInstalled(); err != nil {
		return fmt.Errorf("failed to validate az CLI installation: %w", err)
	}
	
	if err := az.EnsureAzCliLoggedIn(); err != nil {
		return fmt.Errorf("failed to ensure az CLI login: %w", err)
	}

	return nil
}

}
log.Debug("Service principal created successfully!")
Copy link
Member

Choose a reason for hiding this comment

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

💡 Suggestion only please: Use case suggestion: since we create SP for the user, I hope we have agreement from user and informed them about the age of SP and reason it was created and how user can destruct if need be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants