import sys
import glob
import datetime
+import warnings
# Third party modules
import six
import yaml
+import requests
from six import StringIO
from six.moves import configparser
from .app import PpApplication
-__version__ = '0.5.2'
+__version__ = '0.6.1'
LOG = logging.getLogger(__name__)
dev_null = os.sep + os.path.join('dev', 'null')
+ default_forge_uri = 'https://forgeapi.puppet.com/v3/modules'
+ default_http_timeout = 30
+
# -------------------------------------------------------------------------
def __init__(
self, appname=None, verbose=0, version=__version__, base_dir=None,
self.dependencies = []
self.rev_dep = {}
self.no_write = False
+ self.forge_uri = self.default_forge_uri
+ self.http_timeout = self.default_http_timeout
super(CheckPuppetEnvApp, self).__init__(
appname=appname, verbose=verbose, version=version, base_dir=base_dir,
help="Do not generate output files.",
)
+ self.arg_parser.add_argument(
+ '--forge-uri', metavar="URL", dest='forge_uri',
+ help="URL of the Puppetforge-API-Server, default: {!r}".format(
+ self.default_forge_uri)
+ )
+
+ self.arg_parser.add_argument(
+ '-T', '--timeout', '--http-timeout',
+ metavar="SECS", dest='http_timeout', type=int,
+ help=(
+ "Timeout for requesting current version of a module from Puppetforge, "
+ "default: {} seconds.").format(self.default_http_timeout)
+ )
+
# -------------------------------------------------------------------------
def perform_arg_parser(self):
self.puppet_root_env_dir = puppet_root_env_dir
+ if self.args.forge_uri:
+ self.forge_uri = self.args.forge_uri
+ if self.args.http_timeout:
+ self.http_timeout = self.args.http_timeout
+
self._init_puppet_environments()
self.env_name = self.args.env
self.env_dir = os.path.join(self.puppet_root_env_dir, self.env_name)
if module_info:
base_name = module_info['base_name']
self.modules[base_name] = module_info
+ upstream_version = self.get_upstream_version(module_info)
if self.verbose > 2:
LOG.debug("Found module information:\n{}".format(pp(self.modules)))
+ # -------------------------------------------------------------------------
+ def get_upstream_version(self, module_info):
+
+ version = None
+
+ url = "{url}/{user}-{module}".format(
+ url=self.forge_uri, user=module_info['vendor'], module=module_info['base_name'])
+
+ LOG.debug((
+ "Trying to get current version of module {user}-{module} from Puppet forge.").format(
+ user=module_info['vendor'], module=module_info['base_name']))
+ if self.verbose > 2:
+ LOG.debug("URL to request: {}".format(url))
+
+ session = requests.Session()
+ with warnings.catch_warnings(record=True) as w:
+ warnings.simplefilter("always")
+ response = session.request('GET', url, timeout=self.http_timeout)
+ if w:
+ warn_class = w[-1].category.__name__
+ warn_msg = '{}: {}'.format(
+ warn_class, w[-1].message)
+ if warn_class == 'SubjectAltNameWarning':
+ LOG.debug(warn_msg)
+ else:
+ LOG.warn(warn_msg)
+
+ LOG.debug("Got status code: {}.".format(response.status_code))
+ if response.ok:
+ if response.text:
+ msg = "Output:\n{}".format(response.text)
+ else:
+ msg = "No output."
+ LOG.info(msg)
+ #self.print_out(msg)
+ return version
+
+ return version
+
# -------------------------------------------------------------------------
def get_module_info(self, module_dir):