Add support for administrative access (via X-Moniker-Sudo-Tenant-ID header)
Change-Id: Ia92f9c33cebb529333de72765371189ea11b72bc
This commit is contained in:
parent
e824b5b470
commit
c6a1f56ed6
monikerclient
@ -22,13 +22,14 @@ from keystoneclient.v2_0.client import Client
|
||||
class KeystoneAuth(AuthBase):
|
||||
def __init__(self, auth_url, username=None, password=None, tenant_id=None,
|
||||
tenant_name=None, token=None, service_type=None,
|
||||
endpoint_type=None):
|
||||
endpoint_type=None, sudo_tenant_id=None):
|
||||
self.auth_url = str(auth_url).rstrip('/')
|
||||
self.username = username
|
||||
self.password = password
|
||||
self.tenant_id = tenant_id
|
||||
self.tenant_name = tenant_name
|
||||
self.token = token
|
||||
self.sudo_tenant_id = sudo_tenant_id
|
||||
|
||||
if (not username and not password) and not token:
|
||||
raise ValueError('A username and password, or token is required')
|
||||
@ -47,6 +48,9 @@ class KeystoneAuth(AuthBase):
|
||||
|
||||
request.headers['X-Auth-Token'] = self.token
|
||||
|
||||
if self.sudo_tenant_id:
|
||||
request.headers['X-Moniker-Sudo-Tenant-ID'] = self.sudo_tenant_id
|
||||
|
||||
return request
|
||||
|
||||
def get_ksclient(self):
|
||||
|
@ -35,6 +35,7 @@ class Command(CliffCommand):
|
||||
'token': self.app.options.os_token,
|
||||
'service_type': self.app.options.os_service_type,
|
||||
'region_name': self.app.options.os_region_name,
|
||||
'sudo_tenant_id': self.app.options.sudo_tenant_id
|
||||
}
|
||||
|
||||
if client_args['endpoint'] is None and client_args['auth_url'] is None:
|
||||
|
@ -67,4 +67,8 @@ class MonikerShell(App):
|
||||
default=os.environ.get('OS_REGION_NAME'),
|
||||
help="Defaults to env[OS_REGION_NAME]")
|
||||
|
||||
parser.add_argument('--sudo-tenant-id',
|
||||
default=os.environ.get('MONIKER_SUDO_TENANT_ID'),
|
||||
help="Defaults to env[MONIKER_SUDO_TENANT_ID]")
|
||||
|
||||
return parser
|
||||
|
@ -28,7 +28,7 @@ class Client(object):
|
||||
def __init__(self, endpoint=None, auth_url=None, username=None,
|
||||
password=None, tenant_id=None, tenant_name=None, token=None,
|
||||
region_name=None, service_type='dns',
|
||||
endpoint_type='publicURL'):
|
||||
endpoint_type='publicURL', sudo_tenant_id=None):
|
||||
"""
|
||||
:param endpoint: Endpoint URL
|
||||
:param auth_url: Keystone auth_url
|
||||
@ -43,7 +43,7 @@ class Client(object):
|
||||
if auth_url:
|
||||
auth = KeystoneAuth(auth_url, username, password, tenant_id,
|
||||
tenant_name, token, service_type,
|
||||
endpoint_type)
|
||||
endpoint_type, sudo_tenant_id)
|
||||
self.endpoint = auth.get_url()
|
||||
elif endpoint:
|
||||
auth = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user