Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[low-code connectors]: Assert there are no custom top-level fields #15489

Merged
merged 9 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ class ReadException(Exception):
"""
Raise when there is an error reading data from an API Source
"""


class InvalidConnectorDefinitionException(Exception):
"""
Raise when the connector definition is invalid
"""
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import requests
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources.declarative.exceptions import ReadException
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed the file

from airbyte_cdk.sources.declarative.extractors.http_selector import HttpSelector
from airbyte_cdk.sources.declarative.read_exception import ReadException
from airbyte_cdk.sources.declarative.requesters.error_handlers.response_action import ResponseAction
from airbyte_cdk.sources.declarative.requesters.paginators.no_pagination import NoPagination
from airbyte_cdk.sources.declarative.requesters.paginators.paginator import Paginator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from airbyte_cdk.sources.declarative.checks.connection_checker import ConnectionChecker
from airbyte_cdk.sources.declarative.declarative_source import DeclarativeSource
from airbyte_cdk.sources.declarative.exceptions import InvalidConnectorDefinitionException
from airbyte_cdk.sources.declarative.parsers.factory import DeclarativeComponentFactory
from airbyte_cdk.sources.declarative.parsers.yaml_parser import YamlParser
from airbyte_cdk.sources.streams import Stream
Expand All @@ -16,6 +17,8 @@
class YamlDeclarativeSource(DeclarativeSource):
"""Declarative source defined by a yaml file"""

VALID_TOP_LEVEL_FIELDS = {"definitions", "streams", "check", "version"}

def __init__(self, path_to_yaml):
"""
:param path_to_yaml: Path to the yaml file describing the source
Expand All @@ -25,6 +28,11 @@ def __init__(self, path_to_yaml):
self._path_to_yaml = path_to_yaml
self._source_config = self._read_and_parse_yaml_file(path_to_yaml)

# Stopgap to protect the top-level namespace until it's validated through the schema
unknown_fields = [key for key in self._source_config.keys() if key not in self.VALID_TOP_LEVEL_FIELDS]
if unknown_fields:
raise InvalidConnectorDefinitionException(f"Found unknown top-level fields: {unknown_fields}")

@property
def connection_checker(self) -> ConnectionChecker:
check = self._source_config["check"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import pytest
import requests
from airbyte_cdk.models import SyncMode
from airbyte_cdk.sources.declarative.read_exception import ReadException
from airbyte_cdk.sources.declarative.exceptions import ReadException
from airbyte_cdk.sources.declarative.requesters.error_handlers.response_action import ResponseAction
from airbyte_cdk.sources.declarative.requesters.error_handlers.response_status import ResponseStatus
from airbyte_cdk.sources.declarative.requesters.request_option import RequestOptionType
Expand Down
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
schema_loader:
type: JsonSchema
file_path: "./source_{{snakeCase name}}/schemas/\{{ options['name'] }}.json"
selector:
type: RecordSelector
extractor:
type: JelloExtractor
transform: "_"
requester:
type: HttpRequester
name: "\{{ options['name'] }}"
http_method: "GET"
authenticator:
type: BearerAuthenticator
api_token: "\{{ config['api_key'] }}"
retriever:
type: SimpleRetriever
$options:
url_base: TODO "your_api_base_url"
name: "\{{ options['name'] }}"
primary_key: "\{{ options['primary_key'] }}"
record_selector:
$ref: "*ref(selector)"
paginator:
type: NoPagination
customers_stream:
type: DeclarativeStream
$options:
name: "customers"
primary_key: "id"
definitions:
schema_loader:
$ref: "*ref(schema_loader)"
type: JsonSchema
file_path: "./source_{{snakeCase name}}/schemas/\{{ options['name'] }}.json"
selector:
type: RecordSelector
extractor:
type: JelloExtractor
transform: "_"
requester:
type: HttpRequester
name: "\{{ options['name'] }}"
http_method: "GET"
authenticator:
type: BearerAuthenticator
api_token: "\{{ config['api_key'] }}"
retriever:
$ref: "*ref(retriever)"
requester:
$ref: "*ref(requester)"
path: TODO "your_endpoint_path"
type: SimpleRetriever
$options:
url_base: TODO "your_api_base_url"
name: "\{{ options['name'] }}"
primary_key: "\{{ options['primary_key'] }}"
record_selector:
$ref: "*ref(definitions.selector)"
paginator:
type: NoPagination

streams:
- "*ref(customers_stream)"
- type: DeclarativeStream
$options:
name: "customers"
primary_key: "id"
schema_loader:
$ref: "*ref(definitions.schema_loader)"
retriever:
$ref: "*ref(definitions.retriever)"
requester:
$ref: "*ref(definitions.requester)"
path: TODO "your_endpoint_path"
check:
type: CheckStream
stream_names: ["customers"]

version: "0.0.0-alpha"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sherifnada do you have an opinion on what this should be set to?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0.1.0 and I would not use alpha. Semver already covers it in the 0.x version

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this as the first line in the file since it’s more of a “header”