-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/fixes-for-selenium-tests
- Loading branch information
Showing
58 changed files
with
1,276 additions
and
327 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from docusign_admin import ApiClient, ProvisionAssetGroupApi, AssetGroupAccountClone, \ | ||
AssetGroupAccountCloneSourceAccount, AssetGroupAccountCloneTargetAccount, \ | ||
AssetGroupAccountCloneTargetAccountAdmin | ||
from flask import session, request | ||
|
||
from ..utils import get_organization_id | ||
from ...ds_config import DS_CONFIG | ||
|
||
|
||
class Eg012CloneAccountController: | ||
@staticmethod | ||
def get_args(): | ||
"""Get required session and request arguments""" | ||
organization_id = get_organization_id() | ||
|
||
return { | ||
"access_token": session["ds_access_token"], # Represents your {ACCESS_TOKEN} | ||
"organization_id": organization_id, | ||
"source_account_id": request.form.get("source_account_id"), | ||
"target_account_name": request.form.get("target_account_name"), | ||
"target_account_user_name": request.form.get("target_account_user_name"), | ||
"target_account_first_name": request.form.get("target_account_first_name"), | ||
"target_account_last_name": request.form.get("target_account_last_name"), | ||
"target_account_email": request.form.get("target_account_email"), | ||
} | ||
|
||
@staticmethod | ||
def worker(args): | ||
""" | ||
1. Create an API client with headers | ||
2. Get the list of eligible accounts | ||
3. Construct the request body | ||
4. Clone the account | ||
""" | ||
|
||
access_token = args["access_token"] | ||
|
||
# Create an API client with headers | ||
#ds-snippet-start:Admin12Step2 | ||
api_client = ApiClient(host=DS_CONFIG["admin_api_client_host"]) | ||
api_client.set_default_header( | ||
header_name="Authorization", | ||
header_value=f"Bearer {access_token}" | ||
) | ||
#ds-snippet-end:Admin12Step2 | ||
|
||
#ds-snippet-start:Admin12Step4 | ||
account_data = AssetGroupAccountClone( | ||
source_account=AssetGroupAccountCloneSourceAccount( | ||
id=args["source_account_id"] | ||
), | ||
target_account=AssetGroupAccountCloneTargetAccount( | ||
name=args["target_account_name"], | ||
admin=AssetGroupAccountCloneTargetAccountAdmin( | ||
first_name=args["target_account_first_name"], | ||
last_name=args["target_account_last_name"], | ||
email=args["target_account_email"] | ||
), | ||
country_code="US" | ||
) | ||
) | ||
#ds-snippet-end:Admin12Step4 | ||
|
||
#ds-snippet-start:Admin12Step5 | ||
asset_group_api = ProvisionAssetGroupApi(api_client=api_client) | ||
results = asset_group_api.clone_asset_group_account(args["organization_id"], account_data) | ||
#ds-snippet-end:Admin12Step5 | ||
|
||
return results | ||
|
||
@staticmethod | ||
def get_accounts(args): | ||
access_token = args["access_token"] | ||
api_client = ApiClient(host=DS_CONFIG["admin_api_client_host"]) | ||
api_client.set_default_header( | ||
header_name="Authorization", | ||
header_value=f"Bearer {access_token}" | ||
) | ||
|
||
#ds-snippet-start:Admin12Step3 | ||
asset_group_api = ProvisionAssetGroupApi(api_client=api_client) | ||
accounts = asset_group_api.get_asset_group_accounts(args["organization_id"], compliant=True) | ||
#ds-snippet-end:Admin12Step3 | ||
|
||
return accounts |
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,70 @@ | ||
"""Example 012: How to clone an account. """ | ||
|
||
import json | ||
|
||
from docusign_admin.client.api_exception import ApiException | ||
from flask import Blueprint, render_template, session | ||
|
||
from app.docusign import authenticate, ensure_manifest, get_example_by_number | ||
from app.error_handlers import process_error | ||
from ..examples.eg012_clone_account import Eg012CloneAccountController | ||
from ...ds_config import DS_CONFIG | ||
from ...consts import API_TYPE | ||
|
||
example_number = 12 | ||
api = API_TYPE["ADMIN"] | ||
eg = f"aeg0{example_number}" # Reference (and URL) for this example | ||
aeg012 = Blueprint(eg, __name__) | ||
|
||
|
||
@aeg012.route(f"/{eg}", methods=["POST"]) | ||
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"]) | ||
@authenticate(eg=eg, api=api) | ||
def audit_users(): | ||
""" | ||
1. Get required arguments | ||
2. Call the worker method | ||
3. Render the response | ||
""" | ||
example = get_example_by_number(session["manifest"], example_number, api) | ||
|
||
# 1. Get required arguments | ||
args = Eg012CloneAccountController.get_args() | ||
try: | ||
# 2. Call the worker method to clone the account | ||
results = Eg012CloneAccountController.worker(args) | ||
except ApiException as err: | ||
return process_error(err) | ||
|
||
return render_template( | ||
"example_done.html", | ||
title=example["ExampleName"], | ||
message=example["ResultsPageText"], | ||
json=json.dumps(json.dumps(results.to_dict(), default=str)) | ||
) | ||
|
||
|
||
@aeg012.route(f"/{eg}", methods=["GET"]) | ||
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"]) | ||
@authenticate(eg=eg, api=api) | ||
def get_view(): | ||
""" Responds with the form for the example""" | ||
example = get_example_by_number(session["manifest"], example_number, api) | ||
|
||
args = Eg012CloneAccountController.get_args() | ||
|
||
try: | ||
accounts = Eg012CloneAccountController.get_accounts(args) | ||
except ApiException as err: | ||
process_error(err) | ||
|
||
return render_template( | ||
"admin/eg012_clone_account.html", | ||
title=example["ExampleName"], | ||
example=example, | ||
source_file="eg012_clone_account.py", | ||
source_url=DS_CONFIG["admin_github_url"] + "eg012_clone_account.py", | ||
documentation=DS_CONFIG["documentation"] + eg, | ||
accounts=accounts.asset_group_accounts | ||
) | ||
|
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 .views import cneg001 |
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,29 @@ | ||
from flask import request | ||
import hmac | ||
import hashlib | ||
import base64 | ||
|
||
class Eg001ValidateWebhookMessageController: | ||
@staticmethod | ||
def get_args(): | ||
"""Get required session and request arguments""" | ||
return { | ||
"secret": request.form.get("secret"), | ||
"payload": request.form.get("payload"), | ||
} | ||
|
||
@staticmethod | ||
def worker(args): | ||
""" | ||
1. Create an API client with headers | ||
2. Get your monitor data via SDK | ||
""" | ||
#ds-snippet-start:Connect1Step1 | ||
key = bytes(args['secret'], 'utf-8') | ||
payload = bytes(args['payload'], 'utf-8') | ||
|
||
hmac_hash = hmac.new(key, payload, hashlib.sha256) | ||
result = base64.b64encode(hmac_hash.digest()).decode('utf-8') | ||
#ds-snippet-end:Connect1Step1 | ||
|
||
return result |
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 .eg001_validate_webhook_message import cneg001 |
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,55 @@ | ||
"""Example 001: Validate webhook message using HMAC. """ | ||
|
||
from docusign_monitor.client.api_exception import ApiException | ||
from flask import Blueprint, render_template, session | ||
|
||
from app.docusign import authenticate, ensure_manifest, get_example_by_number | ||
from app.error_handlers import process_error | ||
from ..examples.eg001_validate_webhook_message import Eg001ValidateWebhookMessageController | ||
from ...ds_config import DS_CONFIG | ||
from ...consts import API_TYPE | ||
|
||
example_number = 1 | ||
api = API_TYPE["CONNECT"] | ||
eg = f"cneg00{example_number}" # Reference (and URL) for this example | ||
cneg001 = Blueprint(eg, __name__) | ||
|
||
@cneg001.route(f"/{eg}", methods=["POST"]) | ||
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"]) | ||
def get_monitoring_data(): | ||
""" | ||
1. Get required arguments | ||
2. Call the worker method | ||
3. Render the response | ||
""" | ||
example = get_example_by_number(session["manifest"], example_number, api) | ||
|
||
# 1. Get required arguments | ||
args = Eg001ValidateWebhookMessageController.get_args() | ||
try: | ||
# 2. Call the worker method to compute hash | ||
results = Eg001ValidateWebhookMessageController.worker(args) | ||
except ApiException as err: | ||
return process_error(err) | ||
|
||
return render_template( | ||
"example_done.html", | ||
title=example["ExampleName"], | ||
message=example["ResultsPageText"].format(results) | ||
) | ||
|
||
@cneg001.route(f"/{eg}", methods=["GET"]) | ||
@ensure_manifest(manifest_url=DS_CONFIG["example_manifest_url"]) | ||
def get_view(): | ||
""" Responds with the form for the example""" | ||
example = get_example_by_number(session["manifest"], example_number, api) | ||
|
||
return render_template( | ||
"connect/eg001_validate_webhook_message.html", | ||
title=example["ExampleName"], | ||
example=example, | ||
source_file= "eg001_validate_webhook_message.py", | ||
source_url=DS_CONFIG["connect_github_url"] + "eg001_validate_webhook_message.py", | ||
documentation=DS_CONFIG["documentation"] + eg, | ||
) | ||
|
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
Oops, something went wrong.