Skip to content

Commit

Permalink
fix: Run linter (#42)
Browse files Browse the repository at this point in the history
# Description

Run the linter & address all flagged issues.
  • Loading branch information
haleemur authored Aug 28, 2024
1 parent 7ecea7d commit 1021edd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 12 additions & 13 deletions tap_snowflake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@

from __future__ import annotations

import datetime
import os
from dataclasses import dataclass
from enum import Enum, auto
from functools import cached_property
from pathlib import Path
from typing import Any, Iterable, List, Tuple
from uuid import uuid4
import datetime

import singer_sdk.helpers._typing
import sqlalchemy
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import serialization
import sqlalchemy
from singer_sdk import SQLConnector, SQLStream, metrics
from singer_sdk.exceptions import ConfigValidationError
from singer_sdk.helpers._batch import BaseBatchFileEncoding, BatchConfig
from singer_sdk.streams.core import REPLICATION_FULL_TABLE, REPLICATION_INCREMENTAL
from singer_sdk.exceptions import ConfigValidationError
import singer_sdk.helpers._typing
from snowflake.sqlalchemy import URL
from sqlalchemy.sql import text

Expand All @@ -32,12 +33,15 @@ def patched_conform(
property_schema: dict,
) -> Any:
"""Overrides Singer SDK type conformance to prevent dates turning into datetimes.
Converts a primitive (i.e. not object or array) to a json compatible type.
Returns:
The appropriate json compatible type.
"""
if isinstance(elem, datetime.date):
return elem.isoformat()

return unpatched_conform(elem=elem, property_schema=property_schema)


Expand Down Expand Up @@ -79,7 +83,6 @@ class SnowflakeConnector(SQLConnector):

def get_private_key(self):
"""Get private key from the right location."""

try:
encoded_passphrase = self.config["private_key_passphrase"].encode()
except KeyError:
Expand All @@ -103,12 +106,7 @@ def get_private_key(self):

@cached_property
def auth_method(self):
"""
Validate & return the authentication method based on config.
Cache computed auth_method to attribute `_auth_method`.
"""

"""Validate & return the authentication method based on config."""
valid_auth_methods = {"private_key", "private_key_path", "password"}
config_auth_methods = [x for x in self.config if x in valid_auth_methods]
if len(config_auth_methods) != 1:
Expand All @@ -118,7 +116,6 @@ def auth_method(self):

def get_sqlalchemy_url(self, config: dict) -> str:
"""Concatenate a SQLAlchemy URL for use in connecting to the source."""

params = {
"account": config["account"],
"user": config["user"],
Expand Down Expand Up @@ -167,7 +164,9 @@ def discover_catalog_entries(self) -> list[dict]:
]
not_tables = not tables
table_schemas = {} if not_tables else set([x.split(".")[0] for x in tables])
table_schema_names = [x for x in schema_names if x in table_schemas] or schema_names
table_schema_names = [
x for x in schema_names if x in table_schemas
] or schema_names
for schema_name in table_schema_names:
# Iterate through each table and view of relevant schemas
for table_name, is_view in self.get_object_names(
Expand Down
27 changes: 21 additions & 6 deletions tap_snowflake/tap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from tap_snowflake.client import SnowflakeStream

SFLAKE_DOCS = "https://docs.snowflake.com/en/user-guide"


class TapSnowflake(SQLTap):
"""Snowflake tap class."""
Expand All @@ -25,20 +27,30 @@ class TapSnowflake(SQLTap):
th.StringType,
required=False,
secret=True,
description="The password for your Snowflake user. Either one of [`password`, `private_key`, `private_key_path`] is required.",
description=(
"The password for your Snowflake user. One of "
"[`password`, `private_key`, `private_key_path`] is required."
),
),
th.Property(
"private_key",
th.StringType,
required=False,
secret=True,
description="The private key is used to connect to snowflake. Either one of [`password`, `private_key`, `private_key_path`] is required.",
description=(
"The private key is used to connect to snowflake. One of "
"[`password`, `private_key`, `private_key_path`] is required."
),
),
th.Property(
"private_key_path",
th.StringType,
required=False,
description="Path to where the private key is stored. The private key is used to connect to snowflake. Either one of [`password`, `private_key`, `private_key_path`] is required.",
description=(
"Path to where the private key is stored. The private key is used "
"to connect to snowflake. One of [`password`, `private_key`, "
"`private_key_path`] is required."
),
),
th.Property(
"private_key_passphrase",
Expand All @@ -51,7 +63,10 @@ class TapSnowflake(SQLTap):
"account",
th.StringType,
required=True,
description="Your account identifier. See [Account Identifiers](https://docs.snowflake.com/en/user-guide/admin-account-identifier.html).", # noqa: E501
description=(
"Your account identifier. See [Account Identifiers]"
f"({SFLAKE_DOCS}/admin-account-identifier.html)."
),
),
th.Property(
"database",
Expand Down Expand Up @@ -81,8 +96,8 @@ class TapSnowflake(SQLTap):
"should be fully qualified, including schema and table name. "
"NOTE: this limits discovery to the tables specified, for performance "
"reasons. Do not specify `tables` if you intend to discover the entire "
"available catalog. See readme for more details on the tables configuration "
"parameter."
"available catalog. See readme for more details on the tables "
"configuration parameter."
),
),
).to_dict()
Expand Down

0 comments on commit 1021edd

Please sign in to comment.