diff --git a/Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py b/Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py index e1a7e1840..6c7e8fdf7 100644 --- a/Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py +++ b/Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py @@ -125,6 +125,9 @@ {"name": "connect to bigquery client", "function": "connect_to_bigquery_client", "screenshot": "none" }, {"name": "execute bigquery query", "function": "execute_bigquery_query", "screenshot": "none" }, + + {"name": "connect to google service client", "function": "connect_to_google_service_account", "screenshot": "none" }, + {"name": "upload to google storage bucket", "function": "upload_to_google_storage_bucket", "screenshot": "none" }, ) # yapf: disable diff --git a/Framework/Built_In_Automation/Sequential_Actions/common_functions.py b/Framework/Built_In_Automation/Sequential_Actions/common_functions.py index b11e6c6bf..627912edb 100755 --- a/Framework/Built_In_Automation/Sequential_Actions/common_functions.py +++ b/Framework/Built_In_Automation/Sequential_Actions/common_functions.py @@ -6505,6 +6505,70 @@ def execute_bigquery_query(data_set): except: return CommonUtil.Exception_Handler(sys.exc_info()) +@logger +def connect_to_google_service_account(data_set): + """ + data_set: + credentials path | input parameter | path to credentails json file + connect to google service client | common action | client variable name + """ + + sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + CommonUtil.ExecLog(sModuleInfo, "Actions involving the Google service account may not function correctly without a virtual environment.", 2) + cred_path = None + client_var_name = None + for left, _, right in data_set: + if left.strip().lower() == 'credentials path': + cred_path = right.strip() + if left.strip().lower() == 'connect to google service client': + client_var_name = right.strip() + + try: + from google.cloud import storage + client = storage.Client.from_service_account_json(json_credentials_path=cred_path) + sr.Set_Shared_Variables(client_var_name, client) + return "passed" + except: + CommonUtil.ExecLog(sModuleInfo, "Incorrect Credentails", 3) + return "zeuz_failed" + +@logger +def upload_to_google_storage_bucket(data_set): + """ + data_set: + filepath | input parameter | filepath + bucket | input parameter | bucket name + upload to google storage bucket | common action | client variable name + """ + + sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + CommonUtil.ExecLog(sModuleInfo, "Actions involving the Google service account may not function correctly without a virtual environment.", 2) + filepath = None + client_var_name = None + bucket = None + + for left, _, right in data_set: + if left.strip().lower() == 'filepath': + filepath = right.strip() + if left.strip().lower() == 'upload to google storage bucket': + client_var_name = right.strip() + if left.strip().lower() == 'bucket': + bucket = right.strip() + + if None in (filepath,client_var_name,bucket): + CommonUtil.ExecLog(sModuleInfo, "Incorrect Dataset", 3) + return "zeuz_failed" + + try: + client = sr.Get_Shared_Variables(client_var_name) + bucket = client.get_bucket(bucket) + blob = bucket.blob(os.path.basename(filepath)) + blob.upload_from_filename(filepath) + CommonUtil.ExecLog(sModuleInfo, f'File {filepath} uploaded to {bucket}.') + return "passed" + except: + return CommonUtil.Exception_Handler(sys.exc_info()) + @logger def text_to_speech(data_set): """ diff --git a/requirements-linux.txt b/requirements-linux.txt index 2ac57f036..cb0c3b181 100644 --- a/requirements-linux.txt +++ b/requirements-linux.txt @@ -56,4 +56,5 @@ jinja2 pandas pyperclip thefuzz -backports-datetime-fromisoformat; python_version < '3.11' \ No newline at end of file +backports-datetime-fromisoformat; python_version < '3.11' +google-cloud-storage \ No newline at end of file diff --git a/requirements-mac.txt b/requirements-mac.txt index 2fe5a6cf5..741ef304b 100644 --- a/requirements-mac.txt +++ b/requirements-mac.txt @@ -60,4 +60,5 @@ jinja2 pandas pyperclip backports-datetime-fromisoformat; python_version < '3.11' -thefuzz \ No newline at end of file +thefuzz +google-cloud-storage \ No newline at end of file diff --git a/requirements-win.txt b/requirements-win.txt index 7c66bc58a..9043b8301 100644 --- a/requirements-win.txt +++ b/requirements-win.txt @@ -71,3 +71,4 @@ pandas pyperclip backports-datetime-fromisoformat; python_version < '3.11' thefuzz +google-cloud-storage \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1423b9eb3..7a7783443 100644 --- a/requirements.txt +++ b/requirements.txt @@ -51,4 +51,5 @@ configobj boto3 pandas pyperclip -backports-datetime-fromisoformat; python_version < '3.11' \ No newline at end of file +backports-datetime-fromisoformat; python_version < '3.11' +google-cloud-storage \ No newline at end of file