Merge #1235 Some mbs-cli tweaks

This commit is contained in:
Jan Kaluža
2019-04-26 06:14:48 +00:00

View File

@@ -24,17 +24,15 @@
# Jan Kaluza <jkaluza@redhat.com>
from __future__ import print_function
import sys
import enum
from pprint import pprint
import json
import requests
import argparse
import enum
import json
from pprint import pprint
import sys
import openidc_client
import requests
import requests.exceptions
from six.moves import urllib_parse
import requests_kerberos
env_config = {
@@ -160,6 +158,7 @@ class MBSCli(object):
if self._auth_mech == AuthMech.OpenIDC:
headers['Authorization'] = 'Bearer {0}'.format(self._openidc_token)
elif self._auth_mech == AuthMech.Kerberos:
import requests_kerberos
# MBS server does not support mutual auth, so make it optional.
request_data['auth'] = requests_kerberos.HTTPKerberosAuth(
mutual_authentication=requests_kerberos.OPTIONAL)
@@ -265,9 +264,14 @@ def create_mbs_client(args):
mbs_url = args.server
auth_mech = MBSCli.get_auth_mech(mbs_url)
openidc_token=None
openidc_token = None
if auth_mech == AuthMech.OpenIDC:
try:
import openidc_client
except ImportError:
print('The python-openidc-client package must be installed', file=sys.stderr)
sys.exit(1)
id_provider = id_provider_config[args.env]
# Get the auth token using the OpenID client.
@@ -292,6 +296,12 @@ def create_mbs_client(args):
raise
return MBSCli(mbs_url, auth_mech=auth_mech, openidc_token=token)
elif auth_mech == AuthMech.Kerberos:
try:
import requests_kerberos # noqa
except ImportError:
print('The python-requests-kerberos package must be installed', file=sys.stderr)
sys.exit(1)
return MBSCli(mbs_url, auth_mech=auth_mech, openidc_token=openidc_token)