Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add AB Protocol PG source & various python fixes (#610)
- Loading branch information
1 parent
238867d
commit d4b6ebc
Showing
30 changed files
with
610 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 8 additions & 5 deletions
13
airbyte-integrations/singer/exchangeratesapi/source/source_exchangeratesapi_singer/source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
secrets |
20 changes: 20 additions & 0 deletions
20
airbyte-integrations/singer/postgres_abprotocol/Dockerfile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM airbyte/integration-base-singer:dev | ||
|
||
RUN apt-get update && apt-get install -y \ | ||
jq libpq-dev gcc\ | ||
&& rm -rf /var/lib/apt/lists/* | ||
|
||
ENV CODE_PATH="postgres_singer_source" | ||
ENV AIRBYTE_IMPL_MODULE="postgres_singer_source" | ||
ENV AIRBYTE_IMPL_PATH="PostgresSingerSource" | ||
|
||
LABEL io.airbyte.version=0.1.0 | ||
LABEL io.airbyte.name=airbyte/postgres-singer-source-abprotocol | ||
|
||
WORKDIR /airbyte/integration_code | ||
|
||
COPY $CODE_PATH ./$CODE_PATH | ||
COPY setup.py ./ | ||
RUN pip install . | ||
|
||
WORKDIR /airbyte |
21 changes: 21 additions & 0 deletions
21
airbyte-integrations/singer/postgres_abprotocol/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
plugins { | ||
id 'java' | ||
} | ||
|
||
apply from: rootProject.file('tools/gradle/commons/integrations/image.gradle') | ||
apply from: rootProject.file('tools/gradle/commons/integrations/integration-test.gradle') | ||
dependencies { | ||
integrationTestImplementation 'org.apache.commons:commons-dbcp2:2.7.0' | ||
integrationTestImplementation 'com.fasterxml.jackson.core:jackson-databind' | ||
integrationTestImplementation 'org.apache.commons:commons-text:1.9' | ||
integrationTestImplementation "org.testcontainers:postgresql:1.15.0-rc2" | ||
integrationTestImplementation "org.postgresql:postgresql:42.2.16" | ||
|
||
integrationTestImplementation project(':airbyte-config:models') | ||
integrationTestImplementation project(':airbyte-workers') | ||
integrationTestImplementation project(':airbyte-protocol:models') | ||
integrationTestImplementation project(':airbyte-test-utils') | ||
} | ||
|
||
integrationTest.dependsOn(buildImage) | ||
buildImage.dependsOn ":airbyte-integrations:base-singer:buildImage" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import sys | ||
from airbyte_protocol.entrypoint import launch | ||
|
||
from postgres_singer_source import PostgresSingerSource | ||
|
||
if __name__ == "__main__": | ||
source = PostgresSingerSource() | ||
launch(source, sys.argv[1:]) |
1 change: 1 addition & 0 deletions
1
airbyte-integrations/singer/postgres_abprotocol/postgres_singer_source/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .source import * |
37 changes: 37 additions & 0 deletions
37
airbyte-integrations/singer/postgres_abprotocol/postgres_singer_source/source.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import urllib.request | ||
import psycopg2 | ||
|
||
from typing import Generator | ||
|
||
from airbyte_protocol import AirbyteCatalog | ||
from airbyte_protocol import AirbyteConnectionStatus | ||
from airbyte_protocol import Status | ||
from airbyte_protocol import AirbyteMessage | ||
from airbyte_protocol import Source | ||
from airbyte_protocol import ConfigContainer | ||
from base_singer import SingerHelper, SingerSource | ||
|
||
|
||
TAP_CMD = "PGCLIENTENCODING=UTF8 tap-postgres" | ||
class PostgresSingerSource(SingerSource): | ||
def __init__(self): | ||
pass | ||
|
||
def check(self, logger, config_container: ConfigContainer) -> AirbyteConnectionStatus: | ||
config = config_container.rendered_config | ||
try: | ||
params="dbname='{dbname}' user='{user}' host='{host}' password='{password}' port='{port}'".format(**config) | ||
psycopg2.connect(params) | ||
return AirbyteConnectionStatus(status=Status.SUCCEEDED) | ||
except Exception as e: | ||
logger.error(f"Exception while connecting to postgres database: {e}") | ||
return AirbyteConnectionStatus(status=Status.FAILED, message=str(e)) | ||
|
||
def discover_cmd(self, logger, config_path) -> AirbyteCatalog: | ||
return f"{TAP_CMD} --config {config_path} --discover" | ||
|
||
def read_cmd(self, logger, config_path, catalog_path, state_path=None) -> Generator[AirbyteMessage, None, None]: | ||
catalog_option = f"--properties {catalog_path}" | ||
config_option = f"--config {config_path}" | ||
state_option = f"--state {state_path}" if state_path else "" | ||
return f"{TAP_CMD} {catalog_option} {config_option} {state_option}" |
34 changes: 34 additions & 0 deletions
34
airbyte-integrations/singer/postgres_abprotocol/postgres_singer_source/spec.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"documentationUrl": "https://docs.airbyte.io/integrations/sources/postgres", | ||
"connectionSpecification": { | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"title": "Postgres Source Spec", | ||
"type": "object", | ||
"required": ["host", "port", "user", "dbname"], | ||
"additionalProperties": false, | ||
"properties": { | ||
"host": { | ||
"description": "Hostname of the database.", | ||
"type": "string" | ||
}, | ||
"port": { | ||
"description": "Port of the database.", | ||
"type": "integer", | ||
"minimum": 0, | ||
"maximum": 65536 | ||
}, | ||
"user": { | ||
"description": "Username to use to access the database.", | ||
"type": "string" | ||
}, | ||
"password": { | ||
"description": "Password associated with the username.", | ||
"type": "string" | ||
}, | ||
"dbname": { | ||
"description": "Name of the database.", | ||
"type": "string" | ||
} | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
airbyte-integrations/singer/postgres_abprotocol/requirements.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
-e ../../base-python | ||
-e ../../singer/base-singer | ||
-e . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from setuptools import setup, find_packages | ||
|
||
setup( | ||
name='postgres-singer-source', | ||
description='Postgres Singer source', | ||
author='Airbyte', | ||
author_email='contact@airbyte.io', | ||
|
||
packages=find_packages(), | ||
package_data={ | ||
'': ['*.json'] | ||
}, | ||
|
||
install_requires=[ | ||
'psycopg2==2.7.4', | ||
'tap-postgres==0.1.0', | ||
'base_singer', | ||
'airbyte_protocol' | ||
] | ||
) |
Oops, something went wrong.