Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-pczajka committed Mar 8, 2024
1 parent fa6fb1c commit 55cfc60
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/snowflake/cli/api/sql_execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/snowflake/cli/plugins/git/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,17 @@ 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?")
if use_existing_api:
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.")
Expand Down
11 changes: 1 addition & 10 deletions src/snowflake/cli/plugins/git/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down

0 comments on commit 55cfc60

Please sign in to comment.