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

Merged

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I applied your suggestion and changed debug to console.step.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added prompts. At the moment I'm not adding --no-interactive and --skip-conflicting-connections flags.

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, I don't know.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suggest to use this list and extend it later if needed.


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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's only literal_eval and it's used as parser of values (to correct types) because using raw values would add them to CLI always as strings and CLI wouldn't be able to use such config. Reading everything as strings is the specific behaviour of configparser. At the beginning I wanted to use TOML parser to read SQL's config but SQL's config can contain strings without quotes (even example connection added after installation contains such strings) and they are not valid TOML values. So as the result I read everything as strings and try to parse literals to correct types before saving them in CLI.

@sfc-gh-pjob sfc-gh-pjob enabled auto-merge (squash) January 13, 2025 14:50
@sfc-gh-pjob sfc-gh-pjob merged commit 30e43a3 into main Jan 13, 2025
20 checks passed
@sfc-gh-pjob sfc-gh-pjob deleted the feature/SNOW-1833500-snowsql-config-migration-commands branch January 13, 2025 14:55
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