<commit_before>import os
import ConfigParser
import logging
import exceptions

from OpenSSL import crypto

from keystoneclient import session
from keystoneclient.auth.identity import v2 as v2_client
from keystoneclient.auth.identity import v3 as v3_client

from barbicanclient import client

class BarbicanKeystoneSession(object):

    def __init__(self):
        self.admin_user = None
        self.admin_password = <PASSWORD>
        self.project_name = None
        self.auth_url = None
        self.auth_version = '2'
        self.region = 'RegionOne'
        self.session = {}

    def parse_args(self, auth_conf=None):
        config = ConfigParser.SafeConfigParser()
        if (auth_conf):
            self.auth_conf = auth_conf
        else:
            self.auth_conf = '/etc/contrail/contrail-lbaas-auth.conf'
        config.read(self.auth_conf)

        self.admin_user = config.get('BARBICAN', 'admin_user')
        self.admin_password = config.get('<PASSWORD>', '<PASSWORD>')
        self.project_name = config.get('BARBICAN', 'admin_tenant_name')

        self.auth_url = config.get('BARBICAN', 'auth_url')
        tmp_auth_url = self.auth_url
        if (tmp_auth_url[-1] == '/'):
            tmp_auth_url[:-1]
        auth_version = tmp_auth_url.split('/')[-1]
        if (auth_version.lower() == 'v2.0'):
            self.auth_version = '2'
        elif (auth_version.lower() == 'v3.0'):
            self.auth_version = '3'
            self.admin_user_domain = config.get('BARBICAN', 'admin_user_domain')
            self.admin_project_domain = config.get('BARBICAN', 'admin_project_domain')

        try:
            self.region = config.get('BARBICAN', 'region')
        except Exception:
            pass

    def get_session(self, auth_conf=None):
        if self.session.get(self.project_name):
            return self.session[self.project_name]

        self.parse_args(auth_conf)
        kwargs = {'auth_url': self.auth_url,
                  'username': self.admin_user,
                  'password': <PASSWORD>}

        if self.auth_version == '2':
            client = v2_client
            kwargs['tenant_name'] = self.project_name
        elif self.auth_version == '3':
            client = v3_client
            kwargs['project_name'] = self.project_name
            kwargs['user_domain_name'] = self.admin_user_domain
            kwargs['project_domain_name'] = self.admin_project_domain

        try:
            kc = client.Password(**kwargs)<commit_msg>lbaas v2 bug fix in barbican cert manager<commit_after>import os
import ConfigParser
import logging
import exceptions

from OpenSSL import crypto

from keystoneclient import session
from keystoneclient.auth.identity import v2 as v2_client
from keystoneclient.auth.identity import v3 as v3_client

from barbicanclient import client

class BarbicanKeystoneSession(object):

    def __init__(self):
        self.admin_user = None
        self.admin_password = <PASSWORD>
        self.project_name = None
        self.auth_url = None
        self.auth_version = '2'
        self.region = 'RegionOne'
        self.session = {}

    def parse_args(self, auth_conf=None):
        config = ConfigParser.SafeConfigParser()
        if (auth_conf):
            self.auth_conf = auth_conf
        else:
            self.auth_conf = '/etc/contrail/contrail-lbaas-auth.conf'
        config.read(self.auth_conf)

        self.admin_user = config.get('BARBICAN', 'admin_user')
        self.admin_password = config.get('B<PASSWORD>AN', '<PASSWORD>')
        self.project_name = config.get('BARBICAN', 'admin_tenant_name')

        self.auth_url = config.get('BARBICAN', 'auth_url')
        tmp_auth_url = self.auth_url
        if (tmp_auth_url[-1] == '/'):
            tmp_auth_url[:-1]
        auth_version = tmp_auth_url.split('/')[-1]
        if (auth_version.lower() == 'v2.0'):
            self.auth_version = '2'
        elif (auth_version.lower() == 'v3'):
            self.auth_version = '3'
            self.admin_user_domain = config.get('BARBICAN', 'admin_user_domain')
            self.admin_project_domain = config.get('BARBICAN', 'admin_project_domain')

        try:
            self.region = config.get('BARBICAN', 'region')
        except Exception:
            pass

    def get_session(self, auth_conf=None):
        if self.session.get(self.project_name):
            return self.session[self.project_name]

        self.parse_args(auth_conf)
        kwargs = {'auth_url': self.auth_url,
                  'username': self.admin_user,
                  'password': <PASSWORD>}

        if self.auth_version == '2':
            client = v2_client
            kwargs['tenant_name'] = self.project_name
        elif self.auth_version == '3':
            client = v3_client
            kwargs['project_name'] = self.project_name
            kwargs['user_domain_name'] = self.admin_user_domain
            kwargs['project_domain_name'] = self.admin_project_domain

        try:
            kc = client.Password(**kwargs)
{'fraction_non_alphanumeric': 0.11084481725584182, 'fraction_numerical': 0.007189934092270821, 'mean_word_length': 2.4231032125768968, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3115266', 'n_tokens_mistral': 1533, 'n_tokens_neox': 1490, 'n_words': 286}