Clean redundant argument to dict.get
`dict.get()` returns `None` by default, if a key wasn't found. Removing `None` as second argument to avoid redundancy. Change-Id: Ia82f7469cd019509bbeccbfe54b15eeedc7bb6ea
This commit is contained in:
parent
867bcb0db8
commit
e2158b7ef4
@ -80,13 +80,13 @@ def select_auth_plugin(options):
|
||||
# Do the token/url check first as this must override the default
|
||||
# 'password' set by os-client-config
|
||||
# Also, url and token are not copied into o-c-c's auth dict (yet?)
|
||||
if options.auth.get('url', None) and options.auth.get('token', None):
|
||||
if options.auth.get('url') and options.auth.get('token'):
|
||||
# service token authentication
|
||||
auth_plugin_name = 'token_endpoint'
|
||||
elif options.auth_type in [plugin.name for plugin in PLUGIN_LIST]:
|
||||
# A direct plugin name was given, use it
|
||||
auth_plugin_name = options.auth_type
|
||||
elif options.auth.get('username', None):
|
||||
elif options.auth.get('username'):
|
||||
if options.identity_api_version == '3':
|
||||
auth_plugin_name = 'v3password'
|
||||
elif options.identity_api_version.startswith('2'):
|
||||
@ -94,7 +94,7 @@ def select_auth_plugin(options):
|
||||
else:
|
||||
# let keystoneclient figure it out itself
|
||||
auth_plugin_name = 'osc_password'
|
||||
elif options.auth.get('token', None):
|
||||
elif options.auth.get('token'):
|
||||
if options.identity_api_version == '3':
|
||||
auth_plugin_name = 'v3token'
|
||||
elif options.identity_api_version.startswith('2'):
|
||||
@ -144,33 +144,33 @@ def check_valid_auth_options(options, auth_plugin_name, required_scope=True):
|
||||
|
||||
msg = ''
|
||||
if auth_plugin_name.endswith('password'):
|
||||
if not options.auth.get('username', None):
|
||||
if not options.auth.get('username'):
|
||||
msg += _('Set a username with --os-username, OS_USERNAME,'
|
||||
' or auth.username\n')
|
||||
if not options.auth.get('auth_url', None):
|
||||
if not options.auth.get('auth_url'):
|
||||
msg += _('Set an authentication URL, with --os-auth-url,'
|
||||
' OS_AUTH_URL or auth.auth_url\n')
|
||||
if (required_scope and not
|
||||
options.auth.get('project_id', None) and not
|
||||
options.auth.get('domain_id', None) and not
|
||||
options.auth.get('domain_name', None) and not
|
||||
options.auth.get('project_name', None) and not
|
||||
options.auth.get('tenant_id', None) and not
|
||||
options.auth.get('tenant_name', None)):
|
||||
options.auth.get('project_id') and not
|
||||
options.auth.get('domain_id') and not
|
||||
options.auth.get('domain_name') and not
|
||||
options.auth.get('project_name') and not
|
||||
options.auth.get('tenant_id') and not
|
||||
options.auth.get('tenant_name')):
|
||||
msg += _('Set a scope, such as a project or domain, set a '
|
||||
'project scope with --os-project-name, OS_PROJECT_NAME '
|
||||
'or auth.project_name, set a domain scope with '
|
||||
'--os-domain-name, OS_DOMAIN_NAME or auth.domain_name')
|
||||
elif auth_plugin_name.endswith('token'):
|
||||
if not options.auth.get('token', None):
|
||||
if not options.auth.get('token'):
|
||||
msg += _('Set a token with --os-token, OS_TOKEN or auth.token\n')
|
||||
if not options.auth.get('auth_url', None):
|
||||
if not options.auth.get('auth_url'):
|
||||
msg += _('Set a service AUTH_URL, with --os-auth-url, '
|
||||
'OS_AUTH_URL or auth.auth_url\n')
|
||||
elif auth_plugin_name == 'token_endpoint':
|
||||
if not options.auth.get('token', None):
|
||||
if not options.auth.get('token'):
|
||||
msg += _('Set a token with --os-token, OS_TOKEN or auth.token\n')
|
||||
if not options.auth.get('url', None):
|
||||
if not options.auth.get('url'):
|
||||
msg += _('Set a service URL, with --os-url, OS_URL or auth.url\n')
|
||||
|
||||
if msg:
|
||||
|
@ -50,7 +50,7 @@ class APIv1(api.BaseAPI):
|
||||
data = {
|
||||
'account': self._find_account_id(),
|
||||
'container': container,
|
||||
'x-trans-id': response.headers.get('x-trans-id', None),
|
||||
'x-trans-id': response.headers.get('x-trans-id'),
|
||||
}
|
||||
|
||||
return data
|
||||
@ -176,21 +176,19 @@ class APIv1(api.BaseAPI):
|
||||
'account': self._find_account_id(),
|
||||
'container': container,
|
||||
'object_count': response.headers.get(
|
||||
'x-container-object-count',
|
||||
None,
|
||||
'x-container-object-count'
|
||||
),
|
||||
'bytes_used': response.headers.get('x-container-bytes-used', None)
|
||||
'bytes_used': response.headers.get('x-container-bytes-used')
|
||||
}
|
||||
|
||||
if 'x-container-read' in response.headers:
|
||||
data['read_acl'] = response.headers.get('x-container-read', None)
|
||||
data['read_acl'] = response.headers.get('x-container-read')
|
||||
if 'x-container-write' in response.headers:
|
||||
data['write_acl'] = response.headers.get('x-container-write', None)
|
||||
data['write_acl'] = response.headers.get('x-container-write')
|
||||
if 'x-container-sync-to' in response.headers:
|
||||
data['sync_to'] = response.headers.get('x-container-sync-to', None)
|
||||
data['sync_to'] = response.headers.get('x-container-sync-to')
|
||||
if 'x-container-sync-key' in response.headers:
|
||||
data['sync_key'] = response.headers.get('x-container-sync-key',
|
||||
None)
|
||||
data['sync_key'] = response.headers.get('x-container-sync-key')
|
||||
|
||||
properties = self._get_properties(response.headers,
|
||||
'x-container-meta-')
|
||||
@ -248,8 +246,8 @@ class APIv1(api.BaseAPI):
|
||||
'account': self._find_account_id(),
|
||||
'container': container,
|
||||
'object': object,
|
||||
'x-trans-id': response.headers.get('X-Trans-Id', None),
|
||||
'etag': response.headers.get('Etag', None),
|
||||
'x-trans-id': response.headers.get('X-Trans-Id'),
|
||||
'etag': response.headers.get('Etag'),
|
||||
}
|
||||
|
||||
return data
|
||||
@ -453,21 +451,19 @@ class APIv1(api.BaseAPI):
|
||||
'account': self._find_account_id(),
|
||||
'container': container,
|
||||
'object': object,
|
||||
'content-type': response.headers.get('content-type', None),
|
||||
'content-type': response.headers.get('content-type'),
|
||||
}
|
||||
if 'content-length' in response.headers:
|
||||
data['content-length'] = response.headers.get(
|
||||
'content-length',
|
||||
None,
|
||||
'content-length'
|
||||
)
|
||||
if 'last-modified' in response.headers:
|
||||
data['last-modified'] = response.headers.get('last-modified', None)
|
||||
data['last-modified'] = response.headers.get('last-modified')
|
||||
if 'etag' in response.headers:
|
||||
data['etag'] = response.headers.get('etag', None)
|
||||
data['etag'] = response.headers.get('etag')
|
||||
if 'x-object-manifest' in response.headers:
|
||||
data['x-object-manifest'] = response.headers.get(
|
||||
'x-object-manifest',
|
||||
None,
|
||||
'x-object-manifest'
|
||||
)
|
||||
|
||||
properties = self._get_properties(response.headers, 'x-object-meta-')
|
||||
@ -506,10 +502,9 @@ class APIv1(api.BaseAPI):
|
||||
data['properties'] = properties
|
||||
|
||||
# Map containers, bytes and objects a bit nicer
|
||||
data['Containers'] = response.headers.get('x-account-container-count',
|
||||
None)
|
||||
data['Objects'] = response.headers.get('x-account-object-count', None)
|
||||
data['Bytes'] = response.headers.get('x-account-bytes-used', None)
|
||||
data['Containers'] = response.headers.get('x-account-container-count')
|
||||
data['Objects'] = response.headers.get('x-account-object-count')
|
||||
data['Bytes'] = response.headers.get('x-account-bytes-used')
|
||||
# Add in Account info too
|
||||
data['Account'] = self._find_account_id()
|
||||
return data
|
||||
|
@ -90,7 +90,7 @@ class ClientManager(object):
|
||||
self._cli_options = cli_options
|
||||
self._api_version = api_version
|
||||
self._pw_callback = pw_func
|
||||
self._url = self._cli_options.auth.get('url', None)
|
||||
self._url = self._cli_options.auth.get('url')
|
||||
self._region_name = self._cli_options.region_name
|
||||
self._interface = self._cli_options.interface
|
||||
|
||||
@ -146,7 +146,7 @@ class ClientManager(object):
|
||||
# Horrible hack alert...must handle prompt for null password if
|
||||
# password auth is requested.
|
||||
if (self.auth_plugin_name.endswith('password') and
|
||||
not self._cli_options.auth.get('password', None)):
|
||||
not self._cli_options.auth.get('password')):
|
||||
self._cli_options.auth['password'] = self._pw_callback()
|
||||
|
||||
(auth_plugin, self._auth_params) = auth.build_auth_params(
|
||||
@ -162,9 +162,9 @@ class ClientManager(object):
|
||||
# PROJECT_DOMAIN_ID to 'OS_DEFAULT_DOMAIN' for better usability.
|
||||
if (self._api_version.get('identity') == '3' and
|
||||
self.auth_plugin_name.endswith('password') and
|
||||
not self._auth_params.get('project_domain_id', None) and
|
||||
not self._auth_params.get('project_domain_id') and
|
||||
not self.auth_plugin_name.startswith('v2') and
|
||||
not self._auth_params.get('project_domain_name', None)):
|
||||
not self._auth_params.get('project_domain_name')):
|
||||
self._auth_params['project_domain_id'] = default_domain
|
||||
|
||||
# NOTE(stevemar): If USER_DOMAIN_ID or USER_DOMAIN_NAME is present,
|
||||
@ -173,8 +173,8 @@ class ClientManager(object):
|
||||
if (self._api_version.get('identity') == '3' and
|
||||
self.auth_plugin_name.endswith('password') and
|
||||
not self.auth_plugin_name.startswith('v2') and
|
||||
not self._auth_params.get('user_domain_id', None) and
|
||||
not self._auth_params.get('user_domain_name', None)):
|
||||
not self._auth_params.get('user_domain_id') and
|
||||
not self._auth_params.get('user_domain_name')):
|
||||
self._auth_params['user_domain_id'] = default_domain
|
||||
|
||||
# For compatibility until all clients can be updated
|
||||
|
@ -122,8 +122,8 @@ def from_response(response, body):
|
||||
if body:
|
||||
if hasattr(body, 'keys'):
|
||||
error = body[body.keys()[0]]
|
||||
message = error.get('message', None)
|
||||
details = error.get('details', None)
|
||||
message = error.get('message')
|
||||
details = error.get('details')
|
||||
else:
|
||||
# If we didn't get back a properly formed error message we
|
||||
# probably couldn't communicate with Keystone at all.
|
||||
|
@ -169,7 +169,7 @@ class LogConfigurator(object):
|
||||
self.dump_trace = cloud_config.config.get('debug', self.dump_trace)
|
||||
self.console_logger.setLevel(log_level)
|
||||
|
||||
log_file = cloud_config.config.get('log_file', None)
|
||||
log_file = cloud_config.config.get('log_file')
|
||||
if log_file:
|
||||
if not self.file_logger:
|
||||
self.file_logger = logging.FileHandler(filename=log_file)
|
||||
@ -179,7 +179,7 @@ class LogConfigurator(object):
|
||||
self.file_logger.setLevel(log_level)
|
||||
self.root_logger.addHandler(self.file_logger)
|
||||
|
||||
logconfig = cloud_config.config.get('logging', None)
|
||||
logconfig = cloud_config.config.get('logging')
|
||||
if logconfig:
|
||||
highest_level = logging.NOTSET
|
||||
for k in logconfig.keys():
|
||||
|
Loading…
Reference in New Issue
Block a user