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

fix(templates): E2E Cookiecutter - Cover all REST authentication cases + one GraphQL case #1428

Merged
13 changes: 11 additions & 2 deletions .github/workflows/cookiecutter-e2e.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: E2E Cookiecutters

on:
pull_request:
types: [opened, synchronize, reopened]
paths: ["cookiecutter/**", "e2e-tests/cookiecutters/**"]
push:
branches: [main]
paths: ["cookiecutter/**", "e2e-tests/cookiecutters/**"]
Expand All @@ -21,8 +24,13 @@ jobs:
fail-fast: true
matrix:
include:
- { cookiecutter: "tap-template", replay: "tap-graphql-jwt.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "tap-template", replay: "tap-rest-api_key-github.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "tap-template", replay: "tap-rest-jwt-github.json", python-version: "3.9", os: "ubuntu-latest" }
edgarrmondragon marked this conversation as resolved.
Show resolved Hide resolved
- { cookiecutter: "tap-template", replay: "tap-rest-basic_auth.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "tap-template", replay: "tap-rest-bearer_token.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "tap-template", replay: "tap-rest-custom.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "tap-template", replay: "tap-rest-jwt.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "tap-template", replay: "tap-rest-oauth2.json", python-version: "3.9", os: "ubuntu-latest" }
- { cookiecutter: "target-template", replay: "target-per_record.json", python-version: "3.9", os: "ubuntu-latest" }

steps:
Expand Down Expand Up @@ -55,7 +63,8 @@ jobs:
CC_TEMPLATE: cookiecutter/${{ matrix.cookiecutter }}
REPLAY_FILE: e2e-tests/cookiecutters/${{ matrix.replay }}
run: |
bash e2e-tests/cookiecutters/test_cookiecutter.sh $CC_TEMPLATE $REPLAY_FILE 0
chmod +x ./e2e-tests/cookiecutters/test_cookiecutter.sh
./e2e-tests/cookiecutters/test_cookiecutter.sh $CC_TEMPLATE $REPLAY_FILE 0

- uses: actions/upload-artifact@v3
with:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ from singer_sdk.authenticators import BasicAuthenticator
from singer_sdk.helpers.jsonpath import extract_jsonpath
from singer_sdk.streams import {{ cookiecutter.stream_type }}Stream

{% elif cookiecutter.auth_method == "Custom or N/A" -%}
from singer_sdk.helpers.jsonpath import extract_jsonpath
from singer_sdk.streams import {{ cookiecutter.stream_type }}Stream

{% elif cookiecutter.auth_method in ("OAuth2", "JWT") -%}
from singer_sdk.helpers.jsonpath import extract_jsonpath
from singer_sdk.streams import {{ cookiecutter.stream_type }}Stream
Expand Down Expand Up @@ -97,7 +101,7 @@ class {{ cookiecutter.source_name }}Stream({{ cookiecutter.stream_type }}Stream)
"""
return BearerTokenAuthenticator.create_for_stream(
self,
token=self.config.get("api_key")
token=self.config.get("api_key", ""),
)

{%- elif cookiecutter.auth_method == "Basic Auth" %}
Expand All @@ -111,8 +115,8 @@ class {{ cookiecutter.source_name }}Stream({{ cookiecutter.stream_type }}Stream)
"""
return BasicAuthenticator.create_for_stream(
self,
username=self.config.get("username"),
password=self.config.get("password"),
username=self.config.get("username", ""),
password=self.config.get("password", ""),
)

{%- endif %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ class {{ cookiecutter.source_name }}Authenticator(OAuthAuthenticator, metaclass=

@property
def oauth_request_body(self) -> dict:
"""Define the OAuth request body for the {{ cookiecutter.source_name }} API."""
"""Define the OAuth request body for the AutomaticTestTap API.

Returns:
A dict with the request body
"""
# TODO: Define the request body needed for the API.
return {
'resource': 'https://analysis.windows.net/powerbi/api',
Expand Down
14 changes: 14 additions & 0 deletions e2e-tests/cookiecutters/tap-rest-basic_auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"cookiecutter": {
"source_name": "AutomaticTestTap",
"admin_name": "Automatic Tester",
"tap_id": "tap-rest-basic_auth",
"library_name": "tap_rest_basic_auth",
"variant": "None (Skip)",
"stream_type": "REST",
"auth_method": "Basic Auth",
"include_cicd_sample_template": "None (Skip)",
"_template": "../tap-template/",
"_output_dir": "."
}
}
14 changes: 14 additions & 0 deletions e2e-tests/cookiecutters/tap-rest-bearer_token.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"cookiecutter": {
"source_name": "AutomaticTestTap",
"admin_name": "Automatic Tester",
"tap_id": "tap-rest-bearer_token",
"library_name": "tap_rest_bearer_token",
"variant": "None (Skip)",
"stream_type": "REST",
"auth_method": "Bearer Token",
"include_cicd_sample_template": "None (Skip)",
"_template": "../tap-template/",
"_output_dir": "."
}
}
14 changes: 14 additions & 0 deletions e2e-tests/cookiecutters/tap-rest-custom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"cookiecutter": {
"source_name": "AutomaticTestTap",
"admin_name": "Automatic Tester",
"tap_id": "tap-rest-custom",
"library_name": "tap_rest_custom",
"variant": "None (Skip)",
"stream_type": "REST",
"auth_method": "Custom or N/A",
"include_cicd_sample_template": "None (Skip)",
"_template": "../tap-template/",
"_output_dir": "."
}
}
14 changes: 14 additions & 0 deletions e2e-tests/cookiecutters/tap-rest-jwt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"cookiecutter": {
"source_name": "AutomaticTestTap",
"admin_name": "Automatic Tester",
"tap_id": "tap-rest-jwt",
"library_name": "tap_rest_jwt",
"variant": "None (Skip)",
"stream_type": "REST",
"auth_method": "JWT",
"include_cicd_sample_template": "None (Skip)",
"_template": "../tap-template/",
"_output_dir": "."
}
}
14 changes: 14 additions & 0 deletions e2e-tests/cookiecutters/tap-rest-oauth2.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"cookiecutter": {
"source_name": "AutomaticTestTap",
"admin_name": "Automatic Tester",
"tap_id": "tap-rest-oauth2",
"library_name": "tap_rest_oauth2",
"variant": "None (Skip)",
"stream_type": "REST",
"auth_method": "OAuth2",
"include_cicd_sample_template": "None (Skip)",
"_template": "../tap-template/",
"_output_dir": "."
}
}
4 changes: 2 additions & 2 deletions e2e-tests/cookiecutters/test_cookiecutter.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ usage() {

if [[ ! -d $TAP_TEMPLATE ]]; then
usage "Tap template folder not found"
exit
exit 1
fi
if [[ ! -f $REPLAY_FILE ]]; then
usage "Replay file not found"
exit
exit 1
fi

CC_TEST_OUTPUT=$CC_BUILD_PATH/$CC_OUTPUT_DIR
Expand Down