consistent i18n placeholders (flake8 H701, H702, H703)
- eliminates ambiguously defined keywords in i18n strings which may become incorrectly ordered in a corresponding translation. - ensures formatting operations occur outside of i18n calls - use bare multiline string concatenation instead of 'ab' + \n 'cd' - eliminates an 'empty localization string' (passing a variable to i18n function) Change-Id: I0d78b978cc730e5fb892b80dfacaaf6687cd80be
This commit is contained in:
committed by
Gerrit Code Review
parent
67175a6673
commit
f9b535c84e
@@ -15,10 +15,9 @@ DEFAULT_DOMAIN_ID = CONF.identity.default_domain_id
|
|||||||
|
|
||||||
|
|
||||||
def _build_policy_check_credentials(self, action, context, kwargs):
|
def _build_policy_check_credentials(self, action, context, kwargs):
|
||||||
|
LOG.debug(_('RBAC: Authorizing %(action)s(%(kwargs)s)') % {
|
||||||
LOG.debug(_('RBAC: Authorizing %s(%s)') % (
|
'action': action,
|
||||||
action,
|
'kwargs': ', '.join(['%s=%s' % (k, kwargs[k]) for k in kwargs])})
|
||||||
', '.join(['%s=%s' % (k, kwargs[k]) for k in kwargs])))
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token_ref = self.token_api.get_token(
|
token_ref = self.token_api.get_token(
|
||||||
|
|||||||
@@ -84,17 +84,21 @@ def parse_tls_cert(opt):
|
|||||||
try:
|
try:
|
||||||
return LDAP_TLS_CERTS[opt]
|
return LDAP_TLS_CERTS[opt]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError((_('Invalid LDAP tls certs option: %s. '
|
raise ValueError(_(
|
||||||
'Choose one of: ') %
|
'Invalid LDAP TLS certs option: %(option). '
|
||||||
opt) + ', '.join(LDAP_TLS_CERTS.keys()))
|
'Choose one of: %(options)s') % {
|
||||||
|
'option': opt,
|
||||||
|
'options': ', '.join(LDAP_TLS_CERTS.keys())})
|
||||||
|
|
||||||
|
|
||||||
def ldap_scope(scope):
|
def ldap_scope(scope):
|
||||||
try:
|
try:
|
||||||
return LDAP_SCOPES[scope]
|
return LDAP_SCOPES[scope]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError(_('Invalid LDAP scope: %s. Choose one of: ' % scope) +
|
raise ValueError(
|
||||||
', '.join(LDAP_SCOPES.keys()))
|
_('Invalid LDAP scope: %(scope)s. Choose one of: %(options)s') % {
|
||||||
|
'scope': scope,
|
||||||
|
'options': ', '.join(LDAP_SCOPES.keys())})
|
||||||
|
|
||||||
|
|
||||||
class BaseLdap(object):
|
class BaseLdap(object):
|
||||||
@@ -182,9 +186,10 @@ class BaseLdap(object):
|
|||||||
try:
|
try:
|
||||||
ldap_attr, attr_map = item.split(':')
|
ldap_attr, attr_map = item.split(':')
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.warn(_('Invalid additional attribute mapping: "%s". '
|
LOG.warn(_(
|
||||||
'Format must be ' +
|
'Invalid additional attribute mapping: "%s". '
|
||||||
'<ldap_attribute>:<keystone_attribute>') % item)
|
'Format must be <ldap_attribute>:<keystone_attribute>')
|
||||||
|
% item)
|
||||||
continue
|
continue
|
||||||
if attr_map not in self.attribute_mapping:
|
if attr_map not in self.attribute_mapping:
|
||||||
LOG.warn(_('Invalid additional attribute mapping: "%(item)s". '
|
LOG.warn(_('Invalid additional attribute mapping: "%(item)s". '
|
||||||
@@ -500,16 +505,19 @@ class LdapWrapper(object):
|
|||||||
if kind != 'userPassword'
|
if kind != 'userPassword'
|
||||||
else ['****'])
|
else ['****'])
|
||||||
for kind, values in ldap_attrs]
|
for kind, values in ldap_attrs]
|
||||||
LOG.debug(_('LDAP add: dn=%s, attrs=%s'), dn, sane_attrs)
|
LOG.debug(_('LDAP add: dn=%(dn)s, attrs=%(attrs)s') % {
|
||||||
|
'dn': dn, 'attrs': sane_attrs})
|
||||||
return self.conn.add_s(dn, ldap_attrs)
|
return self.conn.add_s(dn, ldap_attrs)
|
||||||
|
|
||||||
def search_s(self, dn, scope, query, attrlist=None):
|
def search_s(self, dn, scope, query, attrlist=None):
|
||||||
if LOG.isEnabledFor(logging.DEBUG):
|
if LOG.isEnabledFor(logging.DEBUG):
|
||||||
LOG.debug(_('LDAP search: dn=%s, scope=%s, query=%s, attrs=%s'),
|
LOG.debug(_(
|
||||||
dn,
|
'LDAP search: dn=%(dn)s, scope=%(scope)s, query=%(query)s, '
|
||||||
scope,
|
'attrs=%(attrs)s') % {
|
||||||
query,
|
'dn': dn,
|
||||||
attrlist)
|
'scope': scope,
|
||||||
|
'query': query,
|
||||||
|
'attrlist': attrlist})
|
||||||
if self.page_size:
|
if self.page_size:
|
||||||
res = self.paged_search_s(dn, scope, query, attrlist)
|
res = self.paged_search_s(dn, scope, query, attrlist)
|
||||||
else:
|
else:
|
||||||
@@ -573,7 +581,8 @@ class LdapWrapper(object):
|
|||||||
sane_modlist = [(op, kind, (values if kind != 'userPassword'
|
sane_modlist = [(op, kind, (values if kind != 'userPassword'
|
||||||
else ['****']))
|
else ['****']))
|
||||||
for op, kind, values in ldap_modlist]
|
for op, kind, values in ldap_modlist]
|
||||||
LOG.debug(_("LDAP modify: dn=%s, modlist=%s"), dn, sane_modlist)
|
LOG.debug(_('LDAP modify: dn=%(dn)s, modlist=%(modlist)s') % {
|
||||||
|
'dn': dn, 'modlist': sane_modlist})
|
||||||
|
|
||||||
return self.conn.modify_s(dn, ldap_modlist)
|
return self.conn.modify_s(dn, ldap_modlist)
|
||||||
|
|
||||||
@@ -582,7 +591,9 @@ class LdapWrapper(object):
|
|||||||
return self.conn.delete_s(dn)
|
return self.conn.delete_s(dn)
|
||||||
|
|
||||||
def delete_ext_s(self, dn, serverctrls):
|
def delete_ext_s(self, dn, serverctrls):
|
||||||
LOG.debug(_("LDAP delete_ext: dn=%s, serverctrls=%s"), dn, serverctrls)
|
LOG.debug(
|
||||||
|
_('LDAP delete_ext: dn=%(dn)s, serverctrls=%(serverctrls)s') % {
|
||||||
|
'dn': dn, 'serverctrls': serverctrls})
|
||||||
return self.conn.delete_ext_s(dn, serverctrls)
|
return self.conn.delete_ext_s(dn, serverctrls)
|
||||||
|
|
||||||
def _disable_paging(self):
|
def _disable_paging(self):
|
||||||
|
|||||||
@@ -187,7 +187,8 @@ class FakeLdap(object):
|
|||||||
raise ldap.SERVER_DOWN
|
raise ldap.SERVER_DOWN
|
||||||
|
|
||||||
key = '%s%s' % (self.__prefix, dn)
|
key = '%s%s' % (self.__prefix, dn)
|
||||||
LOG.debug(_('FakeLdap add item: dn=%s, attrs=%s'), dn, attrs)
|
LOG.debug(_('FakeLdap add item: dn=%(dn)s, attrs=%(attrs)s') % {
|
||||||
|
'dn': dn, 'attrs': attrs})
|
||||||
if key in self.db:
|
if key in self.db:
|
||||||
LOG.debug(_('FakeLdap add item failed: dn=%s is'
|
LOG.debug(_('FakeLdap add item failed: dn=%s is'
|
||||||
' already in store.'), dn)
|
' already in store.'), dn)
|
||||||
@@ -236,7 +237,8 @@ class FakeLdap(object):
|
|||||||
raise ldap.SERVER_DOWN
|
raise ldap.SERVER_DOWN
|
||||||
|
|
||||||
key = '%s%s' % (self.__prefix, dn)
|
key = '%s%s' % (self.__prefix, dn)
|
||||||
LOG.debug(_('FakeLdap modify item: dn=%s attrs=%s'), dn, attrs)
|
LOG.debug(_('FakeLdap modify item: dn=%(dn)s attrs=%(attrs)s') % {
|
||||||
|
'dn': dn, 'attrs': attrs})
|
||||||
try:
|
try:
|
||||||
entry = self.db[key]
|
entry = self.db[key]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@@ -268,9 +270,10 @@ class FakeLdap(object):
|
|||||||
try:
|
try:
|
||||||
values.remove(val)
|
values.remove(val)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
LOG.debug(_('FakeLdap modify item failed:'
|
LOG.debug(_('FakeLdap modify item failed: '
|
||||||
' item has no attribute "%s" with'
|
'item has no attribute "%(k)s" with '
|
||||||
' value "%s" to delete'), k, val)
|
'value "%(v)s" to delete') % {
|
||||||
|
'k': k, 'v': val})
|
||||||
raise ldap.NO_SUCH_ATTRIBUTE
|
raise ldap.NO_SUCH_ATTRIBUTE
|
||||||
else:
|
else:
|
||||||
LOG.debug(_('FakeLdap modify item failed: unknown'
|
LOG.debug(_('FakeLdap modify item failed: unknown'
|
||||||
@@ -293,8 +296,9 @@ class FakeLdap(object):
|
|||||||
if server_fail:
|
if server_fail:
|
||||||
raise ldap.SERVER_DOWN
|
raise ldap.SERVER_DOWN
|
||||||
|
|
||||||
LOG.debug(_('FakeLdap search at dn=%s scope=%s query=%s'),
|
LOG.debug(
|
||||||
dn, SCOPE_NAMES.get(scope, scope), query)
|
_('FakeLdap search at dn=%(dn)s scope=%(scope)s query=%(query)s') %
|
||||||
|
{'dn': dn, 'scope': SCOPE_NAMES.get(scope, scope), 'query': query})
|
||||||
if scope == ldap.SCOPE_BASE:
|
if scope == ldap.SCOPE_BASE:
|
||||||
try:
|
try:
|
||||||
item_dict = self.db['%s%s' % (self.__prefix, dn)]
|
item_dict = self.db['%s%s' % (self.__prefix, dn)]
|
||||||
|
|||||||
@@ -85,7 +85,8 @@ def _create_memberships(api, memberships, user_map, tenant_map):
|
|||||||
for membership in memberships:
|
for membership in memberships:
|
||||||
user_id = user_map[membership['user_id']]
|
user_id = user_map[membership['user_id']]
|
||||||
tenant_id = tenant_map[membership['tenant_id']]
|
tenant_id = tenant_map[membership['tenant_id']]
|
||||||
LOG.debug(_('Add user %s to tenant %s') % (user_id, tenant_id))
|
LOG.debug(_('Add user %(user_id)s to tenant %(tenant_id)s') % {
|
||||||
|
'user_id': user_id, 'tenant_id': tenant_id})
|
||||||
api.add_user_to_project(tenant_id, user_id)
|
api.add_user_to_project(tenant_id, user_id)
|
||||||
|
|
||||||
|
|
||||||
@@ -110,8 +111,12 @@ def _assign_roles(api, assignments, role_map, user_map, tenant_map):
|
|||||||
role_id = role_map[assignment['role']]
|
role_id = role_map[assignment['role']]
|
||||||
user_id = user_map[assignment['user_id']]
|
user_id = user_map[assignment['user_id']]
|
||||||
tenant_id = tenant_map[assignment['tenant_id']]
|
tenant_id = tenant_map[assignment['tenant_id']]
|
||||||
LOG.debug(_('Assign role %s to user %s on tenant %s') %
|
LOG.debug(_(
|
||||||
(role_id, user_id, tenant_id))
|
'Assign role %(role_id)s to user %(user_id)s on tenant '
|
||||||
|
'%(tenant_id)s') % {
|
||||||
|
'role_id': role_id,
|
||||||
|
'user_id': user_id,
|
||||||
|
'tenant_id': tenant_id})
|
||||||
api.add_role_to_user_and_project(user_id, tenant_id, role_id)
|
api.add_role_to_user_and_project(user_id, tenant_id, role_id)
|
||||||
|
|
||||||
|
|
||||||
@@ -125,6 +130,8 @@ def _create_ec2_creds(ec2_api, identity_api, ec2_creds, user_map):
|
|||||||
'user_id': user_id,
|
'user_id': user_id,
|
||||||
'tenant_id': tenant_id,
|
'tenant_id': tenant_id,
|
||||||
}
|
}
|
||||||
LOG.debug(_('Creating ec2 cred for user %s and tenant %s') %
|
LOG.debug(_(
|
||||||
(user_id, tenant_id))
|
'Creating ec2 cred for user %(user_id)s and tenant '
|
||||||
|
'%(tenant_id)s') % {
|
||||||
|
'user_id': user_id, 'tenant_id': tenant_id})
|
||||||
ec2_api.create_credential(None, cred_dict)
|
ec2_api.create_credential(None, cred_dict)
|
||||||
|
|||||||
@@ -217,10 +217,6 @@ def hash_signed_token(signed_text):
|
|||||||
|
|
||||||
def setup_remote_pydev_debug():
|
def setup_remote_pydev_debug():
|
||||||
if CONF.pydev_debug_host and CONF.pydev_debug_port:
|
if CONF.pydev_debug_host and CONF.pydev_debug_port:
|
||||||
error_msg = ('Error setting up the debug environment. Verify that the'
|
|
||||||
' option --debug-url has the format <host>:<port> and '
|
|
||||||
'that a debugger processes is listening on that port.')
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
from pydevd import pydevd
|
from pydevd import pydevd
|
||||||
@@ -233,7 +229,10 @@ def setup_remote_pydev_debug():
|
|||||||
stderrToServer=True)
|
stderrToServer=True)
|
||||||
return True
|
return True
|
||||||
except:
|
except:
|
||||||
LOG.exception(_(error_msg))
|
LOG.exception(_(
|
||||||
|
'Error setting up the debug environment. Verify that the '
|
||||||
|
'option --debug-url has the format <host>:<port> and that a '
|
||||||
|
'debugger processes is listening on that port.'))
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,9 @@ class Application(BaseApplication):
|
|||||||
try:
|
try:
|
||||||
result = method(context, **params)
|
result = method(context, **params)
|
||||||
except exception.Unauthorized as e:
|
except exception.Unauthorized as e:
|
||||||
LOG.warning(_("Authorization failed. %s from %s")
|
LOG.warning(
|
||||||
% (e, req.environ['REMOTE_ADDR']))
|
_('Authorization failed. %(exception)s from %(remote_addr)s') %
|
||||||
|
{'exception': e, 'remote_addr': req.environ['REMOTE_ADDR']})
|
||||||
return render_exception(e)
|
return render_exception(e)
|
||||||
except exception.Error as e:
|
except exception.Error as e:
|
||||||
LOG.warning(e)
|
LOG.warning(e)
|
||||||
|
|||||||
@@ -922,9 +922,9 @@ class GroupApi(common_ldap.BaseLdap, ApiShimMixin):
|
|||||||
self.member_attribute,
|
self.member_attribute,
|
||||||
self.user_api._id_to_dn(user_id))])
|
self.user_api._id_to_dn(user_id))])
|
||||||
except ldap.TYPE_OR_VALUE_EXISTS:
|
except ldap.TYPE_OR_VALUE_EXISTS:
|
||||||
msg = _('User %s is already a member of group %s'
|
raise exception.Conflict(_(
|
||||||
% (user_id, group_id))
|
'User %(user_id)s is already a member of group %(group_id)s') %
|
||||||
raise exception.Conflict(msg)
|
{'user_id': user_id, 'group_id': group_id})
|
||||||
|
|
||||||
def remove_user(self, user_id, group_id):
|
def remove_user(self, user_id, group_id):
|
||||||
conn = self.get_connection()
|
conn = self.get_connection()
|
||||||
|
|||||||
@@ -421,9 +421,9 @@ class Identity(sql.Base, identity.Driver):
|
|||||||
metadata_ref = self.get_metadata(user_id, tenant_id)
|
metadata_ref = self.get_metadata(user_id, tenant_id)
|
||||||
roles = set(metadata_ref.get('roles', []))
|
roles = set(metadata_ref.get('roles', []))
|
||||||
if role_id not in roles:
|
if role_id not in roles:
|
||||||
msg = _('Cannot remove role that has not been granted, %s' %
|
raise exception.RoleNotFound(message=_(
|
||||||
|
'Cannot remove role that has not been granted, %s') %
|
||||||
role_id)
|
role_id)
|
||||||
raise exception.RoleNotFound(message=msg)
|
|
||||||
roles.remove(role_id)
|
roles.remove(role_id)
|
||||||
metadata_ref['roles'] = list(roles)
|
metadata_ref['roles'] = list(roles)
|
||||||
if len(roles):
|
if len(roles):
|
||||||
|
|||||||
@@ -90,5 +90,7 @@ def enforce(credentials, action, target, do_raise=True):
|
|||||||
|
|
||||||
class Policy(policy.Driver):
|
class Policy(policy.Driver):
|
||||||
def enforce(self, credentials, action, target):
|
def enforce(self, credentials, action, target):
|
||||||
LOG.debug(_('enforce %s: %s'), action, credentials)
|
LOG.debug(_('enforce %(action)s: %(credentials)s') % {
|
||||||
|
'action': action,
|
||||||
|
'credentials': credentials})
|
||||||
enforce(credentials, action, target)
|
enforce(credentials, action, target)
|
||||||
|
|||||||
5
tox.ini
5
tox.ini
@@ -40,10 +40,7 @@ show-source = true
|
|||||||
# H402: one line docstring needs punctuation
|
# H402: one line docstring needs punctuation
|
||||||
# H403: multi line docstring end on new line
|
# H403: multi line docstring end on new line
|
||||||
# H404: multi line docstring should start with a summary
|
# H404: multi line docstring should start with a summary
|
||||||
# H701: empty localization string
|
ignore = H201,H301,H302,H304,H306,H401,H402,H403,H404
|
||||||
# H702: use bare string concatenation instead of +; formatting operation should be outside of localization method call
|
|
||||||
# H703: multiple positional placeholders
|
|
||||||
ignore = H201,H301,H302,H304,H306,H401,H402,H403,H404,H701,H702,H703
|
|
||||||
|
|
||||||
builtins = _
|
builtins = _
|
||||||
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools,vendor
|
exclude=.venv,.git,.tox,dist,doc,*openstack/common*,*lib/python*,*egg,tools,vendor
|
||||||
|
|||||||
Reference in New Issue
Block a user