-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:
--initialize
command to onboard a new account (#80)
Closes #21 This is kind of a new idea that we talked about in office hours a while back for leveraging the target's capabilities to configure the database. Related to meltano/hub#1407. Adds a CLI flag for initializing a new account. It interactively prompts for all the information it needs and will execute it if you want it to, otherwise it will just print the sql and you can run it yourself. Based on https://fivetran.com/docs/destinations/snowflake/setup-guide. I created a personal trial snowflake account and was able to initialize using this script then immediately run a tap using the new user/role/warehouse/database. --------- Co-authored-by: Edgar R. M <[email protected]>
- Loading branch information
1 parent
34b7849
commit c45a206
Showing
4 changed files
with
181 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import click | ||
from target_snowflake.connector import SnowflakeConnector | ||
import sys | ||
from sqlalchemy import text | ||
|
||
|
||
def initializer(): | ||
click.echo("") | ||
click.echo("") | ||
click.echo("✨Initializing Snowflake account.✨") | ||
click.echo("Note: You will always be asked to confirm before anything is executed.") | ||
click.echo("") | ||
click.echo("Additionally you can run in `dry_run` mode which will print the SQL without running it.") | ||
dry_run = click.prompt("Would you like to run in `dry_run` mode?", default=False, type=bool) | ||
click.echo("") | ||
click.echo("We will now interactively create (or the print queries) for all the following objects in your Snowflake account:") | ||
click.echo(" - Role") | ||
click.echo(" - User") | ||
click.echo(" - Warehouse") | ||
click.echo(" - Database") | ||
click.echo("") | ||
role = click.prompt("Meltano Role Name:", type=str, default="MELTANO_ROLE") | ||
user = click.prompt("Meltano User Name:", type=str, default="MELTANO_USER") | ||
password = click.prompt("Meltano Password", type=str, confirmation_prompt=True) | ||
warehouse = click.prompt("Meltano Warehouse Name", type=str, default="MELTANO_WAREHOUSE") | ||
database = click.prompt("Meltano Database Name", type=str, default="MELTANO_DATABASE") | ||
script = SnowflakeConnector.get_initialize_script(role, user, password, warehouse, database) | ||
if dry_run: | ||
click.echo(script) | ||
sys.exit(0) | ||
else: | ||
account = click.prompt("Account (i.e. lqnwlrc-onb17812)", type=str) | ||
admin_user = click.prompt("User w/SYSADMIN access", type=str) | ||
admin_pass = click.prompt("User Password", type=str) | ||
connector = SnowflakeConnector( | ||
{ | ||
"account": account, | ||
"database": "SNOWFLAKE", | ||
"password": admin_pass, | ||
"role": "SYSADMIN", | ||
"user": admin_user, | ||
} | ||
) | ||
connector | ||
try: | ||
click.echo("Initialization Started") | ||
with connector._connect() as conn: | ||
click.echo(f"Executing:") | ||
click.echo(f"{script}") | ||
click.prompt("Confirm?", default=True, type=bool) | ||
click.echo("Initialization Started...") | ||
for statement in script.split(';'): | ||
if len(statement.strip()) > 0: | ||
conn.execute( | ||
text(statement) | ||
) | ||
click.echo("Success!") | ||
click.echo("Initialization Complete") | ||
except Exception as e: | ||
click.echo(f"Initialization Failed: {e}") | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters