Skip to content

Commit 089ac9e

Browse files
author
Vitaliy Saveliev
committed
Fix semgrep warnings
1 parent 7696fa6 commit 089ac9e

File tree

6 files changed

+14
-12
lines changed

6 files changed

+14
-12
lines changed

.semgrepignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
env.example.bat
2+
env.example.sh

selvpcclient/resources/tokens.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ def delete_many(self, token_ids, raise_if_not_found=True):
4646
for token_id in token_ids:
4747
try:
4848
self.delete(token_id)
49-
log.info("Token %s has been deleted", token_id)
5049
except ClientException as err:
5150
if raise_if_not_found:
5251
raise err
53-
log.error("%s %s", err, token_id)

selvpcclient/util.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def make_curl(url, method, data):
211211
v = str()
212212
if value:
213213
v = value.encode('utf-8')
214-
h = hashlib.sha1(v)
214+
h = hashlib.sha256(v)
215215
d = h.hexdigest()
216216
value = "{SHA1}%s" % d
217217
header = ' -H "%s: %s"' % (key, value)
@@ -225,15 +225,17 @@ def make_curl(url, method, data):
225225
def is_url(data):
226226
"""Checks if getting value is valid url and path exists."""
227227
try:
228-
r = requests.head(data)
229-
except Exception:
228+
r = requests.head(data, timeout=15)
229+
r.raise_for_status()
230+
except requests.RequestException:
230231
return False
231232
return r.status_code == requests.codes.ok
232233

233234

234235
def process_logo_by_url(url):
235236
"""Download and encode image by url."""
236-
res = requests.get(url)
237+
res = requests.get(url, timeout=15)
238+
res.raise_for_status()
237239
encoded_logo = base64.b64encode(res.content)
238240
return encoded_logo
239241

tests/cli/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import json
22

3-
import mock
3+
from unittest import mock
4+
45
from selvpcclient.client import Client
56
from selvpcclient.shell import CLI
67

78

89
def prepare_to_run_command(cmd):
9-
pass
10+
pass # nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
1011

1112

1213
class FakeStdout(object):

tests/rest/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import mock
2-
31
from datetime import datetime, timedelta
2+
from unittest import mock
43

54
from selvpcclient.httpclient import HTTPClient, RegionalHTTPClient
65

tests/test_util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def function_that_takes_theme_params(logo=None, color=""):
9797
def test_process_theme_params_invalid_logo():
9898
@process_theme_params
9999
def function_that_takes_theme_params(logo=None, color=''):
100-
pass
100+
pass # nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
101101

102102
with pytest.raises(Exception):
103103
function_that_takes_theme_params(logo='is \' not path or url!!!',
@@ -107,7 +107,7 @@ def function_that_takes_theme_params(logo=None, color=''):
107107
def test_process_theme_params_wrong_path():
108108
@process_theme_params
109109
def function_that_takes_theme_params(logo=None, color=''):
110-
pass
110+
pass # nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
111111

112112
with pytest.raises(Exception):
113113
function_that_takes_theme_params(logo='/wrong/path/logo.jpg',

0 commit comments

Comments
 (0)