allow same name and add try for other requests
This commit is contained in:
parent
d120396957
commit
88b4dbf276
1 changed files with 150 additions and 115 deletions
|
@ -204,6 +204,7 @@ class NextcloudHandler:
|
||||||
|
|
||||||
def get(self, path):
|
def get(self, path):
|
||||||
'''Do a GET request'''
|
'''Do a GET request'''
|
||||||
|
try:
|
||||||
r = requests.get(
|
r = requests.get(
|
||||||
f'{self.http}://{self.host}/{path}',
|
f'{self.http}://{self.host}/{path}',
|
||||||
auth=(self.user, self.token), verify=self.ssl, headers=self.headers(),
|
auth=(self.user, self.token), verify=self.ssl, headers=self.headers(),
|
||||||
|
@ -213,16 +214,26 @@ class NextcloudHandler:
|
||||||
if r.status_code == 200:
|
if r.status_code == 200:
|
||||||
return r
|
return r
|
||||||
elif r.status_code == 404:
|
elif r.status_code == 404:
|
||||||
self._log.error(f'File {path} does not exist')
|
self._log.error(
|
||||||
|
'Path %s does not exist',
|
||||||
|
path
|
||||||
|
)
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
else:
|
else:
|
||||||
self._log.error(r.status_code)
|
self._log.error(r.status_code)
|
||||||
sys.exit(4)
|
sys.exit(4)
|
||||||
|
except requests.exceptions.ReadTimeout as error:
|
||||||
|
self._log.error(
|
||||||
|
"Timeout (%s sec) error doing GET request. %s",
|
||||||
|
self.timeout,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
def propfind(self, path):
|
def propfind(self, path):
|
||||||
'''Do a PROPFIND request'''
|
'''Do a PROPFIND request'''
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
s.auth = (self.user, self.token)
|
s.auth = (self.user, self.token)
|
||||||
|
try:
|
||||||
r = s.request(
|
r = s.request(
|
||||||
method='PROPFIND',
|
method='PROPFIND',
|
||||||
url=f'{self.http}://{self.host}/{path}',
|
url=f'{self.http}://{self.host}/{path}',
|
||||||
|
@ -288,9 +299,16 @@ class NextcloudHandler:
|
||||||
"Nextcloud instance returned status code: %s",
|
"Nextcloud instance returned status code: %s",
|
||||||
r.status_code
|
r.status_code
|
||||||
)
|
)
|
||||||
|
except requests.exceptions.ReadTimeout as error:
|
||||||
|
self._log.error(
|
||||||
|
"Timeout (%s sec) error doing GET request. %s",
|
||||||
|
self.timeout,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
def put(self, path, src=None):
|
def put(self, path, src=None):
|
||||||
'''Do a PUT request'''
|
'''Do a PUT request'''
|
||||||
|
try:
|
||||||
if src:
|
if src:
|
||||||
r = requests.put(
|
r = requests.put(
|
||||||
f'{self.http}://{self.host}/{path}',
|
f'{self.http}://{self.host}/{path}',
|
||||||
|
@ -309,9 +327,16 @@ class NextcloudHandler:
|
||||||
"Nextcloud instance returned status code: %s",
|
"Nextcloud instance returned status code: %s",
|
||||||
r.status_code
|
r.status_code
|
||||||
)
|
)
|
||||||
|
except requests.exceptions.ReadTimeout as error:
|
||||||
|
self._log.error(
|
||||||
|
"Timeout (%s sec) error doing GET request. %s",
|
||||||
|
self.timeout,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
def delete(self, path):
|
def delete(self, path):
|
||||||
'''Do a DELETE request'''
|
'''Do a DELETE request'''
|
||||||
|
try:
|
||||||
r = requests.delete(
|
r = requests.delete(
|
||||||
f'{self.http}://{self.host}/{path}',
|
f'{self.http}://{self.host}/{path}',
|
||||||
auth=(self.user, self.token), verify=self.ssl, timeout=self.timeout
|
auth=(self.user, self.token), verify=self.ssl, timeout=self.timeout
|
||||||
|
@ -326,6 +351,12 @@ class NextcloudHandler:
|
||||||
"Nextcloud instance returned status code: %s",
|
"Nextcloud instance returned status code: %s",
|
||||||
r.status_code
|
r.status_code
|
||||||
)
|
)
|
||||||
|
except requests.exceptions.ReadTimeout as error:
|
||||||
|
self._log.error(
|
||||||
|
"Timeout (%s sec) error doing GET request. %s",
|
||||||
|
self.timeout,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
def talk(self, message, channel):
|
def talk(self, message, channel):
|
||||||
'''Post in Talk/Chat'''
|
'''Post in Talk/Chat'''
|
||||||
|
@ -335,7 +366,7 @@ class NextcloudHandler:
|
||||||
}
|
}
|
||||||
|
|
||||||
spreed_v1_path = "ocs/v2.php/apps/spreed/api/v1/chat"
|
spreed_v1_path = "ocs/v2.php/apps/spreed/api/v1/chat"
|
||||||
|
try:
|
||||||
r = requests.post(
|
r = requests.post(
|
||||||
f'{self.http}://{self.host}/{spreed_v1_path}/{channel}',
|
f'{self.http}://{self.host}/{spreed_v1_path}/{channel}',
|
||||||
data=body,
|
data=body,
|
||||||
|
@ -351,6 +382,12 @@ class NextcloudHandler:
|
||||||
"Nextcloud instance returned status code: %s",
|
"Nextcloud instance returned status code: %s",
|
||||||
r.status_code
|
r.status_code
|
||||||
)
|
)
|
||||||
|
except requests.exceptions.ReadTimeout as error:
|
||||||
|
self._log.error(
|
||||||
|
"Timeout (%s sec) error doing GET request. %s",
|
||||||
|
self.timeout,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
|
||||||
def request_passwords_session(self):
|
def request_passwords_session(self):
|
||||||
'''Request a Passwords API session'''
|
'''Request a Passwords API session'''
|
||||||
|
@ -539,8 +576,6 @@ r.status_code
|
||||||
for password in self.list_passwords():
|
for password in self.list_passwords():
|
||||||
if self.is_same_password(obj, password):
|
if self.is_same_password(obj, password):
|
||||||
return True
|
return True
|
||||||
if password['label'] == obj['label']:
|
|
||||||
return True
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def create_password(self, post_obj):
|
def create_password(self, post_obj):
|
||||||
|
|
Loading…
Reference in a new issue