Skip to content

Commit 9de324f

Browse files
authored
Merge pull request #479 from AutomationSolutionz/google-storage-bucket
Actions for google cloud storage
2 parents 19d756a + 6bab8bd commit 9de324f

File tree

6 files changed

+74
-3
lines changed

6 files changed

+74
-3
lines changed

Framework/Built_In_Automation/Sequential_Actions/action_declarations/common.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@
125125

126126
{"name": "connect to bigquery client", "function": "connect_to_bigquery_client", "screenshot": "none" },
127127
{"name": "execute bigquery query", "function": "execute_bigquery_query", "screenshot": "none" },
128+
129+
{"name": "connect to google service client", "function": "connect_to_google_service_account", "screenshot": "none" },
130+
{"name": "upload to google storage bucket", "function": "upload_to_google_storage_bucket", "screenshot": "none" },
128131

129132
) # yapf: disable
130133

Framework/Built_In_Automation/Sequential_Actions/common_functions.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6505,6 +6505,70 @@ def execute_bigquery_query(data_set):
65056505
except:
65066506
return CommonUtil.Exception_Handler(sys.exc_info())
65076507

6508+
@logger
6509+
def connect_to_google_service_account(data_set):
6510+
"""
6511+
data_set:
6512+
credentials path | input parameter | path to credentails json file
6513+
connect to google service client | common action | client variable name
6514+
"""
6515+
6516+
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
6517+
CommonUtil.ExecLog(sModuleInfo, "Actions involving the Google service account may not function correctly without a virtual environment.", 2)
6518+
cred_path = None
6519+
client_var_name = None
6520+
for left, _, right in data_set:
6521+
if left.strip().lower() == 'credentials path':
6522+
cred_path = right.strip()
6523+
if left.strip().lower() == 'connect to google service client':
6524+
client_var_name = right.strip()
6525+
6526+
try:
6527+
from google.cloud import storage
6528+
client = storage.Client.from_service_account_json(json_credentials_path=cred_path)
6529+
sr.Set_Shared_Variables(client_var_name, client)
6530+
return "passed"
6531+
except:
6532+
CommonUtil.ExecLog(sModuleInfo, "Incorrect Credentails", 3)
6533+
return "zeuz_failed"
6534+
6535+
@logger
6536+
def upload_to_google_storage_bucket(data_set):
6537+
"""
6538+
data_set:
6539+
filepath | input parameter | filepath
6540+
bucket | input parameter | bucket name
6541+
upload to google storage bucket | common action | client variable name
6542+
"""
6543+
6544+
sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME
6545+
CommonUtil.ExecLog(sModuleInfo, "Actions involving the Google service account may not function correctly without a virtual environment.", 2)
6546+
filepath = None
6547+
client_var_name = None
6548+
bucket = None
6549+
6550+
for left, _, right in data_set:
6551+
if left.strip().lower() == 'filepath':
6552+
filepath = right.strip()
6553+
if left.strip().lower() == 'upload to google storage bucket':
6554+
client_var_name = right.strip()
6555+
if left.strip().lower() == 'bucket':
6556+
bucket = right.strip()
6557+
6558+
if None in (filepath,client_var_name,bucket):
6559+
CommonUtil.ExecLog(sModuleInfo, "Incorrect Dataset", 3)
6560+
return "zeuz_failed"
6561+
6562+
try:
6563+
client = sr.Get_Shared_Variables(client_var_name)
6564+
bucket = client.get_bucket(bucket)
6565+
blob = bucket.blob(os.path.basename(filepath))
6566+
blob.upload_from_filename(filepath)
6567+
CommonUtil.ExecLog(sModuleInfo, f'File {filepath} uploaded to {bucket}.')
6568+
return "passed"
6569+
except:
6570+
return CommonUtil.Exception_Handler(sys.exc_info())
6571+
65086572
@logger
65096573
def text_to_speech(data_set):
65106574
"""

requirements-linux.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,5 @@ jinja2
5656
pandas
5757
pyperclip
5858
thefuzz
59-
backports-datetime-fromisoformat; python_version < '3.11'
59+
backports-datetime-fromisoformat; python_version < '3.11'
60+
google-cloud-storage

requirements-mac.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ jinja2
6060
pandas
6161
pyperclip
6262
backports-datetime-fromisoformat; python_version < '3.11'
63-
thefuzz
63+
thefuzz
64+
google-cloud-storage

requirements-win.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,4 @@ pandas
7171
pyperclip
7272
backports-datetime-fromisoformat; python_version < '3.11'
7373
thefuzz
74+
google-cloud-storage

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ configobj
5151
boto3
5252
pandas
5353
pyperclip
54-
backports-datetime-fromisoformat; python_version < '3.11'
54+
backports-datetime-fromisoformat; python_version < '3.11'
55+
google-cloud-storage

0 commit comments

Comments
 (0)