331
331
return mysql_config
334
def get_allowed_units(database, username):
334
def get_allowed_units(database, username, relation_id=None):
335
335
m_helper = MySQLHelper()
336
336
m_helper.connect(password=get_mysql_root_password())
337
337
allowed_units = set()
338
for relid in relation_ids('shared-db'):
339
for unit in related_units(relid):
340
hosts = relation_get(attribute="%s_%s" % (database, 'hostname'),
341
unit=unit, rid=relid)
343
hosts = [relation_get(attribute='private-address', unit=unit,
346
# hostname can be json-encoded list of hostnames
348
_hosts = json.loads(hosts)
338
for unit in related_units(relation_id):
339
settings = relation_get(rid=relation_id, unit=unit)
340
# First check for setting with prefix, then without
341
for attr in ["%s_hostname" % (database), 'hostname']:
342
hosts = settings.get(attr, None)
347
# hostname can be json-encoded list of hostnames
349
hosts = json.loads(hosts)
353
hosts = [settings['private-address']]
357
if m_helper.grant_exists(database, username, host):
358
log("Grant exists for host '%s' on db '%s'" %
359
(host, database), level=DEBUG)
360
if unit not in allowed_units:
361
allowed_units.add(unit)
354
if not isinstance(hosts, list):
359
log("Checking host '%s' grant" % (host), level=INFO)
360
if m_helper.grant_exists(database, username, host):
361
if unit not in allowed_units:
362
allowed_units.add(unit)
364
log("No hosts found for grant check", level=INFO)
363
log("Grant does NOT exist for host '%s' on db '%s'" %
364
(host, database), level=DEBUG)
366
log("No hosts found for grant check", level=INFO)
366
368
return allowed_units