Skip to content

Commit

Permalink
Fix semgrep warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaliy Saveliev committed Jun 25, 2024
1 parent 7696fa6 commit 7c5031a
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 11 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/secure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on: push
jobs:
# Sample GitHub Actions:
# https://semgrep.dev/docs/semgrep-ci/sample-ci-configs#sample-github-actions-configuration-file
#
# CLI Reference:
# https://semgrep.dev/docs/cli-reference
semgrep:
runs-on: ubuntu-latest
container:
Expand All @@ -14,7 +17,7 @@ jobs:
security-events: write
steps:
- uses: actions/checkout@v4
- run: semgrep scan --sarif --output=semgrep.sarif --error
- run: semgrep scan --sarif --output=semgrep.sarif --error --severity=WARNING
env:
SEMGREP_RULES: >-
p/bandit
Expand Down Expand Up @@ -54,7 +57,7 @@ jobs:
format: 'sarif'
output: 'trivy.sarif'
exit-code: '1'
severity: 'CRITICAL,HIGH'
severity: 'MEDIUM,CRITICAL,HIGH'
- uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: trivy.sarif
Expand Down
2 changes: 2 additions & 0 deletions .semgrepignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
env.example.bat
env.example.sh
2 changes: 0 additions & 2 deletions selvpcclient/resources/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ def delete_many(self, token_ids, raise_if_not_found=True):
for token_id in token_ids:
try:
self.delete(token_id)
log.info("Token %s has been deleted", token_id)
except ClientException as err:
if raise_if_not_found:
raise err
log.error("%s %s", err, token_id)
10 changes: 6 additions & 4 deletions selvpcclient/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ def make_curl(url, method, data):
v = str()
if value:
v = value.encode('utf-8')
h = hashlib.sha1(v)
h = hashlib.sha256(v)
d = h.hexdigest()
value = "{SHA1}%s" % d
header = ' -H "%s: %s"' % (key, value)
Expand All @@ -225,15 +225,17 @@ def make_curl(url, method, data):
def is_url(data):
"""Checks if getting value is valid url and path exists."""
try:
r = requests.head(data)
except Exception:
r = requests.head(data, timeout=15)
r.raise_for_status()
except requests.RequestException:
return False
return r.status_code == requests.codes.ok


def process_logo_by_url(url):
"""Download and encode image by url."""
res = requests.get(url)
res = requests.get(url, timeout=15)
res.raise_for_status()
encoded_logo = base64.b64encode(res.content)
return encoded_logo

Expand Down
4 changes: 3 additions & 1 deletion tests/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import json

import mock
from unittest import mock

from selvpcclient.client import Client
from selvpcclient.shell import CLI


# nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
def prepare_to_run_command(cmd):
pass

Expand Down
3 changes: 1 addition & 2 deletions tests/rest/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import mock

from datetime import datetime, timedelta
from unittest import mock

from selvpcclient.httpclient import HTTPClient, RegionalHTTPClient

Expand Down
2 changes: 2 additions & 0 deletions tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def function_that_takes_theme_params(logo=None, color=""):


def test_process_theme_params_invalid_logo():
# nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
@process_theme_params
def function_that_takes_theme_params(logo=None, color=''):
pass
Expand All @@ -105,6 +106,7 @@ def function_that_takes_theme_params(logo=None, color=''):


def test_process_theme_params_wrong_path():
# nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
@process_theme_params
def function_that_takes_theme_params(logo=None, color=''):
pass
Expand Down

0 comments on commit 7c5031a

Please sign in to comment.