From dec0efdd57f2762fb301ae1e5b57e7e4c0cda5ce Mon Sep 17 00:00:00 2001 From: William Mattern Date: Mon, 24 Oct 2022 15:16:37 -0400 Subject: [PATCH 1/6] git ignore IDE files/folders --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index f46c1ec..dd30228 100644 --- a/.gitignore +++ b/.gitignore @@ -81,6 +81,7 @@ celerybeat-schedule # virtualenv venv/ ENV/ +.venv # Spyder project settings .spyderproject @@ -95,3 +96,6 @@ ENV/ # Singer files *.config.json *.catalog.json + +# IDE +.idea \ No newline at end of file From 7e064ec7e73dae67163a7ed15bca61456e146448 Mon Sep 17 00:00:00 2001 From: William Mattern Date: Mon, 24 Oct 2022 15:22:58 -0400 Subject: [PATCH 2/6] git ignore singer runner files --- .gitignore | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index dd30228..44fc1e8 100644 --- a/.gitignore +++ b/.gitignore @@ -98,4 +98,10 @@ ENV/ *.catalog.json # IDE -.idea \ No newline at end of file +.idea + +# Singer config +config.json +tap-*.json +target-*.json +*config.json \ No newline at end of file From 7619a3cd87fe4adb8c938659c5a10a6cdb735382 Mon Sep 17 00:00:00 2001 From: William Mattern Date: Thu, 27 Oct 2022 14:52:03 -0400 Subject: [PATCH 3/6] bump version for release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index fe87efc..049f443 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ setup( name='tap-bing-ads', - version="2.2.1", + version="2.3.0", description='Singer.io tap for extracting data from the Bing Ads API', author='Stitch', url='http://singer.io', From afad8a1271dfb0813b311dc144f9c6bd89c757e9 Mon Sep 17 00:00:00 2001 From: William Mattern Date: Thu, 27 Oct 2022 14:53:40 -0400 Subject: [PATCH 4/6] adding refresh token callback function to save tokens to ssm after refreshing --- tap_bing_ads/__init__.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tap_bing_ads/__init__.py b/tap_bing_ads/__init__.py index f898192..42e9d13 100644 --- a/tap_bing_ads/__init__.py +++ b/tap_bing_ads/__init__.py @@ -38,6 +38,7 @@ "oauth_client_secret", "refresh_token", "developer_token", + "refresh_token_ssm_param" ] # objects that are at the root level, with selectable fields in the Stitch UI @@ -164,7 +165,8 @@ def get_authentication(): authentication = OAuthWebAuthCodeGrant( CONFIG['oauth_client_id'], CONFIG['oauth_client_secret'], - '') ## redirect URL not needed for refresh token + '', ## redirect URL not needed for refresh token + token_refreshed_callback=save_refresh_token_to_ssm) # Retrieves OAuth access and refresh tokens from the Microsoft Account authorization service. authentication.request_oauth_tokens_by_refresh_token(CONFIG['refresh_token']) return authentication @@ -172,12 +174,27 @@ def get_authentication(): authentication = OAuthWebAuthCodeGrant( CONFIG['oauth_client_id'], CONFIG['oauth_client_secret'], - '', - oauth_scope='bingads.manage') ## redirect URL not needed for refresh token + '',## redirect URL not needed for refresh token + oauth_scope='bingads.manage', + token_refreshed_callback=save_refresh_token_to_ssm) # Retrieves OAuth access and refresh tokens from the Microsoft Account authorization service. authentication.request_oauth_tokens_by_refresh_token(CONFIG['refresh_token']) return authentication + +def save_refresh_token_to_ssm(oauth_tokens): + try: + import boto3 + LOGGER.info(f"saving refresh token to SSM now at: {CONFIG['refresh_token_ssm_param']}") + + _ssm = boto3.client("ssm") + put_param_output: dict = _ssm.put_parameter(Name=CONFIG['refresh_token_ssm_param'], Value=oauth_tokens.refresh_token, Overwrite=True) + + LOGGER.info(f"put_param_output: {str(put_param_output)}") + except ImportError as e: + LOGGER.warning("SSM param not saved to SSM due to error starting boto3. Eventually, your refresh token will expire.") + + @bing_ads_error_handling def create_sdk_client(service, account_id): # Creates SOAP client with OAuth refresh credentials for services From dddd1e2bf1f0cbea8acddceda118d58b271279f9 Mon Sep 17 00:00:00 2001 From: William Mattern Date: Fri, 18 Nov 2022 15:50:40 -0500 Subject: [PATCH 5/6] formatting, EOL --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 44fc1e8..ad32f8f 100644 --- a/.gitignore +++ b/.gitignore @@ -104,4 +104,4 @@ ENV/ config.json tap-*.json target-*.json -*config.json \ No newline at end of file +*config.json From 54a1374ecc4698ebf124812857ab53c3dca4d5fa Mon Sep 17 00:00:00 2001 From: William Mattern Date: Fri, 18 Nov 2022 16:28:56 -0500 Subject: [PATCH 6/6] code review style changes _ssm -> ssm --- tap_bing_ads/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tap_bing_ads/__init__.py b/tap_bing_ads/__init__.py index 42e9d13..3a01778 100644 --- a/tap_bing_ads/__init__.py +++ b/tap_bing_ads/__init__.py @@ -187,8 +187,8 @@ def save_refresh_token_to_ssm(oauth_tokens): import boto3 LOGGER.info(f"saving refresh token to SSM now at: {CONFIG['refresh_token_ssm_param']}") - _ssm = boto3.client("ssm") - put_param_output: dict = _ssm.put_parameter(Name=CONFIG['refresh_token_ssm_param'], Value=oauth_tokens.refresh_token, Overwrite=True) + ssm = boto3.client("ssm") + put_param_output: dict = ssm.put_parameter(Name=CONFIG['refresh_token_ssm_param'], Value=oauth_tokens.refresh_token, Overwrite=True) LOGGER.info(f"put_param_output: {str(put_param_output)}") except ImportError as e: