Exemplo n.º 1
0
def check_basic_auth():
    '''
    :return: boolean
    '''

    try:
        if pecan.request.headers['Authorization'] and verify_user(
                pecan.request.headers['Authorization']):
            LOG.debug("Authorized username and password")
            plan = True
        else:
            plan = False
            auth_str = pecan.request.headers['Authorization']
            user_pw = auth_str.split(' ')[1]
            decode_user_pw = base64.b64decode(user_pw)
            list_id_pw = decode_user_pw.split(':')
            LOG.error("Incorrect username={} / password={}".format(
                list_id_pw[0], list_id_pw[1]))
    except:
        error(
            '/errors/basic_auth_error',
            _('Unauthorized: The request does not provide any HTTP authentication (basic authetnication)'
              ))

    if not plan:
        error('/errors/authentication_error',
              _('Invalid credentials: username or password is incorrect'))
    return plan
Exemplo n.º 2
0
def check_auth():
    """
    Returns True/False if the username/password of Basic Auth match/not match
    Will also check role-based access controls if AAF integration configured
    :return boolean value
    """

    try:
        if pecan.request.headers['Authorization'] and verify_user(
                pecan.request.headers['Authorization']):
            LOG.debug("Authorized username and password")
            plan = True
        else:
            plan = False
            auth_str = pecan.request.headers['Authorization']
            user_pw = auth_str.split(' ')[1]
            decode_user_pw = base64.b64decode(user_pw)
            list_id_pw = decode_user_pw.split(':')
            LOG.error("Incorrect username={} / password={}".format(
                list_id_pw[0], list_id_pw[1]))
    except:
        error(
            '/errors/basic_auth_error',
            _('Unauthorized: The request does not '
              'provide any HTTP authentication (basic authentication)'))
        plan = False

    if not plan:
        error('/errors/authentication_error',
              _('Invalid credentials: username or password is incorrect'))

    return plan
Exemplo n.º 3
0
    def __init__(self, uuid4):
        """Initializer."""
        self.uuid = uuid4
        self.plan = self.plans_get(plan_id=self.uuid)

        if not self.plan:
            error('/errors/not_found',
                  _('Plan {} not found').format(self.uuid))
        pecan.request.context['plan_id'] = self.uuid
Exemplo n.º 4
0
    def __init__(self, uuid4):
        """Initializer."""
        self.uuid = uuid4
        self.triage = self.triage_get(id=self.uuid)

        if not self.triage:
            error('/errors/not_found',
                  _('DAta {} not found').format(self.uuid))
        pecan.request.context['id'] = self.uuid
Exemplo n.º 5
0
    def index_post(self):

        args = pecan.request.json

        if check_basic_auth():
            response = self.load(args)
        if not response:
            error('/errors/server_error', _('Unable to insert'))
        else:
            pecan.response.status = 201
            return response
Exemplo n.º 6
0
    def index_post(self):

        args = pecan.request.json

        if check_basic_auth():
            response = self.test_rule(args)
        if not response:
            error('/errors/server_error', _('Unable to release orders'))
        else:
            pecan.response.status = 201
            return response
Exemplo n.º 7
0
    def index_post(self):
        """Create a Plan"""

        # Look for duplicate keys in the YAML/JSON, first in the
        # entire request, and then again if the template parameter
        # value is itself an embedded JSON/YAML string.
        where = "API Request"
        try:
            parsed = yaml.load(pecan.request.text, validator.UniqueKeyLoader)
            if 'template' in parsed:
                where = "Template"
                template = parsed['template']
                if isinstance(template, six.string_types):
                    yaml.load(template, validator.UniqueKeyLoader)
        except ConstructorError as exc:
            # Only bail on the duplicate key problem (problem and problem_mark
            # attributes are available in ConstructorError):
            if exc.problem is \
                    validator.UniqueKeyLoader.DUPLICATE_KEY_PROBLEM_MARK:
                # ConstructorError messages have a two line snippet.
                # Grab it, get rid of the second line, and strip any
                # remaining whitespace so we can fashion a one line msg.
                snippet = exc.problem_mark.get_snippet()
                snippet = snippet.split('\n')[0].strip()
                msg = _('{} has a duplicate key on line {}: {}')
                error('/errors/invalid',
                      msg.format(where, exc.problem_mark.line + 1, snippet))
        except Exception as exc:
            # Let all others pass through for now.
            pass

        args = pecan.request.json

        # Print request id from SNIOR at the beginning of API component
        if args and args['name']:
            LOG.info('Plan name: {}'.format(args['name']))

        auth_flag = CONF.conductor_api.basic_auth_secure or CONF.aaf_api.is_aaf_enabled

        # Create the plan only when the basic authentication is disabled or pass the authenticaiton check
        if not auth_flag or \
                (auth_flag and check_auth()):
            plan = self.plan_create(args)

        if not plan:
            error('/errors/server_error', _('Unable to create Plan.'))
        else:
            pecan.response.status = 201
            return plan
Exemplo n.º 8
0
 def index(self):
     """Catchall for unallowed methods"""
     message = _('The {} method is not allowed.').format(
         pecan.request.method)
     kwargs = {'allow': self.allow()}
     error('/errors/not_allowed', message, **kwargs)
Exemplo n.º 9
0
 def index(self):
     """Catchall for unallowed methods"""
     message = _('The %s method is not allowed.') % pecan.request.method
     kwargs = {}
     error('/errors/not_allowed', message, **kwargs)