Skip to content

Commit

Permalink
sslverify false option for sharepoint testing
Browse files Browse the repository at this point in the history
  • Loading branch information
saul-data committed Jul 18, 2023
1 parent e483b8d commit ae926d5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/dataplane/Microsoft/Sharepoint/sharepoint_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
ProxyUrl: Proxy endpoint to use
ProxyMethod: https or http, default https
"""
def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointFilePath, DownloadMethod="Object", LocalFilePath="", Library="root", ProxyUse=False, ProxyUrl="", ProxyMethod="https"):
def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointFilePath, DownloadMethod="Object", LocalFilePath="", Library="root", ProxyUse=False, ProxyUrl="", ProxyMethod="https", SSLVerify=True):

import requests
from datetime import datetime
Expand Down Expand Up @@ -37,7 +37,7 @@ def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointF
else:
proxies = {}

auth = requests.request("POST", url, headers=headers, data=payload, proxies=proxies)
auth = requests.request("POST", url, headers=headers, data=payload, proxies=proxies, verify=SSLVerify)

if auth.status_code != 200:
duration = datetime.now() - start
Expand All @@ -53,7 +53,7 @@ def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointF

# ======= Get Site ID from Site name ====
SiteName = SiteName.replace(" ", "")
SiteID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{Host}:/sites/{SiteName}?$select=id", headers=headers, json=payload, proxies=proxies)
SiteID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{Host}:/sites/{SiteName}?$select=id", headers=headers, json=payload, proxies=proxies, verify=SSLVerify)

if SiteID.status_code != 200:
duration = datetime.now() - start
Expand All @@ -71,7 +71,7 @@ def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointF
else:

drive = ""
driveID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{SiteID['id']}/drives?$select=name,id", headers=headers, json=payload, proxies=proxies)
driveID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{SiteID['id']}/drives?$select=name,id", headers=headers, json=payload, proxies=proxies, verify=SSLVerify)
if driveID.status_code != 200:
duration = datetime.now() - start
return {"result":"Fail", "reason":"Sharepoint get drives", "duration": str(duration), "status": driveID.status_code, "error": driveID.json()}
Expand All @@ -91,7 +91,7 @@ def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointF
# ====== Get Item ID =====


ItemID = requests.request("GET", url, headers=headers, json=payload, proxies=proxies)
ItemID = requests.request("GET", url, headers=headers, json=payload, proxies=proxies, verify=SSLVerify)

if ItemID.status_code != 200:
duration = datetime.now() - start
Expand All @@ -101,7 +101,7 @@ def sharepoint_download(Host, TenantID, ClientID, Secret, SiteName, SharepointF


# ====== Download file using link =====
r = requests.get(ItemID["@microsoft.graph.downloadUrl"], proxies=proxies)
r = requests.get(ItemID["@microsoft.graph.downloadUrl"], proxies=proxies, verify=SSLVerify)

if DownloadMethod == "File":
with open(LocalFilePath, 'wb') as f:
Expand Down
12 changes: 6 additions & 6 deletions src/dataplane/Microsoft/Sharepoint/sharepoint_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
FileConflict: "fail (default) | replace | rename"
FileDescription: Sharepoint description for the file
"""
def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath, SourceFilePath="/tmp/default.txt", Library="root", UploadMethod="Object", UploadObject="", ProxyUse=False, ProxyUrl="", ProxyMethod="https", FileConflict="fail"):
def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath, SourceFilePath="/tmp/default.txt", Library="root", UploadMethod="Object", UploadObject="", ProxyUse=False, ProxyUrl="", ProxyMethod="https", FileConflict="fail", SSLVerify=True):


import requests
Expand Down Expand Up @@ -44,7 +44,7 @@ def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath
else:
proxies = {}

auth = requests.request("POST", url, headers=headers, data=payload, proxies=proxies)
auth = requests.request("POST", url, headers=headers, data=payload, proxies=proxies, verify=SSLVerify)

if auth.status_code != 200:
duration = datetime.now() - start
Expand All @@ -60,7 +60,7 @@ def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath

# ======= Get Site ID from Site name ====
SiteName = SiteName.replace(" ", "")
SiteID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{Host}:/sites/{SiteName}?$select=id", headers=headers, json=payload, proxies=proxies)
SiteID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{Host}:/sites/{SiteName}?$select=id", headers=headers, json=payload, proxies=proxies, verify=SSLVerify)

if SiteID.status_code != 200:
duration = datetime.now() - start
Expand All @@ -80,7 +80,7 @@ def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath
else:

drive = ""
driveID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{SiteID['id']}/drives?$select=name,id", headers=headers, json=payload, proxies=proxies)
driveID = requests.request("GET", f"https://graph.microsoft.com/v1.0/sites/{SiteID['id']}/drives?$select=name,id", headers=headers, json=payload, proxies=proxies, verify=SSLVerify)
if driveID.status_code != 200:
duration = datetime.now() - start
return {"result":"Fail", "reason":"Sharepoint get drives", "duration": str(duration), "status": driveID.status_code, "error": driveID.json()}
Expand Down Expand Up @@ -111,7 +111,7 @@ def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath
"fileSize": FileSize,
"name": TargetFilePath
}
UploadUrl = requests.request("POST", url, headers=headers, json=payload, proxies=proxies)
UploadUrl = requests.request("POST", url, headers=headers, json=payload, proxies=proxies, verify=SSLVerify)

if UploadUrl.status_code != 200:
duration = datetime.now() - start
Expand All @@ -132,7 +132,7 @@ def sharepoint_upload(Host, TenantID, ClientID, Secret, SiteName, TargetFilePath
# "Authorization": "Bearer " + auth["access_token"]
}

upload = requests.put(UploadUrl["uploadUrl"], data=UploadObject, headers=headers, proxies=proxies)
upload = requests.put(UploadUrl["uploadUrl"], data=UploadObject, headers=headers, proxies=proxies, verify=SSLVerify)
if upload.status_code != 201:
duration = datetime.now() - start
return {"result":"non 201", "reason":"Upload file", "duration": str(duration), "status": upload.status_code, "response": upload.json()}
Expand Down

0 comments on commit ae926d5

Please sign in to comment.