Exemplo n.º 1
0
 def _get_user(self, context, instance_id, user_id):
     username, hostname = unquote_user_host(user_id)
     try:
         user = models.User.load(context, instance_id, username, hostname)
     except (ValueError, AttributeError) as e:
         raise exception.BadRequest(msg=str(e))
     if not user:
         raise exception.UserNotFound(uuid=user_id)
     return user
Exemplo n.º 2
0
 def update(self, req, body, tenant_id, instance_id, user_id):
     """Grant access for a user to one or more databases."""
     context = req.environ[wsgi.CONTEXT_KEY]
     self.validate(body)
     user = self._get_user(context, instance_id, user_id)
     username, hostname = unquote_user_host(user_id)
     databases = [db['name'] for db in body['databases']]
     models.User.grant(context, instance_id, username, hostname, databases)
     return wsgi.Result(None, 202)
Exemplo n.º 3
0
 def update(self, req, body, tenant_id, instance_id, user_id):
     """Grant access for a user to one or more databases."""
     context = req.environ[wsgi.CONTEXT_KEY]
     self.validate(body)
     user = self._get_user(context, instance_id, user_id)
     username, hostname = unquote_user_host(user_id)
     databases = [db['name'] for db in body['databases']]
     models.User.grant(context, instance_id, username, hostname, databases)
     return wsgi.Result(None, 202)
Exemplo n.º 4
0
 def _get_user(self, context, instance_id, user_id):
     username, hostname = unquote_user_host(user_id)
     try:
         user = models.User.load(context, instance_id, username, hostname)
     except ValueError as ve:
         raise exception.BadRequest(str(ve))
     if not user:
         raise exception.UserNotFound(uuid=user_id)
     return user
Exemplo n.º 5
0
 def _get_user(self, context, instance_id, user_id):
     username, hostname = unquote_user_host(user_id)
     try:
         user = models.User.load(context, instance_id, username, hostname)
     except (ValueError, AttributeError) as e:
         raise exception.BadRequest(msg=e)
     if not user:
         raise exception.UserNotFound(uuid=user_id)
     return user
Exemplo n.º 6
0
 def index(self, req, tenant_id, instance_id, user_id):
     """Show permissions for the given user."""
     LOG.info(_("Showing user access for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     # Make sure this user exists.
     user = self._get_user(context, instance_id, user_id)
     username, hostname = unquote_user_host(user_id)
     access = models.User.access(context, instance_id, username, hostname)
     view = views.UserAccessView(access.databases)
     return wsgi.Result(view.data(), 200)
Exemplo n.º 7
0
 def delete(self, req, tenant_id, instance_id, user_id, id):
     """Revoke access for a user."""
     context = req.environ[wsgi.CONTEXT_KEY]
     user = self._get_user(context, instance_id, user_id)
     username, hostname = unquote_user_host(user_id)
     access = models.User.access(context, instance_id, username, hostname)
     databases = [db.name for db in access.databases]
     if not id in databases:
         raise exception.DatabaseNotFound(uuid=id)
     models.User.revoke(context, instance_id, username, hostname, id)
     return wsgi.Result(None, 202)
Exemplo n.º 8
0
 def index(self, req, tenant_id, instance_id, user_id):
     """Show permissions for the given user."""
     LOG.info(_("Showing user access for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     # Make sure this user exists.
     user = self._get_user(context, instance_id, user_id)
     username, hostname = unquote_user_host(user_id)
     access = models.User.access(context, instance_id, username, hostname)
     view = views.UserAccessView(access.databases)
     return wsgi.Result(view.data(), 200)
Exemplo n.º 9
0
 def show(self, req, tenant_id, instance_id, id):
     """Return a single user."""
     LOG.info(_("Showing a user for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     username, host = unquote_user_host(id)
     user = models.User.load(context, instance_id, username, host)
     if not user:
         raise exception.UserNotFound(uuid=id)
     view = views.UserView(user)
     return wsgi.Result(view.data(), 200)
Exemplo n.º 10
0
 def delete(self, req, tenant_id, instance_id, user_id, id):
     """Revoke access for a user."""
     context = req.environ[wsgi.CONTEXT_KEY]
     user = self._get_user(context, instance_id, user_id)
     username, hostname = unquote_user_host(user_id)
     access = models.User.access(context, instance_id, username, hostname)
     databases = [db.name for db in access.databases]
     if not id in databases:
         raise exception.DatabaseNotFound(uuid=id)
     models.User.revoke(context, instance_id, username, hostname, id)
     return wsgi.Result(None, 202)
Exemplo n.º 11
0
 def show(self, req, tenant_id, instance_id, id):
     """Return a single user."""
     LOG.info(_("Showing a user for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     username, host = unquote_user_host(id)
     user = models.User.load(context, instance_id, username, host)
     if not user:
         raise exception.UserNotFound(uuid=id)
     view = views.UserView(user)
     return wsgi.Result(view.data(), 200)
Exemplo n.º 12
0
 def delete(self, req, tenant_id, instance_id, id):
     LOG.info(_("Deleting user for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     username, host = unquote_user_host(id)
     user = None
     try:
         user = guest_models.MySQLUser()
         user.name = username
         user.host = host
         found_user = models.User.load(context, instance_id, username, host)
     except (ValueError, AttributeError) as e:
         raise exception.BadRequest(msg=e)
     if not user:
         raise exception.UserNotFound(uuid=id)
     models.User.delete(context, instance_id, user.serialize())
     return wsgi.Result(None, 202)
Exemplo n.º 13
0
 def delete(self, req, tenant_id, instance_id, id):
     LOG.info(_("Deleting user for instance '%s'") % instance_id)
     LOG.info(_("req : '%s'\n\n") % req)
     context = req.environ[wsgi.CONTEXT_KEY]
     username, host = unquote_user_host(id)
     user = None
     try:
         user = guest_models.MySQLUser()
         user.name = username
         user.host = host
         found_user = models.User.load(context, instance_id, username,
                                       host)
     except (ValueError, AttributeError) as e:
         raise exception.BadRequest(msg=e)
     if not user:
         raise exception.UserNotFound(uuid=id)
     models.User.delete(context, instance_id, user.serialize())
     return wsgi.Result(None, 202)