Skip to content

Commit

Permalink
Fix for issues reported by semgrep tool in pentesting report (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuragsharma-123 authored Nov 20, 2024
1 parent 97ad88d commit 98d8c44
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 53 deletions.
90 changes: 47 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Always prefer setuptools over distutils
from codecs import open
from codecs import open as codecs_open
from os import path

import sys
Expand All @@ -12,12 +12,16 @@
here = path.abspath(path.dirname(__file__))

# Get the long description from the README.md file
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
with codecs_open(path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = f.read()

version = {}
with open("spotinst_sdk2/version.py") as fp:
exec(fp.read(), version)
with codecs_open("spotinst_sdk2/version.py", encoding='utf-8') as fp:
for line in fp:
if line.startswith("__version__"):
delim = '"' if '"' in line else "'"
version['__version__'] = line.split(delim)[1]
break

setup(
name='spotinst-sdk2',
Expand Down Expand Up @@ -53,46 +57,46 @@

keywords='spotinst spot instances aws azure ec2 cloud infrastructure development elastigroup',
packages=[
"spotinst_sdk2",
"spotinst_sdk2.clients",
"spotinst_sdk2.clients.admin",
"spotinst_sdk2.clients.elastigroup",
"spotinst_sdk2.clients.functions",
"spotinst_sdk2.clients.hpc",
"spotinst_sdk2.clients.mcs",
"spotinst_sdk2.clients.mrscaler",
"spotinst_sdk2.clients.ocean",
"spotinst_sdk2.clients.ocean_cd",
"spotinst_sdk2.clients.subscription",
"spotinst_sdk2.clients.setup",
"spotinst_sdk2.clients.managed_instance",
"spotinst_sdk2.clients.stateful_node",
"spotinst_sdk2",
"spotinst_sdk2.clients",
"spotinst_sdk2.clients.admin",
"spotinst_sdk2.clients.elastigroup",
"spotinst_sdk2.clients.functions",
"spotinst_sdk2.clients.hpc",
"spotinst_sdk2.clients.mcs",
"spotinst_sdk2.clients.mrscaler",
"spotinst_sdk2.clients.ocean",
"spotinst_sdk2.clients.ocean_cd",
"spotinst_sdk2.clients.subscription",
"spotinst_sdk2.clients.setup",
"spotinst_sdk2.clients.managed_instance",
"spotinst_sdk2.clients.stateful_node",
"spotinst_sdk2.models",
"spotinst_sdk2.models.admin",
"spotinst_sdk2.models.elastigroup",
"spotinst_sdk2.models.elastigroup.aws",
"spotinst_sdk2.models.elastigroup.azure_v3",
"spotinst_sdk2.models.elastigroup.gcp",
"spotinst_sdk2.models.functions",
"spotinst_sdk2.models.hpc",
"spotinst_sdk2.models.hpc.aws",
"spotinst_sdk2.models.mrscaler",
"spotinst_sdk2.models.mrscaler.aws",
"spotinst_sdk2.models.ocean",
"spotinst_sdk2.models.ocean.aws",
"spotinst_sdk2.models.ocean.azure",
"spotinst_sdk2.models.ocean.gcp",
"spotinst_sdk2.models.ocean.ecs",
"spotinst_sdk2.models.ocean.rightsizing",
"spotinst_sdk2.models.ocean_cd",
"spotinst_sdk2.models.ocean_cd",
"spotinst_sdk2.models.setup",
"spotinst_sdk2.models.setup.azure",
"spotinst_sdk2.models.setup.gcp",
"spotinst_sdk2.models.subscription",
"spotinst_sdk2.models.managed_instance",
"spotinst_sdk2.models.managed_instance.aws",
"spotinst_sdk2.models.stateful_node"
"spotinst_sdk2.models.admin",
"spotinst_sdk2.models.elastigroup",
"spotinst_sdk2.models.elastigroup.aws",
"spotinst_sdk2.models.elastigroup.azure_v3",
"spotinst_sdk2.models.elastigroup.gcp",
"spotinst_sdk2.models.functions",
"spotinst_sdk2.models.hpc",
"spotinst_sdk2.models.hpc.aws",
"spotinst_sdk2.models.mrscaler",
"spotinst_sdk2.models.mrscaler.aws",
"spotinst_sdk2.models.ocean",
"spotinst_sdk2.models.ocean.aws",
"spotinst_sdk2.models.ocean.azure",
"spotinst_sdk2.models.ocean.gcp",
"spotinst_sdk2.models.ocean.ecs",
"spotinst_sdk2.models.ocean.rightsizing",
"spotinst_sdk2.models.ocean_cd",
"spotinst_sdk2.models.ocean_cd",
"spotinst_sdk2.models.setup",
"spotinst_sdk2.models.setup.azure",
"spotinst_sdk2.models.setup.gcp",
"spotinst_sdk2.models.subscription",
"spotinst_sdk2.models.managed_instance",
"spotinst_sdk2.models.managed_instance.aws",
"spotinst_sdk2.models.stateful_node"
],
install_requires=['requests', 'PyYaml'],

Expand Down
9 changes: 4 additions & 5 deletions spotinst_sdk2/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@

import logging
import requests

from .version import __version__

VAR_SPOTINST_LOG_LEVEL = 'SPOTINST_LOG_LEVEL'

version = {}
with open(os.path.join(os.path.dirname(__file__), "./version.py")) as fp:
exec(fp.read(), version)

version = {'__version__': __version__}

_SpotinstClient__spotinst_sdk_python_agent_name = 'spotinst-sdk-python'
_SpotinstClient__spotinst_sdk_user_agent = '{}/{}'.format(
Expand Down Expand Up @@ -406,7 +405,7 @@ def print_output(self, output, level="debug"):
if level == "info":
self.logger.info(output)
if level == "warn":
self.logger.warn(output)
self.logger.warning(output)
if level == "error":
self.logger.error(output)
if level == "critical":
Expand Down
6 changes: 3 additions & 3 deletions spotinst_sdk2/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_credentials(self, profile, credentials_file):
VAR_SPOTINST_SHARED_CREDENTIALS_FILE,
DEFAULT_CREDENTIALS_FILE)

with open(credentials_file, 'r') as credentials_file:
with open(credentials_file, 'r', encoding='utf-8') as credentials_file:
self.__load_credentials_yaml(profile, credentials_file)
if not self.auth_token:
self.__load_credentials_ini(profile, credentials_file)
Expand All @@ -60,7 +60,7 @@ def __load_credentials_yaml(self, profile, credentials_file):
if config:
self.account_id = config.get(profile, {}).get("account", None)
self.auth_token = config.get(profile, {}).get("token", None)
except:
except (yaml.YAMLError, KeyError):
return

def __load_credentials_ini(self, profile, credentials_file):
Expand All @@ -70,5 +70,5 @@ def __load_credentials_ini(self, profile, credentials_file):
if config[profile]:
self.account_id = config[profile]["account"]
self.auth_token = config[profile]["token"]
except:
except (configparser.NoSectionError, configparser.NoOptionError):
return
3 changes: 1 addition & 2 deletions spotinst_sdk2/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
__version__ = '3.19.0'

__version__ = '3.20.0'

0 comments on commit 98d8c44

Please sign in to comment.