Exemplo n.º 1
0
 def grant(self, instance, username, databases, hostname=None):
     """Allow an existing user permissions to access a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     dbs = {'databases': [{'name': db} for db in databases]}
     resp, body = self.api.client.put(url % locals(), body=dbs)
     check_for_exceptions(resp, body)
Exemplo n.º 2
0
    def get(self, instance, username, hostname=None):
        """Get a single User from the instance's Database.

        :rtype: :class:`User`.
        """
        user = common.quote_user_host(username, hostname)
        url = "/instances/%s/users/%s" % (base.getid(instance), user)
        return self._get(url, "user")
Exemplo n.º 3
0
 def revoke(self, instance, username, database, hostname=None):
     """Revoke from an existing user access permissions to a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = ("/instances/%(instance_id)s/users/%(user)s/"
            "databases/%(database)s")
     resp, body = self.api.client.delete(url % locals())
     check_for_exceptions(resp, body)
Exemplo n.º 4
0
 def revoke(self, instance, username, database, hostname=None):
     """Revoke from an existing user access permissions to a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/" "databases/%(database)s"
     local_vars = locals()
     resp, body = self.api.client.delete(url % local_vars)
     check_for_exceptions(resp, body)
Exemplo n.º 5
0
 def grant(self, instance, username, databases, hostname=None):
     """Allow an existing user permissions to access a database."""
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     dbs = {'databases': [{'name': db} for db in databases]}
     resp, body = self.api.client.put(url % locals(), body=dbs)
     check_for_exceptions(resp, body)
Exemplo n.º 6
0
    def get(self, instance, username, hostname=None):
        """Get a single User from the instance's Database.

        :rtype: :class:`User`.
        """
        user = common.quote_user_host(username, hostname)
        url = "/instances/%s/users/%s" % (base.getid(instance), user)
        return self._get(url, "user")
Exemplo n.º 7
0
 def list_access(self, instance, username, hostname=None):
     """Show all databases the given user has access to. """
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     resp, body = self.api.client.get(url % locals())
     check_for_exceptions(resp, body)
     if not body:
         raise Exception("Call to %s did not return to a body" % url)
     return [databases.Database(self, db) for db in body['databases']]
Exemplo n.º 8
0
 def list_access(self, instance, username, hostname=None):
     """Show all databases the given user has access to. """
     instance_id = base.getid(instance)
     user = quote_user_host(username, hostname)
     url = "/instances/%(instance_id)s/users/%(user)s/databases"
     resp, body = self.api.client.get(url % locals())
     check_for_exceptions(resp, body)
     if not body:
         raise Exception("Call to %s did not return to a body" % url)
     return [databases.Database(self, db) for db in body['databases']]
Exemplo n.º 9
0
    def update_attributes(self, instance, username, newuserattr=None,
                          hostname=None):
        """Update attributes of a single User in an instance.

        :rtype: :class:`User`.
        """
        if not newuserattr:
            raise Exception("No updates specified for user %s" % username)
        instance_id = base.getid(instance)
        user = common.quote_user_host(username, hostname)
        user_dict = {}
        user_dict['user'] = newuserattr
        url = "/instances/%s/users/%s" % (instance_id, user)
        resp, body = self.api.client.put(url, body=user_dict)
        common.check_for_exceptions(resp, body, url)
Exemplo n.º 10
0
    def update_attributes(self, instance, username, newuserattr=None, hostname=None):
        """
        Update attributes of a single User in an instance.

        :rtype: :class:`User`.
        """
        instance_id = base.getid(instance)
        user = quote_user_host(username, hostname)
        user_dict = {}
        if not newuserattr:
            newuserattr = {}
        else:
            user_dict["user"] = newuserattr
        url = "/instances/%s/users/%s" % (instance_id, user)
        resp, body = self.api.client.put(url, body=user_dict)
        check_for_exceptions(resp, body)
Exemplo n.º 11
0
    def update_attributes(self,
                          instance,
                          username,
                          newuserattr=None,
                          hostname=None):
        """
        Update attributes of a single User in an instance.

        :rtype: :class:`User`.
        """
        instance_id = base.getid(instance)
        user = quote_user_host(username, hostname)
        user_dict = {}
        if not newuserattr:
            newuserattr = {}
        else:
            user_dict['user'] = newuserattr
        url = "/instances/%s/users/%s" % (instance_id, user)
        resp, body = self.api.client.put(url, body=user_dict)
        check_for_exceptions(resp, body)
Exemplo n.º 12
0
 def delete(self, instance_id, username, hostname=None):
     """Delete an existing user in the specified instance"""
     user = quote_user_host(username, hostname)
     url = "/instances/%s/users/%s" % (instance_id, user)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
Exemplo n.º 13
0
 def delete(self, instance, username, hostname=None):
     """Delete an existing user in the specified instance."""
     user = common.quote_user_host(username, hostname)
     url = "/instances/%s/users/%s" % (base.getid(instance), user)
     resp, body = self.api.client.delete(url)
     common.check_for_exceptions(resp, body, url)
Exemplo n.º 14
0
 def delete(self, instance_id, username, hostname=None):
     """Delete an existing user in the specified instance"""
     user = quote_user_host(username, hostname)
     url = "/instances/%s/users/%s" % (instance_id, user)
     resp, body = self.api.client.delete(url)
     check_for_exceptions(resp, body)
Exemplo n.º 15
0
 def delete(self, instance, username, hostname=None):
     """Delete an existing user in the specified instance."""
     user = common.quote_user_host(username, hostname)
     url = "/instances/%s/users/%s" % (base.getid(instance), user)
     resp, body = self.api.client.delete(url)
     common.check_for_exceptions(resp, body, url)