Skip to content

Commit

Permalink
Merge pull request #339 from DalgoT4D/336-enable-snowflake-as-a-desti…
Browse files Browse the repository at this point in the history
…nation

336 enable snowflake as a destination
  • Loading branch information
Ishankoradia authored Sep 27, 2023
2 parents 3b352c5 + fc6a3ad commit e8de331
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
10 changes: 10 additions & 0 deletions ddpui/api/client/airbyte_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,16 @@ def put_airbyte_destination(

elif warehouse.wtype == "bigquery":
dbt_credentials = json.loads(payload.config["credentials_json"])
elif warehouse.wtype == "snowflake":
if (
"credentials" in payload.config
and "password" in payload.config["credentials"]
and isinstance(payload.config["credentials"]["password"], str)
and len(payload.config["credentials"]["password"]) > 0
and list(set(payload.config["credentials"]["password"])) != "*"
):
dbt_credentials["credentials"]["password"] = payload.config["credentials"]["password"]

else:
raise HttpError(400, "unknown warehouse type " + warehouse.wtype)

Expand Down
12 changes: 11 additions & 1 deletion ddpui/api/client/user_org_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def post_organization(request, payload: OrgSchema):
def post_organization_warehouse(request, payload: OrgWarehouseSchema):
"""registers a data warehouse for the org"""
orguser: OrgUser = request.orguser
if payload.wtype not in ["postgres", "bigquery"]:
if payload.wtype not in ["postgres", "bigquery", "snowflake"]:
raise HttpError(400, "unrecognized warehouse type " + payload.wtype)

destination = airbyte_service.create_destination(
Expand All @@ -397,6 +397,16 @@ def post_organization_warehouse(request, payload: OrgWarehouseSchema):

elif payload.wtype == "bigquery":
dbt_credentials = json.loads(payload.airbyteConfig["credentials_json"])
elif payload.wtype == "snowflake":
dbt_credentials = {
"host": payload.airbyteConfig["host"],
"role": payload.airbyteConfig["role"],
"warehouse": payload.airbyteConfig["warehouse"],
"database": payload.airbyteConfig["database"],
"schema": payload.airbyteConfig["schema"],
"username": payload.airbyteConfig["username"],
"credentials": payload.airbyteConfig["credentials"],
}

warehouse = OrgWarehouse(
org=orguser.org,
Expand Down
2 changes: 1 addition & 1 deletion ddpui/models/org.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OrgSchema(Schema):
class OrgWarehouse(models.Model):
"""A data warehouse for an org. Typically we expect exactly one"""

wtype = models.CharField(max_length=25) # postgres, bigquery
wtype = models.CharField(max_length=25) # postgres, bigquery, snowflake
name = models.CharField(max_length=25, default="", blank=True)
credentials = models.CharField(max_length=200)
org = models.ForeignKey(Org, on_delete=models.CASCADE)
Expand Down
5 changes: 4 additions & 1 deletion ddpui/models/org_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from ninja import Schema
from pydantic import SecretStr

from ddpui.models.org import Org, OrgSchema
from ddpui.models.org import Org, OrgSchema, OrgWarehouse


class UserAttributes(models.Model):
Expand Down Expand Up @@ -88,16 +88,19 @@ class OrgUserResponse(Schema):
active: bool
role: int
role_slug: str
wtype: str | None

@staticmethod
def from_orguser(orguser: OrgUser):
"""helper to turn an OrgUser into an OrgUserResponse"""
warehouse = OrgWarehouse.objects.filter(org=orguser.org).first()
return OrgUserResponse(
email=orguser.user.email,
org=orguser.org,
active=orguser.user.is_active,
role=orguser.role,
role_slug=slugify(OrgUserRole(orguser.role).name),
wtype=warehouse.wtype if warehouse else None,
)


Expand Down

0 comments on commit e8de331

Please sign in to comment.