Example #1
0
    def acl(self, request):
        content_type = 'application/json'

        if 'packages' in request.json_body:
            packages = request.json_body['packages']
            unregistered_package = {
                'name': 'unregistered-snap-name',
                'series': '16',
            }
            if unregistered_package in packages:
                return response.Response(
                    json.dumps({
                        'error_message':
                        "Snap not found for the given snap "
                        "name: 'unregistered-snap-name' and "
                        "series: '16'",
                    }).encode(), 404, [('Content-Type', content_type)])

        permission = request.path.split('/')[-1]
        logger.debug('Handling ACL request for {}'.format(permission))
        sso_host = urllib.parse.urlparse(
            os.environ.get('UBUNTU_SSO_API_ROOT_URL',
                           "http://localhost")).netloc
        macaroon = pymacaroons.Macaroon(caveats=[
            pymacaroons.Caveat(caveat_id='test caveat',
                               location=sso_host,
                               verification_key_id='test verifiacion')
        ])
        payload = json.dumps({'macaroon': macaroon.serialize()}).encode()
        response_code = 200
        return response.Response(payload, response_code,
                                 [('Content-Type', content_type)])
Example #2
0
 def _handle_acl_request(self, permission):
     logger.debug('Handling ACL request for {}'.format(permission))
     self.send_response(200)
     self.send_header('Content-Type', 'application/json')
     self.end_headers()
     macaroon = pymacaroons.Macaroon(caveats=[
         pymacaroons.Caveat(caveat_id='test caveat',
                            location='localhost',
                            verification_key_id='test verifiacion')
     ])
     response = {'macaroon': macaroon.serialize()}
     self.wfile.write(json.dumps(response).encode())
Example #3
0
 def _handle_acl_request(self, permission):
     logger.debug('Handling ACL request for {}'.format(permission))
     self.send_response(200)
     self.send_header('Content-Type', 'application/json')
     self.end_headers()
     sso_host = urllib.parse.urlparse(
         os.environ.get('UBUNTU_SSO_API_ROOT_URL',
                        "http://localhost")).netloc
     macaroon = pymacaroons.Macaroon(caveats=[
         pymacaroons.Caveat(caveat_id='test caveat',
                            location=sso_host,
                            verification_key_id='test verifiacion')
     ])
     response = {'macaroon': macaroon.serialize()}
     self.wfile.write(json.dumps(response).encode())
Example #4
0
 def acl(self, request):
     permission = request.path.split('/')[-1]
     logger.debug('Handling ACL request for {}'.format(permission))
     sso_host = urllib.parse.urlparse(
         os.environ.get('UBUNTU_SSO_API_ROOT_URL',
                        "http://localhost")).netloc
     macaroon = pymacaroons.Macaroon(caveats=[
         pymacaroons.Caveat(caveat_id='test caveat',
                            location=sso_host,
                            verification_key_id='test verifiacion')
     ])
     payload = json.dumps({'macaroon': macaroon.serialize()}).encode()
     response_code = 200
     content_type = 'application/json'
     return response.Response(payload, response_code,
                              [('Content-Type', content_type)])
Example #5
0
    def acl(self, request):
        content_type = "application/json"

        if "packages" in request.json_body:
            packages = request.json_body["packages"]
            unregistered_package = {"name": "unregistered-snap-name", "series": "16"}
            if unregistered_package in packages:
                return response.Response(
                    json.dumps(
                        {
                            "error_message": "Snap not found for the given snap "
                            "name: 'unregistered-snap-name' and "
                            "series: '16'"
                        }
                    ).encode(),
                    404,
                    [("Content-Type", content_type)],
                )

        permission = request.path.split("/")[-1]
        logger.debug("Handling ACL request for {}".format(permission))
        sso_host = urllib.parse.urlparse(
            os.environ.get("UBUNTU_SSO_API_ROOT_URL", "http://localhost")
        ).netloc
        macaroon = pymacaroons.Macaroon(
            caveats=[
                pymacaroons.Caveat(
                    caveat_id="test caveat",
                    location=sso_host,
                    verification_key_id="test verifiacion",
                )
            ]
        )
        payload = json.dumps({"macaroon": macaroon.serialize()}).encode()
        response_code = 200
        return response.Response(
            payload, response_code, [("Content-Type", content_type)]
        )
Example #6
0
def fpcaveat(s):
    return pymacaroons.Caveat(caveat_id=s.encode('utf-8'))