From 27721a86326caa7c6f8d7acf352ff704a92cffb1 Mon Sep 17 00:00:00 2001 From: Sam Chow Date: Tue, 12 Jun 2018 13:31:26 -0400 Subject: [PATCH] Add docker shell mode, and remove some config --- config_app/conf/logging.conf | 3 - config_app/conf/logging_debug.conf | 3 - config_app/conf/logging_debug_json.conf | 3 - config_app/conf/logging_json.conf | 3 - config_app/loghandler_config.py | 114 --------------------- config_app/templates/index.html | 10 -- quay-entrypoint.sh | 7 +- util/config/validators/validate_torrent.py | 2 + 8 files changed, 8 insertions(+), 137 deletions(-) delete mode 100755 config_app/loghandler_config.py diff --git a/config_app/conf/logging.conf b/config_app/conf/logging.conf index 885678395..3f1d3a33f 100644 --- a/config_app/conf/logging.conf +++ b/config_app/conf/logging.conf @@ -20,9 +20,6 @@ args=(sys.stdout, ) format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s class=logging.Formatter -[formatter_json] -class=loghandler_config.JsonFormatter - [logger_gunicorn.error] level=ERROR handlers=console diff --git a/config_app/conf/logging_debug.conf b/config_app/conf/logging_debug.conf index 1f1bb2c63..b57ff1519 100644 --- a/config_app/conf/logging_debug.conf +++ b/config_app/conf/logging_debug.conf @@ -36,6 +36,3 @@ qualname=gunicorn.error [formatter_generic] format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s class=logging.Formatter - -[formatter_json] -class=loghandler_config.JsonFormatter diff --git a/config_app/conf/logging_debug_json.conf b/config_app/conf/logging_debug_json.conf index 382f882d1..21eb994a8 100644 --- a/config_app/conf/logging_debug_json.conf +++ b/config_app/conf/logging_debug_json.conf @@ -36,6 +36,3 @@ qualname=gunicorn.error [formatter_generic] format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s class=logging.Formatter - -[formatter_json] -class=loghandler_config.JsonFormatter diff --git a/config_app/conf/logging_json.conf b/config_app/conf/logging_json.conf index cccdcf832..05d4c5dde 100644 --- a/config_app/conf/logging_json.conf +++ b/config_app/conf/logging_json.conf @@ -20,9 +20,6 @@ args=(sys.stdout, ) format=%(asctime)s [%(process)d] [%(levelname)s] [%(name)s] %(message)s class=logging.Formatter -[formatter_json] -class=loghandler_config.JsonFormatter - [logger_gunicorn.error] level=ERROR handlers=console diff --git a/config_app/loghandler_config.py b/config_app/loghandler_config.py deleted file mode 100755 index d3d9948cb..000000000 --- a/config_app/loghandler_config.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -from __future__ import absolute_import - -import datetime -import json -import logging -import re -import traceback - - -LOG_FORMAT_REGEXP = re.compile(r'\((.+?)\)', re.IGNORECASE) - - -def _json_default(obj): - """ - Coerce everything to strings. - All objects representing time get output as ISO8601. - """ - if isinstance(obj, (datetime.date, datetime.time, datetime.datetime)): - return obj.isoformat() - - elif isinstance(obj, Exception): - return "Exception: %s" % str(obj) - - return str(obj) - - -# skip natural LogRecord attributes -# http://docs.python.org/library/logging.html#logrecord-attributes -RESERVED_ATTRS = set([ - 'args', 'asctime', 'created', 'exc_info', 'exc_text', 'filename', 'funcName', 'levelname', - 'levelno', 'lineno', 'module', 'msecs', 'message', 'msg', 'name', 'pathname', 'process', - 'processName', 'relativeCreated', 'stack_info', 'thread', 'threadName' -]) - - -class JsonFormatter(logging.Formatter): - """ - A custom formatter to format logging records as json strings. - extra values will be formatted as str() if nor supported by - json default encoder - """ - - def __init__(self, *args, **kwargs): - """ - :param json_default: a function for encoding non-standard objects - as outlined in http://docs.python.org/2/library/json.html - :param json_encoder: optional custom encoder - :param json_serializer: a :meth:`json.dumps`-compatible callable - that will be used to serialize the log record. - :param prefix: an optional key prefix to nest logs - """ - self.json_default = kwargs.pop("json_default", _json_default) - self.json_encoder = kwargs.pop("json_encoder", None) - self.json_serializer = kwargs.pop("json_serializer", json.dumps) - self.default_values = kwargs.pop("default_extra", {}) - self.prefix_key = kwargs.pop("prefix_key", "data") - - logging.Formatter.__init__(self, *args, **kwargs) - - self._fmt_parameters = self._parse_format_string() - self._skip_fields = set(self._fmt_parameters) - self._skip_fields.update(RESERVED_ATTRS) - - def _parse_format_string(self): - """Parses format string looking for substitutions""" - standard_formatters = LOG_FORMAT_REGEXP - return standard_formatters.findall(self._fmt) - - def add_fields(self, log_record, record, message_dict): - """ - Override this method to implement custom logic for adding fields. - """ - - target = log_record - if self.prefix_key: - log_record[self.prefix_key] = {} - target = log_record[self.prefix_key] - - for field, value in record.__dict__.iteritems(): - if field in self._fmt_parameters and field in RESERVED_ATTRS: - log_record[field] = value - elif field not in RESERVED_ATTRS: - target[field] = value - - target.update(message_dict) - target.update(self.default_values) - - def format(self, record): - """Formats a log record and serializes to json""" - message_dict = {} - if isinstance(record.msg, dict): - message_dict = record.msg - record.message = None - if "message" in message_dict: - record.message = message_dict.pop("message", "") - else: - record.message = record.getMessage() - - # only format time if needed - if "asctime" in self._fmt_parameters: - record.asctime = self.formatTime(record, self.datefmt) - - # Display formatted exception, but allow overriding it in the - # user-supplied dict. - if record.exc_info and not message_dict.get('exc_info'): - message_dict['exc_info'] = traceback.format_list(traceback.extract_tb(record.exc_info[2])) - log_record = {} - - self.add_fields(log_record, record, message_dict) - - return self.json_serializer(log_record, default=self.json_default, cls=self.json_encoder) diff --git a/config_app/templates/index.html b/config_app/templates/index.html index 7a40e3d30..2ec95f8b8 100644 --- a/config_app/templates/index.html +++ b/config_app/templates/index.html @@ -19,19 +19,9 @@ - - - - - - - - - - {% for script_path in main_scripts %} diff --git a/quay-entrypoint.sh b/quay-entrypoint.sh index 9e9a60fe5..24c58b500 100755 --- a/quay-entrypoint.sh +++ b/quay-entrypoint.sh @@ -4,7 +4,7 @@ MODE="$1" display_usage() { echo "This script takes one argument." - echo -e "\nUsage: ${0} \n" + echo -e "\nUsage: ${0} \n" } if [[ "${MODE}" = "help" ]] @@ -32,6 +32,11 @@ EOF venv/bin/python -m displayversion case "$MODE" in + "shell") + echo "Entering shell mode" + /bin/bash + exit 0 + ;; "config") echo "Entering config mode, only copying config-app entrypoints" cp -r ${QUAYDIR}/config_app/init/service/* /etc/service diff --git a/util/config/validators/validate_torrent.py b/util/config/validators/validate_torrent.py index dce091efa..567285f0b 100644 --- a/util/config/validators/validate_torrent.py +++ b/util/config/validators/validate_torrent.py @@ -3,6 +3,8 @@ import logging from hashlib import sha1 from util.config.validators import BaseValidator, ConfigValidationException +# Temporarily removed because registry.torrent imports from app, add encoded_jwt back once extracted +# TODO(jschorr): extract app from following package and re-enable jwt_from_infohash in validator # from util.registry.torrent import jwt_from_infohash logger = logging.getLogger(__name__)