From c6a1f56ed6b6befc77967ba40e751a6a80238ae8 Mon Sep 17 00:00:00 2001 From: Davide Guerri Date: Sun, 24 Feb 2013 16:47:50 +0100 Subject: [PATCH] Add support for administrative access (via X-Moniker-Sudo-Tenant-ID header) Change-Id: Ia92f9c33cebb529333de72765371189ea11b72bc --- monikerclient/auth.py | 6 +++++- monikerclient/cli/base.py | 1 + monikerclient/shell.py | 4 ++++ monikerclient/v1/__init__.py | 4 ++-- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/monikerclient/auth.py b/monikerclient/auth.py index fe77015..2299a74 100644 --- a/monikerclient/auth.py +++ b/monikerclient/auth.py @@ -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): diff --git a/monikerclient/cli/base.py b/monikerclient/cli/base.py index 1ccae65..9c6690d 100644 --- a/monikerclient/cli/base.py +++ b/monikerclient/cli/base.py @@ -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: diff --git a/monikerclient/shell.py b/monikerclient/shell.py index 791673e..9ea727f 100644 --- a/monikerclient/shell.py +++ b/monikerclient/shell.py @@ -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 diff --git a/monikerclient/v1/__init__.py b/monikerclient/v1/__init__.py index 967037e..7ea8d1a 100644 --- a/monikerclient/v1/__init__.py +++ b/monikerclient/v1/__init__.py @@ -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