Add hacking extension
This patch set adds hacking rule to pegleg and fixes outstanding non- docstring related violations. Change-Id: I5bb5e78c211f24cf95669124bfcf9603bea8bf15 Signed-off-by: Tin Lam <tin@irrational.io>
This commit is contained in:
parent
213ca596e3
commit
1a325a400b
@ -216,7 +216,7 @@ def _verify_file_contents(*, sitename=None):
|
|||||||
|
|
||||||
def _verify_single_file(filename, schemas):
|
def _verify_single_file(filename, schemas):
|
||||||
errors = []
|
errors = []
|
||||||
LOG.debug("Validating file %s." % filename)
|
LOG.debug("Validating file %s.", filename)
|
||||||
with open(filename) as f:
|
with open(filename) as f:
|
||||||
if not f.read(4) == '---\n':
|
if not f.read(4) == '---\n':
|
||||||
errors.append((FILE_MISSING_YAML_DOCUMENT_HEADER,
|
errors.append((FILE_MISSING_YAML_DOCUMENT_HEADER,
|
||||||
|
@ -196,7 +196,7 @@ def _get_and_validate_site_repositories(site_name, site_data):
|
|||||||
LOG.info("The repository for site_name: %s does not contain a "
|
LOG.info("The repository for site_name: %s does not contain a "
|
||||||
"site-definition.yaml with a 'repositories' key. Ensure "
|
"site-definition.yaml with a 'repositories' key. Ensure "
|
||||||
"your repository is self-contained and doesn't require "
|
"your repository is self-contained and doesn't require "
|
||||||
"extra repositories for correct rendering." % site_name)
|
"extra repositories for correct rendering.", site_name)
|
||||||
return site_data.get('repositories', {})
|
return site_data.get('repositories', {})
|
||||||
|
|
||||||
|
|
||||||
|
@ -15,9 +15,9 @@
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
|
|
||||||
from pegleg.engine.util import files
|
|
||||||
from pegleg.engine.util import definition
|
from pegleg.engine.util import definition
|
||||||
|
from pegleg.engine.util import files
|
||||||
|
from pegleg.engine.util.pegleg_secret_management import PeglegSecretManagement
|
||||||
|
|
||||||
__all__ = ('encrypt', 'decrypt')
|
__all__ = ('encrypt', 'decrypt')
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ def _collect_to_file(site_name, save_location):
|
|||||||
save_file = os.path.join(save_location, repo_name + '.yaml')
|
save_file = os.path.join(save_location, repo_name + '.yaml')
|
||||||
if repo_name not in save_files:
|
if repo_name not in save_files:
|
||||||
save_files[repo_name] = open(save_file, "w")
|
save_files[repo_name] = open(save_file, "w")
|
||||||
LOG.debug("Collecting file %s to file %s" % (filename, save_file))
|
LOG.debug("Collecting file %s to file %s", filename, save_file)
|
||||||
save_files[repo_name].writelines(_read_and_format_yaml(filename))
|
save_files[repo_name].writelines(_read_and_format_yaml(filename))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
raise click.ClickException("Error saving output: %s" % str(ex))
|
raise click.ClickException("Error saving output: %s" % str(ex))
|
||||||
|
@ -12,11 +12,13 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
|
|
||||||
from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
|
|
||||||
from deckhand.engine import layering
|
from deckhand.engine import layering
|
||||||
from deckhand import errors as dh_errors
|
from deckhand import errors as dh_errors
|
||||||
|
|
||||||
|
from pegleg.engine.errorcodes import DECKHAND_DUPLICATE_SCHEMA
|
||||||
|
from pegleg.engine.errorcodes import DECKHAND_RENDER_EXCEPTION
|
||||||
|
|
||||||
|
|
||||||
def load_schemas_from_docs(documents):
|
def load_schemas_from_docs(documents):
|
||||||
'''
|
'''
|
||||||
|
@ -12,13 +12,14 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
|
||||||
import base64
|
import base64
|
||||||
|
import logging
|
||||||
|
|
||||||
|
from cryptography.exceptions import InvalidSignature
|
||||||
from cryptography.fernet import Fernet
|
from cryptography.fernet import Fernet
|
||||||
from cryptography.hazmat.backends import default_backend
|
from cryptography.hazmat.backends import default_backend
|
||||||
from cryptography.hazmat.primitives import hashes
|
from cryptography.hazmat.primitives import hashes
|
||||||
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
|
||||||
from cryptography.exceptions import InvalidSignature
|
|
||||||
|
|
||||||
KEY_LENGTH = 32
|
KEY_LENGTH = 32
|
||||||
ITERATIONS = 10000
|
ITERATIONS = 10000
|
||||||
|
@ -12,11 +12,12 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import click
|
|
||||||
import collections
|
import collections
|
||||||
import os
|
|
||||||
import yaml
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
|
||||||
|
import click
|
||||||
|
import yaml
|
||||||
|
|
||||||
from pegleg import config
|
from pegleg import config
|
||||||
from pegleg.engine import util
|
from pegleg.engine import util
|
||||||
@ -330,7 +331,7 @@ def search(search_paths):
|
|||||||
search_paths = [search_paths]
|
search_paths = [search_paths]
|
||||||
|
|
||||||
for search_path in search_paths:
|
for search_path in search_paths:
|
||||||
LOG.debug("Recursively collecting YAMLs from %s" % search_path)
|
LOG.debug("Recursively collecting YAMLs from %s", search_path)
|
||||||
for root, _, filenames in os.walk(search_path):
|
for root, _, filenames in os.walk(search_path):
|
||||||
|
|
||||||
# Ignore hidden folders like .tox or .git for faster processing.
|
# Ignore hidden folders like .tox or .git for faster processing.
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import logging
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
import logging
|
||||||
|
|
||||||
PEGLEG_MANAGED_SCHEMA = 'pegleg/PeglegManagedDocument/v1'
|
PEGLEG_MANAGED_SCHEMA = 'pegleg/PeglegManagedDocument/v1'
|
||||||
ENCRYPTED = 'encrypted'
|
ENCRYPTED = 'encrypted'
|
||||||
@ -22,7 +22,7 @@ METADATA = 'metadata'
|
|||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class PeglegManagedSecretsDocument():
|
class PeglegManagedSecretsDocument(object):
|
||||||
"""Object representing one Pegleg managed secret document."""
|
"""Object representing one Pegleg managed secret document."""
|
||||||
|
|
||||||
def __init__(self, secrets_document):
|
def __init__(self, secrets_document):
|
||||||
|
@ -14,16 +14,17 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import yaml
|
|
||||||
import sys
|
|
||||||
import re
|
import re
|
||||||
import click
|
import sys
|
||||||
|
|
||||||
|
import click
|
||||||
|
import yaml
|
||||||
|
|
||||||
from pegleg.engine.util.encryption import encrypt
|
|
||||||
from pegleg.engine.util.encryption import decrypt
|
from pegleg.engine.util.encryption import decrypt
|
||||||
|
from pegleg.engine.util.encryption import encrypt
|
||||||
|
from pegleg.engine.util import files
|
||||||
from pegleg.engine.util.pegleg_managed_document import \
|
from pegleg.engine.util.pegleg_managed_document import \
|
||||||
PeglegManagedSecretsDocument as PeglegManagedSecret
|
PeglegManagedSecretsDocument as PeglegManagedSecret
|
||||||
from pegleg.engine.util import files
|
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
PASSPHRASE_PATTERN = '^.{24,}$'
|
PASSPHRASE_PATTERN = '^.{24,}$'
|
||||||
@ -31,7 +32,7 @@ ENV_PASSPHRASE = 'PEGLEG_PASSPHRASE'
|
|||||||
ENV_SALT = 'PEGLEG_SALT'
|
ENV_SALT = 'PEGLEG_SALT'
|
||||||
|
|
||||||
|
|
||||||
class PeglegSecretManagement():
|
class PeglegSecretManagement(object):
|
||||||
"""An object to handle operations on of a pegleg managed file."""
|
"""An object to handle operations on of a pegleg managed file."""
|
||||||
|
|
||||||
def __init__(self, file_path=None, docs=None):
|
def __init__(self, file_path=None, docs=None):
|
||||||
|
@ -18,8 +18,8 @@ import uuid
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
from pegleg.engine.util import files
|
|
||||||
from pegleg.engine.exceptions import PeglegBaseException
|
from pegleg.engine.exceptions import PeglegBaseException
|
||||||
|
from pegleg.engine.util import files
|
||||||
|
|
||||||
from shipyard_client.api_client.shipyard_api_client import ShipyardClient
|
from shipyard_client.api_client.shipyard_api_client import ShipyardClient
|
||||||
from shipyard_client.api_client.shipyardclient_context import \
|
from shipyard_client.api_client.shipyardclient_context import \
|
||||||
@ -65,7 +65,7 @@ class ShipyardHelper(object):
|
|||||||
self.context_marker = self.ctx.obj['context_marker']
|
self.context_marker = self.ctx.obj['context_marker']
|
||||||
if self.context_marker is None:
|
if self.context_marker is None:
|
||||||
self.context_marker = str(uuid.uuid4())
|
self.context_marker = str(uuid.uuid4())
|
||||||
LOG.debug("context_marker is %s" % self.context_marker)
|
LOG.debug("context_marker is %s", self.context_marker)
|
||||||
self.site_name = self.ctx.obj['site_name']
|
self.site_name = self.ctx.obj['site_name']
|
||||||
self.client_context = ShipyardClientContext(
|
self.client_context = ShipyardClientContext(
|
||||||
self.auth_vars, self.context_marker)
|
self.auth_vars, self.context_marker)
|
||||||
@ -76,7 +76,7 @@ class ShipyardHelper(object):
|
|||||||
|
|
||||||
collected_documents = files.collect_files_by_repo(self.site_name)
|
collected_documents = files.collect_files_by_repo(self.site_name)
|
||||||
|
|
||||||
LOG.info("Uploading %s collection(s) " % len(collected_documents))
|
LOG.info("Uploading %d collection(s) ", len(collected_documents))
|
||||||
for idx, document in enumerate(collected_documents):
|
for idx, document in enumerate(collected_documents):
|
||||||
# Append flag is not required for the first
|
# Append flag is not required for the first
|
||||||
# collection being uploaded to Shipyard. It
|
# collection being uploaded to Shipyard. It
|
||||||
@ -129,7 +129,7 @@ class ShipyardHelper(object):
|
|||||||
raise DocumentUploadError(resp_text)
|
raise DocumentUploadError(resp_text)
|
||||||
else:
|
else:
|
||||||
output = self.formatted_response_handler(resp_text)
|
output = self.formatted_response_handler(resp_text)
|
||||||
LOG.info("Uploaded document in buffer %s " % output)
|
LOG.info("Uploaded document in buffer %s ", output)
|
||||||
|
|
||||||
# Commit in the last iteration of the loop when all the documents
|
# Commit in the last iteration of the loop when all the documents
|
||||||
# have been pushed to Shipyard buffer.
|
# have been pushed to Shipyard buffer.
|
||||||
|
@ -7,7 +7,7 @@ mock==2.0.0
|
|||||||
yapf==0.20.0
|
yapf==0.20.0
|
||||||
|
|
||||||
# Linting
|
# Linting
|
||||||
flake8==3.3.0
|
hacking>=1.1.0,<1.2.0 # Apache-2.0
|
||||||
|
|
||||||
# Security
|
# Security
|
||||||
bandit>=1.5.0
|
bandit>=1.5.0
|
||||||
|
@ -455,8 +455,7 @@ def test_process_repositories_without_repositories_key_in_site_definition(
|
|||||||
_test_process_repositories_inner(
|
_test_process_repositories_inner(
|
||||||
site_name=mock.sentinel.site, expected_extra_repos={})
|
site_name=mock.sentinel.site, expected_extra_repos={})
|
||||||
msg = ("The repository for site_name: %s does not contain a "
|
msg = ("The repository for site_name: %s does not contain a "
|
||||||
"site-definition.yaml with a 'repositories' key" % str(
|
"site-definition.yaml with a 'repositories' key")
|
||||||
mock.sentinel.site))
|
|
||||||
assert any(msg in x[1][0] for x in m_log.info.mock_calls)
|
assert any(msg in x[1][0] for x in m_log.info.mock_calls)
|
||||||
|
|
||||||
|
|
||||||
|
10
tox.ini
10
tox.ini
@ -74,6 +74,14 @@ commands = {posargs}
|
|||||||
[flake8]
|
[flake8]
|
||||||
filename = *.py
|
filename = *.py
|
||||||
show-source = true
|
show-source = true
|
||||||
ignore =
|
# [H106] Don't put vim configuration in source files.
|
||||||
|
# [H210] Require 'autospec', 'spec', or 'spec_set' in mock.patch/mock.patch.object calls
|
||||||
|
# [H904] Delay string interpolations at logging calls.
|
||||||
|
enable-extensions = H106,H201,H904
|
||||||
|
# TODO(lamt) Clean up these docstring violations if possible
|
||||||
|
# [H403] multi line docstrings should end on a new line
|
||||||
|
# [H404] multi line docstring should start without a leading new line
|
||||||
|
# [H405] multi line docstring summary not separated with an empty line
|
||||||
|
ignore = H403,H404,H405
|
||||||
exclude=.venv,.git,.tox,build,dist,*lib/python*,*egg,tools,*.ini,*.po,*.pot
|
exclude=.venv,.git,.tox,build,dist,*lib/python*,*egg,tools,*.ini,*.po,*.pot
|
||||||
max-complexity = 24
|
max-complexity = 24
|
||||||
|
Loading…
x
Reference in New Issue
Block a user