Commit 9a26a63a authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon
Browse files

Removed logger from the context

parent fde6bb72
......@@ -21,7 +21,7 @@ CONFIG_DEFAULTS = {
class Base(object):
def __init__(self, extra_args=None):
self.logger = logging.getLogger()
self.logger = logging.getLogger('fts3')
# Common CLI options
usage = None
......@@ -10,16 +10,18 @@ import sys
from exceptions import *
from request import RequestFactory
log = logging.getLogger(__name__)
# Return a list of certificates from the file
def _get_x509_list(cert, logger):
def _get_x509_list(cert):
x509_list = []
fd = BIO.openfile(cert, 'rb')
cert = X509.load_cert_bio(fd)
while True:
logger.debug("Loaded " + cert.get_subject().as_text())
log.debug("Loaded " + cert.get_subject().as_text())
cert = X509.load_cert_bio(fd)
except X509.X509Error:
# When there are no more certs, this is what we get, so it is fine
......@@ -32,12 +34,6 @@ def _get_x509_list(cert, logger):
# Base class for actors
class Context(object):
def _set_logger(self, logger):
if logger:
self.logger = logger
self.logger = logging.getLogger()
def _read_passwd_from_stdin(self, *args, **kwargs):
if not self.passwd:
self.passwd = getpass.getpass('Private key password: ')
......@@ -59,7 +55,7 @@ class Context(object):
ucert = os.environ['X509_USER_CERT']
if ucert and ukey:
self.x509_list = _get_x509_list(ucert, self.logger)
self.x509_list = _get_x509_list(ucert)
self.x509 = self.x509_list[0]
not_after = self.x509.get_not_after()
if not_after.get_datetime() <
......@@ -101,19 +97,18 @@ class Context(object):
raise BadEndpoint("%s (%s)" % (self.endpoint, str(e))), None, sys.exc_info()[2]
return endpoint_info
def __init__(self, endpoint, ucert=None, ukey=None, logger=None):
def __init__(self, endpoint, ucert=None, ukey=None):
self.passwd = None
self._set_x509(ucert, ukey)
self._requester = RequestFactory(self.ucert, self.ukey, passwd=self.passwd)
self.endpoint_info = self._validate_endpoint()
# Log obtained information
self.logger.debug("Using endpoint: %s" % self.endpoint_info['url'])
self.logger.debug("REST API version: %(major)d.%(minor)d.%(patch)d" % self.endpoint_info['api'])
self.logger.debug("Schema version: %(major)d.%(minor)d.%(patch)d" % self.endpoint_info['schema'])
self.logger.debug("Delegation version: %(major)d.%(minor)d.%(patch)d" % self.endpoint_info['delegation'])
log.debug("Using endpoint: %s" % self.endpoint_info['url'])
log.debug("REST API version: %(major)d.%(minor)d.%(patch)d" % self.endpoint_info['api'])
log.debug("Schema version: %(major)d.%(minor)d.%(patch)d" % self.endpoint_info['schema'])
log.debug("Delegation version: %(major)d.%(minor)d.%(patch)d" % self.endpoint_info['delegation'])
def get_endpoint_info(self):
return self.endpoint_info
......@@ -3,12 +3,15 @@ from M2Crypto import X509, ASN1, m2
from M2Crypto.ASN1 import UTC
import ctypes
import json
import logging
import platform
import sys
import time
from exceptions import *
log = logging.getLogger(__name__)
# See
# for an explanation on all this mess
# TL;DR: M2Crypto fails to properly initialize the internal structure, which
......@@ -135,7 +138,7 @@ class Delegator(object):
# Extensions are broken in SL5!!
if _m2crypto_extensions_broken():
self.context.logger.warning("X509v3 extensions disabled!")
log.warning("X509v3 extensions disabled!")
# X509v3 Basic Constraints
proxy.add_ext(X509.new_extension('basicConstraints', 'CA:FALSE', critical=True))
......@@ -194,27 +197,27 @@ class Delegator(object):
def delegate(self, lifetime=timedelta(hours=7), force=False):
delegation_id = self._get_delegation_id()
self.context.logger.debug("Delegation ID: " + delegation_id)
log.debug("Delegation ID: " + delegation_id)
remaining_life = self._get_remaining_life(delegation_id)
if remaining_life is None:
self.context.logger.debug("No previous delegation found")
log.debug("No previous delegation found")
elif remaining_life <= timedelta(0):
self.context.logger.debug("The delegated credentials expired")
log.debug("The delegated credentials expired")
elif remaining_life >= timedelta(hours=1):
if not force:
self.context.logger.debug("Not bothering doing the delegation")
log.debug("Not bothering doing the delegation")
return delegation_id
self.context.logger.debug("Delegation not expired, but this is a forced delegation")
log.debug("Delegation not expired, but this is a forced delegation")
# Ask for the request
x509_request = self._get_proxy_request(delegation_id)
# Sign request
self.context.logger.debug("Signing request")
log.debug("Signing request")
x509_proxy = self._sign_request(x509_request, lifetime)
x509_proxy_pem = self._full_proxy_chain(x509_proxy)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment