Merge pull request #16 from jistr/ftr/auth_options
Allow token authentication CLI args
This commit is contained in:
commit
91f36916e5
@ -35,7 +35,7 @@ def _get_ksclient(**kwargs):
|
||||
def _get_endpoint(client, **kwargs):
|
||||
"""Get an endpoint using the provided keystone client."""
|
||||
return client.service_catalog.url_for(
|
||||
service_type=kwargs.get('service_type') or 'metering',
|
||||
service_type=kwargs.get('service_type') or 'management',
|
||||
endpoint_type=kwargs.get('endpoint_type') or 'publicURL')
|
||||
|
||||
|
||||
|
@ -40,22 +40,33 @@ class TuskarShell(object):
|
||||
self._ensure_auth_info(args)
|
||||
|
||||
def _ensure_auth_info(self, args):
|
||||
if not args.os_username:
|
||||
raise UsageError("You must provide username via either "
|
||||
"--os-username or env[OS_USERNAME]")
|
||||
'''Ensure that authentication information is provided. Two variants
|
||||
of authentication are supported:
|
||||
- provide username, password, tenant and auth url
|
||||
- provide token and tuskar url (or auth url instead of tuskar url)
|
||||
'''
|
||||
if not args.os_auth_token:
|
||||
if not args.os_username:
|
||||
raise UsageError("You must provide username via either "
|
||||
"--os-username or env[OS_USERNAME]")
|
||||
|
||||
if not args.os_password:
|
||||
raise UsageError("You must provide password via either "
|
||||
"--os-password or env[OS_PASSWORD]")
|
||||
if not args.os_password:
|
||||
raise UsageError("You must provide password via either "
|
||||
"--os-password or env[OS_PASSWORD]")
|
||||
|
||||
if not args.os_tenant_id and not args.os_tenant_name:
|
||||
raise UsageError("You must provide tenant via either "
|
||||
"--os-tenant-name or --os-tenant-id or "
|
||||
"env[OS_TENANT_NAME] or env[OS_TENANT_ID]")
|
||||
if not args.os_tenant_id and not args.os_tenant_name:
|
||||
raise UsageError("You must provide tenant via either "
|
||||
"--os-tenant-name or --os-tenant-id or "
|
||||
"env[OS_TENANT_NAME] or env[OS_TENANT_ID]")
|
||||
|
||||
if not args.os_auth_url:
|
||||
raise UsageError("You must provide auth URL via either "
|
||||
"--os-auth-url or env[OS_AUTH_URL]")
|
||||
if not args.os_auth_url:
|
||||
raise UsageError("You must provide auth URL via either "
|
||||
"--os-auth-url or env[OS_AUTH_URL]")
|
||||
else:
|
||||
if not args.tuskar_url and not args.os_auth_url:
|
||||
raise UsageError("You must provide either "
|
||||
"--tuskar_url or --os_auth_url or "
|
||||
"env[TUSKAR_URL] or env[OS_AUTH_URL]")
|
||||
|
||||
|
||||
class UsageError(Exception):
|
||||
|
@ -10,6 +10,7 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from tuskarclient import shell
|
||||
import tuskarclient.tests.utils as tutils
|
||||
|
||||
|
||||
@ -17,3 +18,39 @@ class ShellTest(tutils.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(ShellTest, self).setUp()
|
||||
self.s = shell.TuskarShell({})
|
||||
|
||||
def empty_args(self):
|
||||
args = lambda: None # i'd use object(), but it can't have attributes
|
||||
args_attributes = [
|
||||
'os_username', 'os_password', 'os_tenant_name', 'os_tenant_id',
|
||||
'os_auth_url', 'os_auth_token', 'tuskar_url',
|
||||
]
|
||||
for attr in args_attributes:
|
||||
setattr(args, attr, None)
|
||||
|
||||
return args
|
||||
|
||||
def test_ensure_auth_info_with_credentials(self):
|
||||
ensure = self.s._ensure_auth_info
|
||||
usage_error = shell.UsageError
|
||||
args = self.empty_args()
|
||||
|
||||
args.os_username = 'user'
|
||||
args.os_password = 'pass'
|
||||
args.os_tenant_name = 'tenant'
|
||||
self.assertRaises(usage_error, ensure, args)
|
||||
|
||||
args.os_auth_url = 'keystone'
|
||||
ensure(args) # doesn't raise
|
||||
|
||||
def test_ensure_auth_info_with_token(self):
|
||||
ensure = self.s._ensure_auth_info
|
||||
usage_error = shell.UsageError
|
||||
args = self.empty_args()
|
||||
|
||||
args.os_auth_token = 'token'
|
||||
self.assertRaises(usage_error, ensure, args)
|
||||
|
||||
args.tuskar_url = 'tuskar'
|
||||
ensure(args) # doesn't raise
|
||||
|
@ -70,4 +70,18 @@ def create_top_parser():
|
||||
help=argparse.SUPPRESS,
|
||||
)
|
||||
|
||||
parser.add_argument('--os-auth-token',
|
||||
default=utils.env('OS_AUTH_TOKEN'),
|
||||
help='Defaults to env[OS_AUTH_TOKEN]')
|
||||
|
||||
parser.add_argument('--os_auth_token',
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
parser.add_argument('--tuskar-url',
|
||||
default=utils.env('TUSKAR_URL'),
|
||||
help='Defaults to env[TUSKAR_URL]')
|
||||
|
||||
parser.add_argument('--tuskar_url',
|
||||
help=argparse.SUPPRESS)
|
||||
|
||||
return parser
|
||||
|
Loading…
x
Reference in New Issue
Block a user