From 55cfc60171cc76734d3e8b54a101cf9037ff9177 Mon Sep 17 00:00:00 2001 From: Patryk Czajka Date: Fri, 8 Mar 2024 12:19:32 +0100 Subject: [PATCH] review fixes --- src/snowflake/cli/api/sql_execution.py | 11 +++++++++++ src/snowflake/cli/plugins/git/commands.py | 6 ++++-- src/snowflake/cli/plugins/git/manager.py | 11 +---------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/snowflake/cli/api/sql_execution.py b/src/snowflake/cli/api/sql_execution.py index 3b2a04fcba..397fcf5538 100644 --- a/src/snowflake/cli/api/sql_execution.py +++ b/src/snowflake/cli/api/sql_execution.py @@ -82,6 +82,17 @@ def use_role(self, new_role: str): if is_different_role: self._execute_query(f"use role {prev_role}") + def create_password_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 _execute_schema_query(self, query: str, name: Optional[str] = None, **kwargs): """ Check that a database and schema are provided before executing the query. Useful for operating on schema level objects. diff --git a/src/snowflake/cli/plugins/git/commands.py b/src/snowflake/cli/plugins/git/commands.py index bfb1a62f89..285882f9aa 100644 --- a/src/snowflake/cli/plugins/git/commands.py +++ b/src/snowflake/cli/plugins/git/commands.py @@ -87,7 +87,9 @@ def setup( secret = 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) + manager.create_password_secret( + username=username, password=password, name=secret + ) cli_console.step(f"Secret '{secret}' successfully created") use_existing_api = typer.confirm("Use existing api integration?") @@ -95,7 +97,7 @@ def setup( api_integration = typer.prompt("API integration identifier") else: api_integration = f"{repository_name}_api_integration" - manager.create_api_integration( + manager.create_git_api_integration( name=api_integration, allowed_prefix=url, secret=secret ) cli_console.step(f"API integration '{api_integration}' successfully created.") diff --git a/src/snowflake/cli/plugins/git/manager.py b/src/snowflake/cli/plugins/git/manager.py index 11d0e580ff..b855f4c69f 100644 --- a/src/snowflake/cli/plugins/git/manager.py +++ b/src/snowflake/cli/plugins/git/manager.py @@ -33,16 +33,7 @@ def create( query += f" git_credentials = {secret}" return self._execute_query(query) - 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( + def create_git_api_integration( self, name: str, allowed_prefix: str, secret: Optional[str] ) -> SnowflakeCursor: query = (