Merge "Adding --insecure flag"

This commit is contained in:
Jenkins 2015-11-15 08:21:02 +00:00 committed by Gerrit Code Review
commit 00362a08da
3 changed files with 67 additions and 30 deletions

View File

@ -20,7 +20,7 @@ from mistralclient.api.v2 import client as client_v2
def client(mistral_url=None, username=None, api_key=None, def client(mistral_url=None, username=None, api_key=None,
project_name=None, auth_url=None, project_id=None, project_name=None, auth_url=None, project_id=None,
endpoint_type='publicURL', service_type='workflow', endpoint_type='publicURL', service_type='workflow',
auth_token=None, user_id=None, cacert=None): auth_token=None, user_id=None, cacert=None, insecure=False):
if mistral_url and not isinstance(mistral_url, six.string_types): if mistral_url and not isinstance(mistral_url, six.string_types):
raise RuntimeError('Mistral url should be a string.') raise RuntimeError('Mistral url should be a string.')
@ -36,7 +36,8 @@ def client(mistral_url=None, username=None, api_key=None,
service_type=service_type, service_type=service_type,
auth_token=auth_token, auth_token=auth_token,
user_id=user_id, user_id=user_id,
cacert=cacert cacert=cacert,
insecure=insecure
) )

View File

@ -31,25 +31,39 @@ class Client(object):
def __init__(self, mistral_url=None, username=None, api_key=None, def __init__(self, mistral_url=None, username=None, api_key=None,
project_name=None, auth_url=None, project_id=None, project_name=None, auth_url=None, project_id=None,
endpoint_type='publicURL', service_type='workflowv2', endpoint_type='publicURL', service_type='workflowv2',
auth_token=None, user_id=None, cacert=None): auth_token=None, user_id=None, cacert=None, insecure=False):
if mistral_url and not isinstance(mistral_url, six.string_types): if mistral_url and not isinstance(mistral_url, six.string_types):
raise RuntimeError('Mistral url should be string') raise RuntimeError('Mistral url should be string')
if auth_url: if auth_url:
(mistral_url, auth_token, project_id, user_id) = ( (mistral_url, auth_token, project_id, user_id) = (
self.authenticate(mistral_url, username, api_key, self.authenticate(
project_name, auth_url, project_id, mistral_url,
endpoint_type, service_type, auth_token, username,
user_id, cacert)) api_key,
project_name,
auth_url,
project_id,
endpoint_type,
service_type,
auth_token,
user_id,
cacert,
insecure
)
)
if not mistral_url: if not mistral_url:
mistral_url = "http://localhost:8989/v2" mistral_url = "http://localhost:8989/v2"
self.http_client = httpclient.HTTPClient(mistral_url, self.http_client = httpclient.HTTPClient(
mistral_url,
auth_token, auth_token,
project_id, project_id,
user_id) user_id
)
# Create all resource managers. # Create all resource managers.
self.workbooks = workbooks.WorkbookManager(self) self.workbooks = workbooks.WorkbookManager(self)
self.executions = executions.ExecutionManager(self) self.executions = executions.ExecutionManager(self)
@ -64,15 +78,18 @@ class Client(object):
def authenticate(self, mistral_url=None, username=None, api_key=None, def authenticate(self, mistral_url=None, username=None, api_key=None,
project_name=None, auth_url=None, project_id=None, project_name=None, auth_url=None, project_id=None,
endpoint_type='publicURL', service_type='workflowv2', endpoint_type='publicURL', service_type='workflowv2',
auth_token=None, user_id=None, cacert=None): auth_token=None, user_id=None, cacert=None,
insecure=False):
if project_name and project_id: if project_name and project_id:
raise RuntimeError('Only project name or ' raise RuntimeError(
'project id should be set') 'Only project name or project id should be set'
)
if username and user_id: if username and user_id:
raise RuntimeError('Only user name or user id' raise RuntimeError(
' should be set') 'Only user name or user id should be set'
)
keystone_client = _get_keystone_client(auth_url) keystone_client = _get_keystone_client(auth_url)
@ -85,7 +102,9 @@ class Client(object):
tenant_name=project_name, tenant_name=project_name,
auth_url=auth_url, auth_url=auth_url,
endpoint=auth_url, endpoint=auth_url,
cacert=cacert) cacert=cacert,
insecure=insecure
)
keystone.authenticate() keystone.authenticate()
token = keystone.auth_token token = keystone.auth_token

View File

@ -43,8 +43,12 @@ LOG = logging.getLogger(__name__)
class OpenStackHelpFormatter(argparse.HelpFormatter): class OpenStackHelpFormatter(argparse.HelpFormatter):
def __init__(self, prog, indent_increment=2, max_help_position=32, def __init__(self, prog, indent_increment=2, max_help_position=32,
width=None): width=None):
super(OpenStackHelpFormatter, self).__init__(prog, indent_increment, super(OpenStackHelpFormatter, self).__init__(
max_help_position, width) prog,
indent_increment,
max_help_position,
width
)
def start_section(self, heading): def start_section(self, heading):
# Title-case the headings. # Title-case the headings.
@ -114,8 +118,10 @@ class MistralShell(app.App):
log_lvl = logging.DEBUG if self.options.debug else logging.WARNING log_lvl = logging.DEBUG if self.options.debug else logging.WARNING
logging.basicConfig( logging.basicConfig(
format="%(levelname)s (%(module)s) %(message)s", format="%(levelname)s (%(module)s) %(message)s",
level=log_lvl) level=log_lvl
)
logging.getLogger('iso8601').setLevel(logging.WARNING) logging.getLogger('iso8601').setLevel(logging.WARNING)
if self.options.verbose_level <= 1: if self.options.verbose_level <= 1:
logging.getLogger('requests').setLevel(logging.WARNING) logging.getLogger('requests').setLevel(logging.WARNING)
@ -262,6 +268,14 @@ class MistralShell(app.App):
default=c.env('OS_CACERT'), default=c.env('OS_CACERT'),
help='Authentication CA Certificate (Env: OS_CACERT)' help='Authentication CA Certificate (Env: OS_CACERT)'
) )
parser.add_argument(
'--insecure',
action='store_true',
dest='insecure',
default=c.env('MISTRALCLIENT_INSECURE', default=False),
help='Disables SSL/TLS certificate verification '
'(Env: MISTRALCLIENT_INSECURE)'
)
return parser return parser
def initialize_app(self, argv): def initialize_app(self, argv):
@ -284,7 +298,8 @@ class MistralShell(app.App):
if do_help or ('bash-completion' in argv): if do_help or ('bash-completion' in argv):
self.options.auth_url = None self.options.auth_url = None
self.client = client.client(mistral_url=self.options.mistral_url, self.client = client.client(
mistral_url=self.options.mistral_url,
username=self.options.username, username=self.options.username,
api_key=self.options.password, api_key=self.options.password,
project_name=self.options.tenant_name, project_name=self.options.tenant_name,
@ -293,7 +308,9 @@ class MistralShell(app.App):
endpoint_type=self.options.endpoint_type, endpoint_type=self.options.endpoint_type,
service_type=self.options.service_type, service_type=self.options.service_type,
auth_token=self.options.token, auth_token=self.options.token,
cacert=self.options.cacert) cacert=self.options.cacert,
insecure=self.options.insecure
)
def _set_shell_commands(self, cmds_dict): def _set_shell_commands(self, cmds_dict):
for k, v in cmds_dict.items(): for k, v in cmds_dict.items():