Ejemplo n.º 1
0
    def delete_app(self, app):
        """Delete app.

        Parameters:
            app (str): The application ID
        Returns:
            bool
        """
        app = extract_id(app)
        method = 'DELETE'
        path = self.path('map', 'app-id', app)
        response = yield from self.req_handler(method, path)
        return ok(response)
Ejemplo n.º 2
0
    def delete_user(self, user):
        """Delete user.

        Parameters:
            user (str): The user name
        Returns:
            bool
        """
        user = extract_id(user)
        method = 'DELETE'
        path = self.path('map', 'user-id', user)
        response = yield from self.req_handler(method, path)
        return ok(response)
Ejemplo n.º 3
0
    def delete_app(self, app):
        """Delete app.

        Parameters:
            app (str): The application ID
        Returns:
            bool
        """
        app = extract_id(app)
        method = 'DELETE'
        path = self.path('map', 'app-id', app)
        response = yield from self.req_handler(method, path)
        return ok(response)
Ejemplo n.º 4
0
    def delete_user(self, user):
        """Delete user.

        Parameters:
            user (str): The user name
        Returns:
            bool
        """
        user = extract_id(user)
        method = 'DELETE'
        path = self.path('map', 'user-id', user)
        response = yield from self.req_handler(method, path)
        return ok(response)
Ejemplo n.º 5
0
    def read_app(self, app):
        """Read app.

        Parameters:
            app (str): The application ID
        Returns:
            Value
        """
        app = extract_id(app)
        method = 'GET'
        path = self.path('map', 'app-id', app)
        response = yield from self.req_handler(method, path)
        result = yield from response.json()
        return Value(**result)
Ejemplo n.º 6
0
    def read_app(self, app):
        """Read app.

        Parameters:
            app (str): The application ID
        Returns:
            Value
        """
        app = extract_id(app)
        method = 'GET'
        path = self.path('map', 'app-id', app)
        response = yield from self.req_handler(method, path)
        result = yield from response.json()
        return Value(**result)
Ejemplo n.º 7
0
    def read_user(self, user):
        """Read user.

        Parameters:
            user (str): The user name
        Returns:
            Value
        """
        user = extract_id(user)
        method = 'GET'
        path = self.path('map', 'user-id', user)
        response = yield from self.req_handler(method, path)
        result = yield from response.json()
        return Value(**result)
Ejemplo n.º 8
0
    def read_user(self, user):
        """Read user.

        Parameters:
            user (str): The user name
        Returns:
            Value
        """
        user = extract_id(user)
        method = 'GET'
        path = self.path('map', 'user-id', user)
        response = yield from self.req_handler(method, path)
        result = yield from response.json()
        return Value(**result)
Ejemplo n.º 9
0
    def revoke(self, token):
        """Revokes a token and all child tokens.

        When the token is revoked, all secrets generated with it are also
        revoked.

        Parameters:
            token (str): The token ID
        """
        token = extract_id(token)
        method = 'POST'
        path = self.token_path('revoke', token)

        response = yield from self.req_handler(method, path)
        result = yield from response.json()
        return result
Ejemplo n.º 10
0
    def revoke_orphan(self, token):
        """Revokes a token but not its child tokens.

        When the token is revoked, all secrets generated with it are also
        revoked. All child tokens are orphaned, but can be revoked
        sub-sequently using :py:meth:`revoke`.

        Parameters:
            token (str): The token ID
        """
        token = extract_id(token)
        method = 'POST'
        path = self.token_path('revoke-orphan', token)

        response = yield from self.req_handler(method, path)
        result = yield from response.json()
        return result
Ejemplo n.º 11
0
    def write_user(self, user, app, cidr_block=None):
        """Write user.

        Parameters:
            user (str): The user name
            app (str): The application ID
            cidr_block (str): The CIDR block to limit
        Returns:
            bool
        """
        app = extract_id(app)
        user = extract_name(user)
        method = 'POST'
        path = self.path('map', 'user-id', user)
        data = {'value': app, 'cidr_block': cidr_block}

        response = yield from self.req_handler(method, path, json=data)
        return ok(response)
Ejemplo n.º 12
0
    def lookup(self, token):
        """Returns information about a client token.

        Parameters:
            token (str): The token ID
        Returns:
            ReadToken: The client token
        """
        token = extract_id(token)
        method = 'GET'
        path = self.token_path('lookup', token)

        try:
            response = yield from self.req_handler(method, path)
            result = yield from response.json()
            return ReadToken(**result)
        except (InvalidPath, BadToken):
            raise KeyError('%r does not exists' % token)
Ejemplo n.º 13
0
    def write_app(self, app, *, policies=None, display_name=None):
        """Write app.

        Parameters:
            app (str): The application ID
            policies (list): The policies
            display_name (str): The name to be displayed
        Returns:
            bool
        """
        app = extract_id(app)
        method = 'POST'
        path = self.path('map', 'app-id', app)
        policies = format_policies(policies)

        data = {'display_name': display_name or app, 'value': policies}

        response = yield from self.req_handler(method, path, json=data)
        return ok(response)
Ejemplo n.º 14
0
    def write_user(self, user, app, cidr_block=None):
        """Write user.

        Parameters:
            user (str): The user name
            app (str): The application ID
            cidr_block (str): The CIDR block to limit
        Returns:
            bool
        """
        app = extract_id(app)
        user = extract_name(user)
        method = 'POST'
        path = self.path('map', 'user-id', user)
        data = {'value': app,
                'cidr_block': cidr_block}

        response = yield from self.req_handler(method, path, json=data)
        return ok(response)
Ejemplo n.º 15
0
    def write_app(self, app, *, policies=None, display_name=None):
        """Write app.

        Parameters:
            app (str): The application ID
            policies (list): The policies
            display_name (str): The name to be displayed
        Returns:
            bool
        """
        app = extract_id(app)
        method = 'POST'
        path = self.path('map', 'app-id', app)
        policies = format_policies(policies)

        data = {'display_name': display_name or app,
                'value': policies}

        response = yield from self.req_handler(method, path, json=data)
        return ok(response)
Ejemplo n.º 16
0
    def login(self, *, app, user):
        """Returns information about the current client token.

        Parameters:
            app (str): The application ID
            user (str): The user name
        Returns:
            LoginToken: The client token
        """
        method = 'POST'
        path = self.path('login')
        app = extract_id(app)
        user = extract_name(user)
        data = {'app_id': app, 'user_id': user}

        token = yield from authenticate(self.req_handler,
                                        method,
                                        path,
                                        json=data)
        return token
Ejemplo n.º 17
0
    def login(self, *, app, user):
        """Returns information about the current client token.

        Parameters:
            app (str): The application ID
            user (str): The user name
        Returns:
            LoginToken: The client token
        """
        method = 'POST'
        path = self.path('login')
        app = extract_id(app)
        user = extract_name(user)
        data = {'app_id': app,
                'user_id': user}

        token = yield from authenticate(self.req_handler,
                                        method,
                                        path,
                                        json=data)
        return token
Ejemplo n.º 18
0
    def renew(self, token, increment=None):
        """Renews a lease associated with a token.

        This is used to prevent the expiration of a token, and the automatic
        revocation of it.

        Parameters:
            token (str): The token ID
            increment (int): An optional requested lease increment can be
                             provided. This increment may be ignored.
        Returns:
            LoginToken: The client token
        """
        token = extract_id(token)
        method = 'POST'
        path = self.token_path('renew', token)
        data = {'increment': increment}

        response = yield from self.req_handler(method, path, json=data)
        result = yield from response.json()
        return LoginToken(**result)