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-1833500] New command: snow helpers import-snowsql-connections #1956

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

Conversation

sfc-gh-pjob
Copy link
Contributor

@sfc-gh-pjob sfc-gh-pjob commented Dec 18, 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 on MacOS.
  • I've confirmed that my changes are working by executing CLI's commands manually on Windows.
  • 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

  • Added new command: snow helpers import-snowsql-connections
    • It allows to import connections from SnowSQL config files.

@sfc-gh-pjob sfc-gh-pjob marked this pull request as ready for review December 19, 2024 16:50
@sfc-gh-pjob sfc-gh-pjob requested review from a team as code owners December 19, 2024 16:50
@sfc-gh-pjob sfc-gh-pjob changed the title [SNOW-1833500] New hidden command: snow helpers import-snowsql-connections [SNOW-1833500] New command: snow helpers import-snowsql-connections Dec 19, 2024
Comment on lines +182 to +186
log.debug(
"Reading SnowSQL's connection configuration [%s] from [%s]",
snowsql_connection_section_name,
str(file.path),
)
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 consider cli_console.step instead of debug. Imo showing users what is being read what is happening may be helpful in case of this command.

Comment on lines +220 to +222
raise ClickException(
f"Default connection name [{default_cli_connection_name}] conflicts with the name of one of connections from SnowSQL. Please specify a different name for your default connection."
)
Copy link
Contributor

@sfc-gh-turbaszek sfc-gh-turbaszek Jan 8, 2025

Choose a reason for hiding this comment

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

How about making this command more interactive? We error in case of connection/default names. In both cases we can prompt for user action instead of failing and requiring them to do some manual steps

Connection 'foo' exists in both configuration files, do you want to use SnowSQL definition? [y/N]

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea. I'd also consider --no-interactive or --skip-conflicting-connections so user can choose not to be prompted, but this might wait until someone actually requests it.

Comment on lines +232 to +240
key_names_replacements = {
"accountname": "account",
"username": "user",
"databasename": "database",
"dbname": "database",
"schemaname": "schema",
"warehousename": "warehouse",
"rolename": "role",
"private_key_path": "private_key_file",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this full list of options?


def parse_value(value: Any):
try:
parsed_value = literal_eval(value)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need eval?

custom_snowsql_config_files: Optional[List[Path]] = typer.Option(
None,
"--snowsql-config-file",
help="Specifies file paths to SnowSQL configuration. The option can be used multiple times to specify more than 1 file.",
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
help="Specifies file paths to SnowSQL configuration. The option can be used multiple times to specify more than 1 file.",
help="Specifies file paths to custom SnowSQL configuration. The option can be used multiple times to specify more than 1 file.",

At first I thought that you need to provide default locations by hand :D

imported_named_conenction = _convert_connection_from_snowsql_config_section(
snowsql_named_connection
)
if connection_name in imported_named_connections:
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't we raise / prompt if connection is defined twice instead of overriding (or at least log console.step(connection redefined in X, overriding))

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.

3 participants