Ejemplo n.º 1
0
    def delete_order(self, order_ref, delete_secret=True):
        if delete_secret:
            order = self.cl_client.get_order(order_ref)
            secret_ref = order.secret_ref
            secret_id = CloudkeepResponse.get_id_from_ref(secret_ref)
            self.secrets_client.delete_secret(secret_id)

        resp = self.cl_client.delete_order(order_ref)
        order_id = CloudkeepResponse.get_id_from_ref(order_ref)
        if order_id in self.created_orders:
            self.created_orders.remove(order_id)
        return resp
Ejemplo n.º 2
0
    def create_order(self,
                     name=None,
                     payload_content_type=None,
                     algorithm=None,
                     bit_length=None,
                     mode=None,
                     expiration=None,
                     payload_content_encoding=None):
        try:
            resp = self.orders_client.create_order(
                name=name,
                payload_content_type=payload_content_type,
                payload_content_encoding=payload_content_encoding,
                algorithm=algorithm,
                bit_length=bit_length,
                mode=mode,
                expiration=expiration)
        except ConnectionError as e:
            # Gracefully handling when Falcon doesn't properly handle our req
            if type(e.message.reason) is BadStatusLine:
                return {'status_code': 0}
            raise e

        behavior_response = CloudkeepResponse(resp=resp)
        order_id = behavior_response.id
        if order_id is not None:
            self.created_orders.append(behavior_response.id)
        return behavior_response
Ejemplo n.º 3
0
    def create_secret(self,
                      name=None,
                      expiration=None,
                      algorithm=None,
                      bit_length=None,
                      mode=None,
                      payload=None,
                      payload_content_type=None,
                      payload_content_encoding=None,
                      headers=None):
        resp = self.client.create_secret(
            name=name,
            expiration=expiration,
            algorithm=algorithm,
            bit_length=bit_length,
            mode=mode,
            payload=payload,
            payload_content_type=payload_content_type,
            payload_content_encoding=payload_content_encoding,
            headers=headers)

        behavior_response = CloudkeepResponse(resp=resp)
        secret_id = behavior_response.id
        if secret_id is not None:
            self.created_secrets.append(secret_id)
        return behavior_response
Ejemplo n.º 4
0
    def create_order_w_payload(self,
                               name=None,
                               algorithm=None,
                               bit_length=None,
                               mode=None,
                               payload_content_type=None,
                               expiration=None,
                               payload_content_encoding=None,
                               payload=None):
        """Creates an order with a plain_text value. Separate from
        standard create order method because it is used for negative
        testing only and is expected to fail.
        """
        try:
            resp = self.orders_client.create_order_w_payload(
                name=name or self.config.name,
                algorithm=algorithm or self.config.algorithm,
                bit_length=bit_length or self.config.bit_length,
                mode=mode or self.config.mode,
                expiration=expiration,
                payload_content_type=payload_content_type,
                payload_content_encoding=payload_content_encoding,
                payload=payload)
        except ConnectionError as e:
            # Gracefully handling when Falcon doesn't properly handle our req
            if type(e.message.reason) is BadStatusLine:
                return {'status_code': 0}
            raise e

        behavior_response = CloudkeepResponse(resp=resp)
        order_id = behavior_response.id
        if order_id is not None:
            self.created_orders.append(behavior_response.id)
        return behavior_response
Ejemplo n.º 5
0
 def create_secret_with_no_json(self):
     """Create a secret but do not pass any JSON in POST data."""
     resp = self.client.create_secret_with_no_json()
     behavior_response = CloudkeepResponse(resp=resp)
     secret_id = behavior_response.id
     if secret_id is not None:
         self.created_secrets.append(secret_id)
     return behavior_response
Ejemplo n.º 6
0
    def create_container(self, name, container_type, secret_refs):
        """ Proxies the ContainerClient's create_container and captures
        the resulting HATOAS ref for cleanup.
        """
        resp = self.client.create_container(
            name=name, container_type=container_type, secret_refs=secret_refs)

        if resp.entity and resp.entity.reference:
            self.created_containers.append(resp.entity.reference)

        return CloudkeepResponse(resp=resp, entity=resp.entity)
Ejemplo n.º 7
0
 def create_and_check_secret(self, name=None, expiration=None,
                             algorithm=None, bit_length=None,
                             mode=None, payload=None,
                             payload_content_type=None):
     resp = self.create_secret_overriding_cfg(
         name=name, expiration=expiration, algorithm=algorithm,
         bit_length=bit_length, mode=mode,
         payload=payload, payload_content_type=payload_content_type)
     get_resp = self.client.get_secret(resp.id)
     behavior_resp = CloudkeepResponse(resp=resp.create_resp,
                                       get_resp=get_resp)
     return behavior_resp
Ejemplo n.º 8
0
 def test_create_order_w_empty_name_checking_name(self):
     """Covers creating order with an empty name, checking that the
     created secret's name matches the secret's ID."""
     order = self.cl_behaviors.create_order(
         name='',
         mime_type=self.config.mime_type,
         algorithm=self.config.algorithm,
         bit_length=self.config.bit_length,
         mode=self.config.mode)
     secret_id = CloudkeepResponse.get_id_from_ref(order.secret_ref)
     self.assertEqual(order.secret['name'], secret_id,
                      "Name did not match secret ID")
Ejemplo n.º 9
0
    def create_and_check_order(self, name=None, expiration=None,
                               algorithm=None, bit_length=None,
                               mode=None, mime_type=None):
        order = self.create_order_overriding_cfg(
            name=name, expiration=expiration,
            algorithm=algorithm, bit_length=bit_length,
            mode=mode, mime_type=mime_type)
        resp = self.barb_client.get_order(order.id)

        behavior_response = CloudkeepResponse(entity=order,
                                              get_resp=resp)
        return behavior_response
Ejemplo n.º 10
0
 def test_create_order_w_empty_name_checking_name(self):
     """Covers creating order with an empty name, checking that the
     created secret's name matches the secret's ID."""
     order = self.cl_behaviors.create_order(
         name='',
         mime_type=self.config.mime_type,
         algorithm=self.config.algorithm,
         bit_length=self.config.bit_length,
         cypher_type=self.config.cypher_type)
     secret_id = CloudkeepResponse.get_id_from_ref(order.secret_ref)
     self.assertEqual(order.secret['name'], secret_id,
                      "Name did not match secret ID")
Ejemplo n.º 11
0
    def create_and_check_secret(self, name=None, expiration=None,
                                algorithm=None, bit_length=None,
                                mode=None, plain_text=None,
                                mime_type=None):
        secret = self.create_secret_overriding_cfg(
            name=name, expiration=expiration, algorithm=algorithm,
            bit_length=bit_length, mode=mode,
            plain_text=plain_text, mime_type=mime_type)
        resp = self.barb_client.get_secret(secret.id)

        behavior_response = CloudkeepResponse(entity=secret,
                                              get_resp=resp)
        return behavior_response
Ejemplo n.º 12
0
 def create_and_check_order(self,
                            name=None,
                            payload_content_type=None,
                            payload_content_encoding=None,
                            algorithm=None,
                            bit_length=None,
                            mode=None):
     """Creates order, gets order, and gets secret made by order."""
     resp = self.create_order_overriding_cfg(name=name,
                                             algorithm=algorithm,
                                             bit_length=bit_length,
                                             mode=mode)
     get_order_resp = self.orders_client.get_order(order_id=resp.id)
     behavior_response = CloudkeepResponse(resp=resp.create_resp,
                                           get_resp=get_order_resp)
     return behavior_response
Ejemplo n.º 13
0
    def test_create_order_checking_secret_metadata(self):
        """ Assumes that the order status is active and not pending."""
        order_ref = self.cl_behaviors.create_order_from_config()
        order = self.cl_client.get_order(order_ref)

        # Retrieve automatically created secret metadata
        secret_id = CloudkeepResponse.get_id_from_ref(order.secret_ref)
        secret = self.secrets_client.get_secret(secret_id).entity

        self.assertIsNotNone(secret)
        self.assertEqual(secret.name, self.config.name)
        self.assertEqual(secret.mode, self.config.mode)
        self.assertEqual(secret.algorithm, self.config.algorithm)
        self.assertEqual(secret.bit_length, self.config.bit_length)
        self.assertEqual(secret.content_types.get('default'),
                         self.config.payload_content_type)
Ejemplo n.º 14
0
    def test_create_order_checking_secret_metadata(self):
        """ Assumes that the order status is active and not pending."""
        order_ref = self.cl_behaviors.create_order_from_config()
        order = self.cl_client.get_order(order_ref)

        # Retrieve automatically created secret metadata
        secret_id = CloudkeepResponse.get_id_from_ref(order.secret_ref)
        secret = self.secrets_client.get_secret(secret_id).entity

        self.assertIsNotNone(secret)
        self.assertEqual(secret.name, self.config.name)
        self.assertEqual(secret.mode, self.config.mode)
        self.assertEqual(secret.algorithm, self.config.algorithm)
        self.assertEqual(secret.bit_length, self.config.bit_length)
        self.assertEqual(secret.content_types.get('default'),
                         self.config.payload_content_type)
Ejemplo n.º 15
0
    def _wait_for_order_to_activate(self, create_resp):
        """ Recheck the order every second to see if it's active yet."""
        if not create_resp.entity or not create_resp.entity.reference:
            # We only care about orders that have been created
            return

        stop_time = datetime.now() + timedelta(seconds=30)
        order_ref = create_resp.entity.reference
        order_id = CloudkeepResponse.get_id_from_ref(order_ref)

        while datetime.now() < stop_time:
            order = self.orders_client.get_order(order_id).entity

            if not order:
                raise Exception('Couldn\'t properly retrieve or parse order')

            if order.status == 'ACTIVE':
                # Early return if order has gone active
                return

            # Moderate the calls a little so we don't get rate-limited
            sleep(0.1)
Ejemplo n.º 16
0
    def _wait_for_order_to_activate(self, create_resp):
        """ Recheck the order every second to see if it's active yet."""
        if not create_resp.entity or not create_resp.entity.reference:
            # We only care about orders that have been created
            return

        stop_time = datetime.now() + timedelta(seconds=30)
        order_ref = create_resp.entity.reference
        order_id = CloudkeepResponse.get_id_from_ref(order_ref)

        while datetime.now() < stop_time:
            order = self.orders_client.get_order(order_id).entity

            if not order:
                raise Exception('Couldn\'t properly retrieve or parse order')

            if order.status == 'ACTIVE':
                # Early return if order has gone active
                return

            # Moderate the calls a little so we don't get rate-limited
            sleep(0.1)
Ejemplo n.º 17
0
 def delete_secret(self, secret_ref):
     secret_id = CloudkeepResponse.get_id_from_ref(secret_ref)
     self.remove_from_created_secrets(secret_id=secret_id)
     resp = self.cl_client.delete_secret(href=secret_ref)
     return resp