-
Notifications
You must be signed in to change notification settings - Fork 5
INTER-1799: Improve examples #161
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 all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2aeb992
chore: move examples to dir and add examples
erayaydin 9d755bb
chore: move python-dotenv to dev dependencies
erayaydin ce7ec1b
ci: fix python-dotenv issue for functional tests
erayaydin 7cdb858
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin 55ab70c
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin ade0d78
docs: add ruleset evaluation example to get_event
erayaydin 5c03a89
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin ccf6599
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin 99e8a45
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin 6575875
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin af8a55a
Merge branch 'inter-1796-migrate-openapi-generator' into inter-1799-i…
erayaydin 58815c1
Merge branch 'main' into inter-1799-improve-examples
erayaydin 3afd871
docs: clarify RULESET_ID is optional in example
erayaydin dba5be5
style: fix lint issues
erayaydin a0d2278
docs: update ruleset_id comment
erayaydin 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
File renamed without changes.
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,56 @@ | ||
| import os | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| import fingerprint_server_sdk | ||
| from fingerprint_server_sdk.configuration import Region | ||
| from fingerprint_server_sdk.rest import ApiException | ||
|
|
||
| load_dotenv() | ||
|
|
||
| # configure | ||
| region_str = os.environ.get('REGION', 'us').upper() | ||
| api_key = os.environ.get('PRIVATE_KEY') | ||
|
|
||
| if not api_key: | ||
| print('API key not provided') | ||
| exit(1) | ||
|
|
||
| configuration = fingerprint_server_sdk.Configuration(api_key=api_key, region=Region[region_str]) | ||
|
|
||
| # create an instance | ||
| api_instance = fingerprint_server_sdk.FingerprintApi(configuration) | ||
| event_id = os.environ.get('EVENT_ID', None) | ||
| # RULESET_ID - when provided, the response will include rule_action data. | ||
| # See https://docs.fingerprint.com/docs/rules-engine#ruleset-evaluation-using-server-api | ||
| ruleset_id = os.environ.get('RULESET_ID', None) | ||
|
|
||
| if not event_id: | ||
| print('Event id not provided') | ||
| exit(1) | ||
|
|
||
| try: | ||
| event = api_instance.get_event(event_id, ruleset_id) | ||
| print(f'Event ID: {event.event_id}') | ||
| print(f'Timestamp: {event.timestamp}') | ||
| if event.identification: | ||
| print(f'Visitor ID: {event.identification.visitor_id}') | ||
| print(f'Confidence: {event.identification.confidence.score}') | ||
| if event.bot: | ||
| print(f'Bot detection result: {event.bot}') | ||
| if ruleset_id and event.rule_action: | ||
| rule_action = event.rule_action.actual_instance | ||
| print(f'Rule action: {rule_action.type}') | ||
| if rule_action.type == 'block': | ||
| print(f'Block with HTTP status code: `{rule_action.status_code}`') | ||
| print(f'Block with response body: `{rule_action.body}`') | ||
| print(f'Block with response headers: `{rule_action.headers}`') | ||
| elif rule_action.type == 'allow': | ||
| print(f'Allow with header modifications: `{rule_action.request_header_modifications}`') | ||
| except ApiException as e: | ||
| print(f'Exception when calling get_event: {e}\n') | ||
| exit(1) | ||
|
|
||
| print('\nGet event successful!') | ||
|
|
||
| exit(0) | ||
File renamed without changes.
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,50 @@ | ||
| import os | ||
| from datetime import datetime, timedelta, timezone | ||
|
|
||
| from dotenv import load_dotenv | ||
|
|
||
| import fingerprint_server_sdk | ||
| from fingerprint_server_sdk.configuration import Region | ||
| from fingerprint_server_sdk.rest import ApiException | ||
|
|
||
| load_dotenv() | ||
|
|
||
| # configure | ||
| region_str = os.environ.get('REGION', 'us').upper() | ||
| configuration = fingerprint_server_sdk.Configuration( | ||
| api_key=os.environ['PRIVATE_KEY'], region=Region[region_str] | ||
| ) | ||
|
|
||
| # create an instance | ||
| api_instance = fingerprint_server_sdk.FingerprintApi(configuration) | ||
|
|
||
| end = datetime.now(tz=timezone.utc) | ||
| start = end - timedelta(days=7) | ||
| start_timestamp = int(start.timestamp() * 1000) | ||
| end_timestamp = int(end.timestamp() * 1000) | ||
|
|
||
| try: | ||
| response = api_instance.search_events(limit=10, start=start_timestamp, end=end_timestamp) | ||
|
|
||
| print(f'Found {len(response.events)} events') | ||
| for event in response.events: | ||
| event_visitor_id = event.identification.visitor_id if event.identification else '-' | ||
| print(f'Event ID: {event.event_id}, Visitor ID: {event_visitor_id}') | ||
|
|
||
| if response.pagination_key: | ||
| print(f'Fetching next page with pagination_key: {response.pagination_key}') | ||
| next_page = api_instance.search_events( | ||
| limit=10, | ||
| start=start_timestamp, | ||
| end=end_timestamp, | ||
| pagination_key=response.pagination_key, | ||
| ) | ||
| print(f'Found {len(next_page.events)} more events on next page') | ||
|
|
||
| except ApiException as e: | ||
| print(f'Exception when calling search_events: {e}') | ||
| exit(1) | ||
|
|
||
| print('Search events successful!') | ||
|
|
||
| exit(0) |
File renamed without changes.
File renamed without changes.
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
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
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.