Skip to content

Commit

Permalink
remove sslmode
Browse files Browse the repository at this point in the history
  • Loading branch information
EDsCODE committed Jan 25, 2024
1 parent 12f6a3d commit 17fb483
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 40 deletions.
5 changes: 2 additions & 3 deletions frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1833,10 +1833,9 @@ const api = {
dbname: string,
user: string,
password: string,
schema: string,
sslmode: string
schema: string
): Promise<ExternalDataPostgresSchema[]> {
const queryParams = toParams({ host, port, dbname, user, password, schema, sslmode })
const queryParams = toParams({ host, port, dbname, user, password, schema })

return await new ApiRequest()
.externalDataSources()
Expand Down
12 changes: 7 additions & 5 deletions frontend/src/scenes/data-warehouse/external/SourceModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,13 @@ function FirstStep(): JSX.Element {
}
if (config.name === 'Hubspot') {
return (
<Link to={addToHubspotButtonUrl() || ''}>
<LemonButton className="w-full" center type="secondary">
<img src={hubspotLogo} alt="hubspot logo" height={45} />
</LemonButton>
</Link>
<div className="w-full">
<Link to={addToHubspotButtonUrl() || ''}>
<LemonButton className="w-full" center type="secondary">
<img src={hubspotLogo} alt="hubspot logo" height={45} />
</LemonButton>
</Link>
</div>
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,29 +117,26 @@ export const sourceFormLogic = kea<sourceFormLogicType>([
user: '',
password: '',
schema: '',
sslmode: '',
},
},
errors: ({ payload: { host, port, dbname, user, password, schema, sslmode } }) => ({
errors: ({ payload: { host, port, dbname, user, password, schema } }) => ({
payload: {
host: !host && 'Please enter a host.',
port: !port && 'Please enter a port.',
dbname: !dbname && 'Please enter a dbname.',
user: !user && 'Please enter a user.',
password: !password && 'Please enter a password.',
schema: !schema && 'Please enter a schema.',
sslmode: !sslmode && 'Please enter a sslmode.',
},
}),
submit: async ({ payload: { host, port, dbname, user, password, schema, sslmode }, prefix }) => {
submit: async ({ payload: { host, port, dbname, user, password, schema }, prefix }) => {
const schemas = await api.externalDataSources.database_schema(
host,
port,
dbname,
user,
password,
schema,
sslmode
schema
)
actions.setDatabaseSchemas(schemas)

Expand All @@ -151,7 +148,6 @@ export const sourceFormLogic = kea<sourceFormLogicType>([
user,
password,
schema,
sslmode,
},
prefix,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,6 @@ export const SOURCE_DETAILS: Record<string, SourceConfig> = {
required: true,
placeholder: 'public',
},
{
name: 'sslmode',
label: 'SSL Mode',
type: 'text',
required: true,
placeholder: 'required',
},
],
},
}
Expand Down
7 changes: 3 additions & 4 deletions posthog/temporal/data_imports/external_data_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from posthog.temporal.common.logger import bind_temporal_worker_logger
from typing import Tuple
import asyncio
from django.conf import settings


@dataclasses.dataclass
Expand Down Expand Up @@ -56,10 +57,9 @@ async def create_external_data_job_model(inputs: CreateExternalDataJobInputs) ->
user = source.job_inputs.get("user")
password = source.job_inputs.get("password")
database = source.job_inputs.get("database")
sslmode = source.job_inputs.get("sslmode")
schema = source.job_inputs.get("schema")
schemas_to_sync = await sync_to_async(get_postgres_schemas)( # type: ignore
host, port, database, user, password, sslmode, schema
host, port, database, user, password, schema
)
else:
schemas_to_sync = list(PIPELINE_TYPE_SCHEMA_DEFAULT_MAPPING[source.source_type])
Expand Down Expand Up @@ -197,7 +197,6 @@ async def run_external_data_job(inputs: ExternalDataJobInputs) -> None:
user = model.pipeline.job_inputs.get("user")
password = model.pipeline.job_inputs.get("password")
database = model.pipeline.job_inputs.get("database")
sslmode = model.pipeline.job_inputs.get("sslmode")
schema = model.pipeline.job_inputs.get("schema")

source = postgres_source(
Expand All @@ -206,7 +205,7 @@ async def run_external_data_job(inputs: ExternalDataJobInputs) -> None:
user=user,
password=password,
database=database,
sslmode=sslmode,
sslmode="prefer" if settings.TEST else "require",
schema=schema,
table_names=inputs.schemas,
)
Expand Down
1 change: 0 additions & 1 deletion posthog/temporal/tests/test_external_data_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ async def setup_job_1():
"user": settings.PG_USER,
"password": settings.PG_PASSWORD,
"schema": "public",
"sslmode": "disable",
},
) # type: ignore

Expand Down
9 changes: 3 additions & 6 deletions posthog/warehouse/api/external_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ def _handle_postgres_source(self, request: Request, *args: Any, **kwargs: Any) -

user = payload.get("user")
password = payload.get("password")
sslmode = payload.get("sslmode")
schema = payload.get("schema")
table_names = payload.get("schemas")

Expand All @@ -249,7 +248,6 @@ def _handle_postgres_source(self, request: Request, *args: Any, **kwargs: Any) -
"database": database,
"user": user,
"password": password,
"sslmode": sslmode,
"schema": schema,
},
prefix=prefix,
Expand Down Expand Up @@ -328,13 +326,12 @@ def database_schema(self, request: Request, *arg: Any, **kwargs: Any):

user = request.query_params.get("user")
password = request.query_params.get("password")
sslmode = request.query_params.get("sslmode")
schema = request.query_params.get("schema")

if not host or not port or not database or not user or not password or not sslmode or not schema:
if not host or not port or not database or not user or not password or not schema:
return Response(
status=status.HTTP_400_BAD_REQUEST,
data={"message": "Missing required parameters: host, port, database, user, password, sslmode, schema"},
data={"message": "Missing required parameters: host, port, database, user, password, schema"},
)

# Validate internal postgres
Expand All @@ -344,7 +341,7 @@ def database_schema(self, request: Request, *arg: Any, **kwargs: Any):
data={"message": "Cannot use internal Postgres database"},
)

result = get_postgres_schemas(host, port, database, user, password, sslmode, schema)
result = get_postgres_schemas(host, port, database, user, password, schema)
result_mapped_to_options = [{"table": row, "should_sync": False} for row in result]
return Response(status=status.HTTP_200_OK, data=result_mapped_to_options)

Expand Down
5 changes: 0 additions & 5 deletions posthog/warehouse/api/test/test_external_data_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ def test_database_schema(self):
"database": settings.PG_DATABASE,
"user": settings.PG_USER,
"password": settings.PG_PASSWORD,
"sslmode": "disable",
"schema": "public",
},
)
Expand All @@ -175,7 +174,6 @@ def test_internal_postgres(self, patch_get_postgres_schemas):
"database": settings.PG_DATABASE,
"user": settings.PG_USER,
"password": settings.PG_PASSWORD,
"sslmode": "disable",
"schema": "public",
},
)
Expand All @@ -192,7 +190,6 @@ def test_internal_postgres(self, patch_get_postgres_schemas):
"database": settings.PG_DATABASE,
"user": settings.PG_USER,
"password": settings.PG_PASSWORD,
"sslmode": "disable",
"schema": "public",
},
)
Expand All @@ -209,7 +206,6 @@ def test_internal_postgres(self, patch_get_postgres_schemas):
"database": settings.PG_DATABASE,
"user": settings.PG_USER,
"password": settings.PG_PASSWORD,
"sslmode": "disable",
"schema": "public",
},
)
Expand All @@ -226,7 +222,6 @@ def test_internal_postgres(self, patch_get_postgres_schemas):
"database": settings.PG_DATABASE,
"user": settings.PG_USER,
"password": settings.PG_PASSWORD,
"sslmode": "disable",
"schema": "public",
},
)
Expand Down
5 changes: 3 additions & 2 deletions posthog/warehouse/models/external_data_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from posthog.models.utils import CreatedMetaFields, UUIDModel, sane_repr
import uuid
import psycopg
from django.conf import settings


class ExternalDataSchema(CreatedMetaFields, UUIDModel):
Expand Down Expand Up @@ -47,14 +48,14 @@ def sync_old_schemas_with_new_schemas(new_schemas: list, source_id: uuid.UUID, t
ExternalDataSchema.objects.create(name=schema, team_id=team_id, source_id=source_id, should_sync=False)


def get_postgres_schemas(host: str, port: str, database: str, user: str, password: str, sslmode: str, schema: str):
def get_postgres_schemas(host: str, port: str, database: str, user: str, password: str, schema: str):
connection = psycopg.Connection.connect(
host=host,
port=int(port),
dbname=database,
user=user,
password=password,
sslmode=sslmode,
sslmode="prefer" if settings.TEST else "require",
)

with connection.cursor() as cursor:
Expand Down

0 comments on commit 17fb483

Please sign in to comment.