Resolves Bandit 101 errors from misusing asserts
From Bandit's docs: It was discovered that some projects used assert to enforce interface constraints. However, assert is removed with compiling to optimised byte coden (python -o producing *.pyo files). This caused various protections to be removed. The use of assert is also considered as general bad practice in OpenStack codebases. Change-Id: Ie2b5e9cc3e1afcf9e9bd0f8675947754fa1e4b7d
This commit is contained in:
parent
89dfec7b4c
commit
8a39a6fd17
@ -36,13 +36,11 @@ LOG = logging.getLogger(__name__)
|
||||
class FormationPlugin(BaseDataSourcePlugin):
|
||||
def __init__(self, region):
|
||||
# Save site name is valid
|
||||
try:
|
||||
assert region is not None
|
||||
super().__init__(region)
|
||||
except AssertionError:
|
||||
if not region:
|
||||
LOG.error("Site: None! Spyglass exited!")
|
||||
LOG.info("Check spyglass --help for details")
|
||||
exit()
|
||||
super().__init__(region)
|
||||
|
||||
self.source_type = "rest"
|
||||
self.source_name = "formation"
|
||||
@ -80,23 +78,21 @@ class FormationPlugin(BaseDataSourcePlugin):
|
||||
|
||||
def get_plugin_conf(self, kwargs):
|
||||
""" Validates the plugin param and return if success"""
|
||||
try:
|
||||
assert (
|
||||
kwargs["formation_url"]
|
||||
) is not None, "formation_url is Not Specified"
|
||||
url = kwargs["formation_url"]
|
||||
assert (
|
||||
kwargs["formation_user"]
|
||||
) is not None, "formation_user is Not Specified"
|
||||
user = kwargs["formation_user"]
|
||||
assert (
|
||||
kwargs["formation_password"]
|
||||
) is not None, "formation_password is Not Specified"
|
||||
password = kwargs["formation_password"]
|
||||
except AssertionError:
|
||||
LOG.error("Insufficient plugin parameter! Spyglass exited!")
|
||||
raise
|
||||
|
||||
if not kwargs["formation_url"]:
|
||||
LOG.error("formation_url not specified! Spyglass exited!")
|
||||
exit()
|
||||
url = kwargs["formation_url"]
|
||||
|
||||
if not kwargs["formation_user"]:
|
||||
LOG.error("formation_user not specified! Spyglass exited!")
|
||||
exit()
|
||||
user = kwargs["formation_user"]
|
||||
|
||||
if not kwargs["formation_password"]:
|
||||
LOG.error("formation_password not specified! Spyglass exited!")
|
||||
exit()
|
||||
password = kwargs['formation_password']
|
||||
|
||||
plugin_conf = {"url": url, "user": user, "password": password}
|
||||
return plugin_conf
|
||||
|
@ -68,16 +68,14 @@ class TugboatPlugin(BaseDataSourcePlugin):
|
||||
and excel specs are not specified. The below code has been
|
||||
written as an additional safeguard.
|
||||
"""
|
||||
try:
|
||||
assert len(kwargs["excel"]), "Engineering Spec file not specified"
|
||||
excel_file_info = kwargs["excel"]
|
||||
assert (
|
||||
kwargs["excel_spec"]
|
||||
) is not None, "Excel Spec file not specified"
|
||||
excel_spec_info = kwargs["excel_spec"]
|
||||
except AssertionError as e:
|
||||
LOG.error("{}:Spyglass exited!".format(e))
|
||||
if not kwargs["excel"]:
|
||||
LOG.error("Engineering excel file not specified: Spyglass exited!")
|
||||
exit()
|
||||
excel_file_info = kwargs["excel"]
|
||||
if not kwargs["excel_spec"]:
|
||||
LOG.error("Engineering spec file not specified: Spyglass exited!")
|
||||
exit()
|
||||
excel_spec_info = kwargs["excel_spec"]
|
||||
plugin_conf = {
|
||||
"excel_path": excel_file_info,
|
||||
"excel_spec": excel_spec_info,
|
||||
|
Loading…
x
Reference in New Issue
Block a user