I'm trying to create an automation process which can help poll the events related to any new file added to Box folder and do the transfer of the file from Box folder to Azure ADLS Gen2 Storage Account. What is the best way to authenticate to interact with Events, Files and Folder APIs via Python SDK.
I'm currently doing authentication using Developer Token, however this token is short lived and expires every 60 minutes. I tried switching over to App Tokens (as they're long lived) however these tokens have limited functionality and cannot interact with Events API.
Please help I need it urgently. I have my whole code ready and deployed as a Docker Container on Azure, however I need to regenerate my Developer Token every 60 minutes. I need a better way.
Currently, I'm doing authenticate and download files from Box and Upload to Azure like this -
# Import libraries
from boxsdk import OAuth2, Client
from box_poc import download_file_from_box, upload_file_to_adlsgen2
import os, uuid, sys
from azure.storage.filedatalake import DataLakeServiceClient
from azure.core._match_conditions import MatchConditions
from azure.storage.filedatalake._models import ContentSettings
# Azure Storage Account details
storage_account_name = os.environ['STORAGE_ACCOUNT_NAME']
storage_account_container_name = os.environ['STORAGE_ACCOUNT_CONTAINER_NAME']
storage_account_container_dir = os.environ['STORAGE_ACCOUNT_CONTAINER_DIR']
storage_account_key = os.environ['STORAGE_ACCOUNT_KEY']
# Box account details
box_client_id = os.environ['BOX_CLIENT_ID']
box_client_secret = os.environ['BOX_CLIENT_SECRET']
box_access_token = os.environ['BOX_ACCESS_TOKEN']
box_folder_id = os.environ['BOX_FOLDER_ID']
auth = OAuth2(
client_id=box_client_id,
client_secret=box_client_secret,
access_token=box_access_token,
)
client = Client(auth)
# Listen to incoming events happening on Box account
events = client.events().generate_events_with_long_polling()
for event in events:
print('Got {0} event'.format(event.event_type))
if event.event_type == "ITEM_UPLOAD":
# Trigger
file_name=download_file_from_box(box_client_id,box_client_secret,box_access_token,box_folder_id)
upload_file_to_adlsgen2(storage_account_name,storage_account_key,storage_account_container_name,storage_account_container_dir,file_name)
os.remove(file_name)
else:
pass
Comments
0 comments