more work on standardization of cliauth
This commit is contained in:
@@ -27,7 +27,7 @@ By way of a quick-start::
|
|||||||
|
|
||||||
# use v2.0 auth with http://example.com:5000/v2.0")
|
# use v2.0 auth with http://example.com:5000/v2.0")
|
||||||
>>> from keystoneclient.v2_0 import client
|
>>> from keystoneclient.v2_0 import client
|
||||||
>>> keystone = client.Client(user_name=USERNAME, password=PASSWORD, tenant_name=TENANT, auth_url=KEYSTONE_URL)
|
>>> keystone = client.Client(username=USERNAME, password=PASSWORD, tenant_name=TENANT, auth_url=KEYSTONE_URL)
|
||||||
>>> keystone.tenants.list()
|
>>> keystone.tenants.list()
|
||||||
>>> tenant = keystone.tenants.create(name="test", descrption="My new tenant!", enabled=True)
|
>>> tenant = keystone.tenants.create(name="test", descrption="My new tenant!", enabled=True)
|
||||||
>>> tenant.delete()
|
>>> tenant.delete()
|
||||||
@@ -49,7 +49,7 @@ with the ``--username``, ``--apikey`` and ``--projectid`` params, but it's
|
|||||||
easier to just set them as environment variables::
|
easier to just set them as environment variables::
|
||||||
|
|
||||||
export OS_TENANT_NAME=project
|
export OS_TENANT_NAME=project
|
||||||
export OS_USER_NAME=user
|
export OS_USERNAME=user
|
||||||
export OS_PASSWORD=pass
|
export OS_PASSWORD=pass
|
||||||
|
|
||||||
You will also need to define the authentication url with ``--url`` and the
|
You will also need to define the authentication url with ``--url`` and the
|
||||||
@@ -66,7 +66,7 @@ can specify the one you want with ``--region_name`` (or
|
|||||||
You'll find complete documentation on the shell by running
|
You'll find complete documentation on the shell by running
|
||||||
``keystone help``::
|
``keystone help``::
|
||||||
|
|
||||||
usage: keystone [--user_name user] [--password password]
|
usage: keystone [--username user] [--password password]
|
||||||
[--tenant_name tenant] [--auth_url URL]
|
[--tenant_name tenant] [--auth_url URL]
|
||||||
<subcommand> ...
|
<subcommand> ...
|
||||||
|
|
||||||
@@ -78,8 +78,7 @@ You'll find complete documentation on the shell by running
|
|||||||
|
|
||||||
|
|
||||||
Optional arguments:
|
Optional arguments:
|
||||||
--user_name USER Defaults to env[OS_USER_NAME].
|
--username USER Defaults to env[OS_USERNAME].
|
||||||
--user_id USERID Defaults to env[OS_USER_ID].
|
|
||||||
--password PASSWORD Defaults to env[OS_PASSWORD].
|
--password PASSWORD Defaults to env[OS_PASSWORD].
|
||||||
--tenant_name TENANT Defaults to env[OS_TENANT_NAME].
|
--tenant_name TENANT Defaults to env[OS_TENANT_NAME].
|
||||||
--tenant_id TENANTID Defaults to env[OS_TENANT_].
|
--tenant_id TENANTID Defaults to env[OS_TENANT_].
|
||||||
|
@@ -38,11 +38,11 @@ class HTTPClient(httplib2.Http):
|
|||||||
|
|
||||||
USER_AGENT = 'python-keystoneclient'
|
USER_AGENT = 'python-keystoneclient'
|
||||||
|
|
||||||
def __init__(self, user_name=None, tenant_id=None, tenant_name=None,
|
def __init__(self, username=None, tenant_id=None, tenant_name=None,
|
||||||
password=None, project_id=None, auth_url=None,
|
password=None, project_id=None, auth_url=None,
|
||||||
region_name=None, timeout=None, endpoint=None, token=None):
|
region_name=None, timeout=None, endpoint=None, token=None):
|
||||||
super(HTTPClient, self).__init__(timeout=timeout)
|
super(HTTPClient, self).__init__(timeout=timeout)
|
||||||
self.user_name = user_name
|
self.username = username
|
||||||
self.tenant_id = tenant_id
|
self.tenant_id = tenant_id
|
||||||
self.tenant_name = tenant_name
|
self.tenant_name = tenant_name
|
||||||
self.password = password
|
self.password = password
|
||||||
|
@@ -55,9 +55,9 @@ class OpenStackIdentityShell(object):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
help=argparse.SUPPRESS)
|
help=argparse.SUPPRESS)
|
||||||
|
|
||||||
parser.add_argument('--user_name',
|
parser.add_argument('--username',
|
||||||
default=env('OS_USER_NAME'),
|
default=env('OS_USERNAME'),
|
||||||
help='Defaults to env[OS_USER_NAME].')
|
help='Defaults to env[OS_USERNAME].')
|
||||||
|
|
||||||
parser.add_argument('--password',
|
parser.add_argument('--password',
|
||||||
default=env('OS_PASSWORD'),
|
default=env('OS_PASSWORD'),
|
||||||
@@ -151,9 +151,9 @@ class OpenStackIdentityShell(object):
|
|||||||
#FIXME(usrleon): Here should be restrict for project id same as
|
#FIXME(usrleon): Here should be restrict for project id same as
|
||||||
# for username or apikey but for compatibility it is not.
|
# for username or apikey but for compatibility it is not.
|
||||||
|
|
||||||
if not args.user_name:
|
if not args.username:
|
||||||
raise exc.CommandError("You must provide a user name:"
|
raise exc.CommandError("You must provide a username:"
|
||||||
"via --user_name or env[OS_USER_NAME]")
|
"via --username or env[OS_USERNAME]")
|
||||||
if not args.password:
|
if not args.password:
|
||||||
raise exc.CommandError("You must provide a password, either"
|
raise exc.CommandError("You must provide a password, either"
|
||||||
"via --password or env[OS_PASSWORD]")
|
"via --password or env[OS_PASSWORD]")
|
||||||
@@ -163,7 +163,7 @@ class OpenStackIdentityShell(object):
|
|||||||
"via --auth_url or via"
|
"via --auth_url or via"
|
||||||
"env[OS_AUTH_URL")
|
"env[OS_AUTH_URL")
|
||||||
|
|
||||||
self.cs = self.get_api_class(options.version)(user_name=args.user_name,
|
self.cs = self.get_api_class(options.version)(username=args.username,
|
||||||
tenant_name=args.tenant_name,
|
tenant_name=args.tenant_name,
|
||||||
tenant_id=args.tenant_id,
|
tenant_id=args.tenant_id,
|
||||||
password=args.password,
|
password=args.password,
|
||||||
|
@@ -86,7 +86,7 @@ class Client(client.HTTPClient):
|
|||||||
"""
|
"""
|
||||||
self.management_url = self.auth_url
|
self.management_url = self.auth_url
|
||||||
# try:
|
# try:
|
||||||
raw_token = self.tokens.authenticate(user_name=self.user_name,
|
raw_token = self.tokens.authenticate(username=self.username,
|
||||||
tenant_id=self.tenant_id,
|
tenant_id=self.tenant_id,
|
||||||
tenant_name=self.tenant_name,
|
tenant_name=self.tenant_name,
|
||||||
password=self.password,
|
password=self.password,
|
||||||
|
@@ -21,12 +21,12 @@ class Token(base.Resource):
|
|||||||
class TokenManager(base.ManagerWithFind):
|
class TokenManager(base.ManagerWithFind):
|
||||||
resource_class = Token
|
resource_class = Token
|
||||||
|
|
||||||
def authenticate(self, user_name=None, tenant_id=None, tenant_name=None,
|
def authenticate(self, username=None, tenant_id=None, tenant_name=None,
|
||||||
password=None, token=None, return_raw=False):
|
password=None, token=None, return_raw=False):
|
||||||
if token and token != password:
|
if token and token != password:
|
||||||
params = {"auth": {"token": {"id": token}}}
|
params = {"auth": {"token": {"id": token}}}
|
||||||
elif user_name and password:
|
elif username and password:
|
||||||
params = {"auth": {"passwordCredentials": {"username": user_name,
|
params = {"auth": {"passwordCredentials": {"username": username,
|
||||||
"password": password}}}
|
"password": password}}}
|
||||||
else:
|
else:
|
||||||
raise ValueError('A username and password or token is required.')
|
raise ValueError('A username and password or token is required.')
|
||||||
|
Reference in New Issue
Block a user