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

Snow 1181759 git setup #880

Merged
merged 14 commits into from
Mar 11, 2024
Merged

Conversation

sfc-gh-pczajka
Copy link
Contributor

@sfc-gh-pczajka sfc-gh-pczajka commented Mar 8, 2024

Pre-review checklist

  • I've confirmed that instructions included in README.md are still correct after my changes in the codebase.
  • I've added or updated automated unit tests to verify correctness of my new code.
  • I've added or updated integration tests to verify correctness of my new code.
  • I've confirmed that my changes are working by executing CLI's commands manually.
  • I've confirmed that my changes are up-to-date with the target branch.
  • I've described my changes in the release notes.
  • I've described my changes in the section below.

Changes description

Add snow git setup command, which creates git repository and creates all necessary objects.


manager = GitManager()

def _assure_repository_does_not_exist() -> None:
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to move those functions outside the command, it will increase readability

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

Comment on lines 78 to 93
secret_needed = typer.confirm("Use secret for authentication?")
if not secret_needed:
return None

use_existing_secret = typer.confirm("Use existing secret?")
if use_existing_secret:
existing_secret = typer.prompt("Secret identifier")
return existing_secret

cli_console.step("Creating new secret")
secret_name = f"{repository_name}_secret"
username = typer.prompt("username")
password = typer.prompt("password/token", hide_input=True)
manager.create_secret(username=username, password=password, name=secret_name)
cli_console.step(f"Secret '{secret_name}' successfully created")
return secret_name
Copy link
Contributor

Choose a reason for hiding this comment

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

Inline the prompts and confirm into command. It will be easier to follow the command flow. Currently I find it pretty hard to grasp

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

Comment on lines 36 to 45
def create_secret(self, name: str, username: str, password: str) -> SnowflakeCursor:
query = (
f"create secret {name}"
f" type = password"
f" username = '{username}'"
f" password = '{password}'"
)
return self._execute_query(query)

def create_api_integration(
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to SQLMixin as those are not specific to git repo

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. I renamed create_secret -> create_password_secret as different secret types have different arguments

_assure_repository_does_not_exist(repository_name)
manager = GitManager()

url = typer.prompt("Origin url")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we validate if not empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In that case typer asks again:

▶ snow git setup repo
Origin url: 
Origin url:  
Origin url: 
Origin url: 

I was considering validating whether it starts with https://, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 for at least https validation

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

secret = f"{repository_name}_secret"
username = typer.prompt("username")
password = typer.prompt("password/token", hide_input=True)
manager.create_password_secret(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would move object creation to the end, in this way there's a clear separation of "prompts" and "actions" WDYT?

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

Comment on lines 25 to 29
query = (
f"create git repository {repo_name}"
f" api_integration = {api_integration}"
f" origin = '{url}'"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use multiline string, it makes things a bit more readable

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

Comment on lines +98 to +100
cli_console.step(f"Using existing secret '{secret_name}'")
else:
cli_console.step(f"Secret '{secret_name}' will be created")
Copy link
Contributor

Choose a reason for hiding this comment

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

Personally I would hide this information. If secrets exists - just continue. If it does not exists - ask for required value. WDYT?

@sfc-gh-pczajka sfc-gh-pczajka merged commit 71e8619 into git-repository Mar 11, 2024
17 checks passed
@sfc-gh-pczajka sfc-gh-pczajka deleted the SNOW-1181759-git-setup branch March 11, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants