-
Notifications
You must be signed in to change notification settings - Fork 8
[tap-frontapp] - fix libraries and dependabot issues #27
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9f6165a
[SAC-27536] Frontapp App libary changes
gl-romil 62f087f
[SAC-27535] [tap-frontapp] - fix extraction failures (#28)
romilqlik 04153ae
Update discover.py
romilqlik 987a159
Update __init__.py
romilqlik 3fe7d0b
Update setup.py
romilqlik 23f103e
Update __init__.py
romilqlik 4340a81
Update discover.py
romilqlik f55c28f
Update __init__.py
romilqlik 9b804e3
Update __init__.py
romilqlik 937ee61
Update discover.py
romilqlik 78437a0
Update test_client.py
romilqlik 4b39d14
Qa bugfixes from sac 27536 (#30)
romilqlik 502c2dc
requests update to 2.32.4
rdeshmukh15 ae3ff99
selected field removal from schema files (#33)
mittal-tushar 0b89467
[SAC-27953] - Rate limit change for `get_report_metrics` API (#34)
mittal-tushar cfbbc35
Merge branch 'master' of https://github.com/singer-io/tap-frontapp in…
mittal-tushar aea1a3f
[SAC-27953] - Usage of `retry-after` header for 429 errors and thrott…
mittal-tushar 45b6067
Merge branch 'master' into feature/SAC-27536-frontapp-libraries
rdeshmukh15 c3ac7f8
Update config.yml
rdeshmukh15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -102,3 +102,6 @@ tags | |
| singer-check-tap-data | ||
| state.json | ||
| catalog.json | ||
| output.json | ||
| convert_json_csv.py | ||
| notes_frontapp.txt | ||
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -6,88 +6,61 @@ | |
|
|
||
| import singer | ||
| from singer import utils | ||
| from singer.catalog import Catalog, CatalogEntry, Schema | ||
| from . import streams | ||
| from singer.catalog import Catalog | ||
| from .context import Context | ||
| from .discover import discover | ||
| from .sync import sync | ||
| from . import schemas | ||
|
|
||
| REQUIRED_CONFIG_KEYS = ["token"] | ||
|
|
||
| LOGGER = singer.get_logger() | ||
|
|
||
| #def check_authorization(atx): | ||
| # atx.client.get('/settings') | ||
|
|
||
|
|
||
| # Some taps do discovery dynamically where the catalog is read in from a | ||
| # call to the api but with the odd frontapp structure, we won't do that | ||
| # here we never use atx in here since the schema is from file but we | ||
| # would use it if we pulled schema from the API def discover(atx): | ||
| def discover(): | ||
| catalog = Catalog([]) | ||
| for tap_stream_id in schemas.STATIC_SCHEMA_STREAM_IDS: | ||
| #print("tap stream id=",tap_stream_id) | ||
| schema = Schema.from_dict(schemas.load_schema(tap_stream_id)) | ||
| metadata = [] | ||
| for field_name in schema.properties.keys(): | ||
| #print("field name=",field_name) | ||
| if field_name in schemas.PK_FIELDS[tap_stream_id]: | ||
| inclusion = 'automatic' | ||
| else: | ||
| inclusion = 'available' | ||
| metadata.append({ | ||
| 'metadata': { | ||
| 'inclusion': inclusion | ||
| }, | ||
| 'breadcrumb': ['properties', field_name] | ||
| }) | ||
| catalog.streams.append(CatalogEntry( | ||
| stream=tap_stream_id, | ||
| tap_stream_id=tap_stream_id, | ||
| key_properties=schemas.PK_FIELDS[tap_stream_id], | ||
| schema=schema, | ||
| metadata=metadata | ||
| )) | ||
| return catalog | ||
|
|
||
|
|
||
| def get_abs_path(path: str): | ||
| """Returns absolute path for URL.""" | ||
| def get_abs_path(path): | ||
| """Returns absolute path for a given relative path.""" | ||
| return os.path.join(os.path.dirname(os.path.realpath(__file__)), path) | ||
|
|
||
|
|
||
| # this is already defined in schemas.py though w/o dependencies. do we keep this for the sync? | ||
| def load_schema(tap_stream_id): | ||
| path = "schemas/{}.json".format(tap_stream_id) | ||
| """Loads schema from JSON file, resolving dependencies.""" | ||
| path = f"schemas/{tap_stream_id}.json" | ||
| schema = utils.load_json(get_abs_path(path)) | ||
| dependencies = schema.pop("tap_schema_dependencies", []) | ||
| refs = {} | ||
| for sub_stream_id in dependencies: | ||
| refs[sub_stream_id] = load_schema(sub_stream_id) | ||
| refs = {sub_stream_id: load_schema(sub_stream_id) for sub_stream_id in dependencies} | ||
| if refs: | ||
| singer.resolve_schema_references(schema, refs) | ||
| return schema | ||
|
|
||
|
|
||
| def sync(atx): | ||
| for tap_stream_id in schemas.STATIC_SCHEMA_STREAM_IDS: | ||
| schemas.load_and_write_schema(tap_stream_id) | ||
|
|
||
| streams.sync_selected_streams(atx) | ||
| def validate_credentials(token): | ||
| """Validates the FrontApp token using a simple API call""" | ||
| headers = {"Authorization": f"Bearer {token}"} | ||
| try: | ||
| response = requests.get("https://api2.frontapp.com/me", headers=headers, timeout=10) | ||
| if response.status_code == 200: | ||
| LOGGER.info("Frontapp credentials validated successfully.") | ||
| else: | ||
| LOGGER.critical("Invalid Frontapp credentials. Status code: %s", response.status_code) | ||
| sys.exit(1) | ||
| except requests.exceptions.RequestException as err: | ||
| LOGGER.critical("Credential validation failed: %s", str(err)) | ||
| sys.exit(1) | ||
|
||
|
|
||
|
|
||
| @utils.handle_top_exception(LOGGER) | ||
| def main(): | ||
| args = utils.parse_args(REQUIRED_CONFIG_KEYS) | ||
| #Validate credentials early | ||
| validate_credentials(args.config["token']) | ||
|
|
||
| atx = Context(args.config, args.state) | ||
|
|
||
| if args.discover: | ||
| # the schema is static from file so we don't need to pass in atx for connection info. | ||
| catalog = discover() | ||
| json.dump(catalog.to_dict(), sys.stdout) | ||
| else: | ||
| atx.catalog = Catalog.from_dict(args.properties) \ | ||
| if args.properties else discover() | ||
| atx.catalog = Catalog.from_dict(args.properties) if args.properties else discover() | ||
| sync(atx) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or 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,38 @@ | ||
| import singer | ||
| from singer import metadata | ||
| from singer.catalog import Catalog, CatalogEntry, Schema | ||
| from .schemas import get_schemas | ||
|
|
||
| LOGGER = singer.get_logger() | ||
|
|
||
|
|
||
| def discover(): | ||
| """Run the discovery mode, prepare the catalog file and return the catalog.""" | ||
| schemas, field_metadata = get_schemas() | ||
| LOGGER.info("Schemas loaded: %s , list(schemas.keys())) | ||
|
|
||
| catalog = Catalog([]) | ||
|
|
||
| for stream_name, schema_dict in schemas.items(): | ||
| try: | ||
| schema = Schema.from_dict(schema_dict) | ||
| mdata = field_metadata[stream_name] | ||
| except Exception as err: | ||
| LOGGER.error(err) | ||
| LOGGER.error(f"stream_name: {stream_name}") | ||
| LOGGER.error(f"type schema_dict: {type(schema_dict)}") | ||
| raise err | ||
|
|
||
| key_properties = mdata.get((), {}).get("table-key-properties",[]) | ||
|
|
||
| catalog.streams.append( | ||
| CatalogEntry( | ||
| stream=stream_name, | ||
| tap_stream_id=stream_name, | ||
| key_properties=key_properties, | ||
| schema=schema, | ||
| metadata=metadata.to_list(mdata), | ||
| ) | ||
| ) | ||
|
|
||
| return catalog |
This file contains hidden or 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 hidden or 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,35 @@ | ||
|
|
||
| import singer | ||
| from tap_frontapp.streams import sync_selected_streams | ||
| from tap_frontapp.schemas import load_and_write_schema, STATIC_SCHEMA_STREAM_IDS | ||
|
|
||
| LOGGER = singer.get_logger() | ||
|
|
||
|
|
||
| def update_currently_syncing(state, stream_name): | ||
| """Update the currently syncing stream in the Singer state.""" | ||
| if not stream_name and singer.get_currently_syncing(state): | ||
| del state["currently_syncing"] | ||
| else: | ||
| singer.set_currently_syncing(state, stream_name) | ||
| singer.write_state(state) | ||
|
|
||
|
|
||
| def sync(atx): | ||
| """Main sync method to process selected streams from FrontApp.""" | ||
|
|
||
| catalog = atx.catalog | ||
| state = atx.state | ||
|
|
||
| streams_to_sync = [s.tap_stream_id for s in catalog.get_selected_streams(state)] | ||
| LOGGER.info("Selected streams: %s", streams_to_sync) | ||
|
|
||
| last_stream = singer.get_currently_syncing(state) | ||
| LOGGER.info("Currently syncing: %s", last_stream) | ||
|
|
||
| for stream_name in STATIC_SCHEMA_STREAM_IDS: | ||
| load_and_write_schema(stream_name) | ||
|
|
||
| LOGGER.info("Starting sync of selected streams.") | ||
| sync_selected_streams(atx) | ||
| LOGGER.info("All selected streams synced successfully.") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.