Merge "Remove Client V1 Behaviors"
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
"""
|
||||
Copyright 2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
|
||||
|
||||
class BaseBehaviors(object):
|
||||
|
||||
def __init__(self, client):
|
||||
self.LOG = logging.getLogger(type(self).__name__)
|
||||
self.client = client
|
||||
self.created_entities = []
|
||||
self.base_url = client.secrets._api.endpoint_override
|
||||
|
||||
def get_json(self, response):
|
||||
json_data = dict()
|
||||
|
||||
try:
|
||||
json_data = response.json()
|
||||
except ValueError as e:
|
||||
self.LOG.exception(e)
|
||||
self.LOG.error("Error converting response to JSON: %s", e.message)
|
||||
self.LOG.error("Response Content: %s", response.content)
|
||||
|
||||
return json_data
|
||||
|
||||
def get_id_from_href(self, href):
|
||||
"""Returns the id from reference.
|
||||
|
||||
The id must be the last item in the href.
|
||||
|
||||
:param href: The href containing the id.
|
||||
:returns the id portion of the href
|
||||
"""
|
||||
|
||||
item_id = None
|
||||
if href and len(href) > 0:
|
||||
base, item_id = os.path.split(href)
|
||||
return item_id
|
||||
@@ -1,110 +0,0 @@
|
||||
"""
|
||||
Copyright 2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
from functionaltests.client.v1.behaviors import base_behaviors
|
||||
|
||||
|
||||
class ContainerBehaviors(base_behaviors.BaseBehaviors):
|
||||
|
||||
def create_generic_container(self, data, secrets=None):
|
||||
"""Creates a generic container object
|
||||
|
||||
:param data: Data used to create object
|
||||
:param secrets: Optional paramter to include a dictionary of secrets
|
||||
to override the default secrets data.
|
||||
:return: A generic container object
|
||||
"""
|
||||
if secrets:
|
||||
data['secrets'] = secrets
|
||||
return self.client.containers.create(**data)
|
||||
|
||||
def create_rsa_container(self, data, disable_passphrase=False):
|
||||
"""Creates RSA container object
|
||||
|
||||
:param data: Data used to create object
|
||||
:param disable_passphrase: Option to disable the passphrase on an RSA
|
||||
container
|
||||
:return: RSA container object
|
||||
"""
|
||||
if disable_passphrase:
|
||||
data['private_key_passphrase'] = None
|
||||
|
||||
return self.client.containers.create_rsa(**data)
|
||||
|
||||
def create_certificate_container(self, data):
|
||||
"""Creates a certificate container object
|
||||
|
||||
:param data: Data used to create object
|
||||
:return: Certificate container object
|
||||
"""
|
||||
return self.client.containers.create_certificate(**data)
|
||||
|
||||
def store_container(self, container):
|
||||
"""Create generic container from the data in a client container object
|
||||
|
||||
:param container: A container object
|
||||
:return: A container ref
|
||||
"""
|
||||
|
||||
resp = container.store()
|
||||
container_ref = str(resp)
|
||||
|
||||
if container_ref:
|
||||
self.created_entities.append(container_ref)
|
||||
return resp
|
||||
|
||||
def get_container(self, container_ref):
|
||||
"""Handles getting a single container
|
||||
|
||||
:param container_ref: Reference to the container to be retrieved
|
||||
:return: A container object.
|
||||
"""
|
||||
|
||||
return self.client.containers.get(container_ref)
|
||||
|
||||
def get_containers(self, limit=10, offset=0):
|
||||
"""Handles getting a list of containers.
|
||||
|
||||
:param limit: limits number of returned containers
|
||||
:param offset: represents how many records to skip before retrieving
|
||||
the list
|
||||
:return: A list of barbican client container objects.
|
||||
"""
|
||||
return self.client.containers.list(limit=limit, offset=offset)
|
||||
|
||||
def delete_container(self, container_ref, expected_fail=False):
|
||||
"""Handles deleting a containers.
|
||||
|
||||
:param container_ref: Reference of the container to be deleted
|
||||
:param expected_fail: If there is a negative test, this should be
|
||||
marked true if you are trying to delete a container that does
|
||||
not exist.
|
||||
:return: Response of the delete.
|
||||
"""
|
||||
resp = self.client.containers.delete(container_ref)
|
||||
|
||||
if not expected_fail:
|
||||
self.created_entities.remove(container_ref)
|
||||
|
||||
return resp
|
||||
|
||||
def delete_all_created_containers(self):
|
||||
"""Delete all of the containers that we have created."""
|
||||
containers_to_delete = [container for container
|
||||
in self.created_entities]
|
||||
|
||||
for container_ref in containers_to_delete:
|
||||
self.delete_container(container_ref)
|
||||
@@ -1,95 +0,0 @@
|
||||
"""
|
||||
Copyright 2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
from functionaltests.client.v1.behaviors import base_behaviors
|
||||
|
||||
|
||||
class OrderBehaviors(base_behaviors.BaseBehaviors):
|
||||
|
||||
def create_key_order(self, data):
|
||||
"""Create a key order from the data in the model.
|
||||
|
||||
:param data: The data used to create the order
|
||||
:return: The create response and href for the order
|
||||
"""
|
||||
|
||||
return self.client.orders.create_key(**data)
|
||||
|
||||
def create_asymmetric_order(self, data):
|
||||
"""Create an asymmetric order from the data in the model.
|
||||
|
||||
:param data: The data used to create the order
|
||||
:return: The create response and href for the order
|
||||
"""
|
||||
|
||||
return self.client.orders.create_asymmetric(**data)
|
||||
|
||||
def store_order(self, order):
|
||||
"""Stores an order object in the barbican database
|
||||
|
||||
:return: The order href
|
||||
"""
|
||||
|
||||
resp = order.submit()
|
||||
order_ref = str(resp)
|
||||
|
||||
if order_ref:
|
||||
self.created_entities.append(order_ref)
|
||||
|
||||
return resp
|
||||
|
||||
def get_order(self, order_ref):
|
||||
"""Get an order from an href.
|
||||
|
||||
:param order_ref: The href for an order
|
||||
:return: The response from the get
|
||||
"""
|
||||
return self.client.orders.get(order_ref)
|
||||
|
||||
def get_orders(self, limit=10, offset=0):
|
||||
"""Get a list of orders.
|
||||
|
||||
:param limit: limits number of returned orders (default 10)
|
||||
:param offset: represents how many records to skip before retrieving
|
||||
the list (default 0)
|
||||
:return the response, a list of orders and the next/pref hrefs
|
||||
"""
|
||||
|
||||
orders = self.client.orders.list(limit, offset)
|
||||
|
||||
return orders
|
||||
|
||||
def delete_order(self, order_ref, expected_fail=False):
|
||||
"""Delete an order.
|
||||
|
||||
:param order_ref: HATEOS ref of the order to be deleted
|
||||
:param expected_fail: Flag telling the delete whether or not this
|
||||
operation is expected to fail (ie coming
|
||||
from a negative test). We need this to
|
||||
determine whether or not this delete should
|
||||
also remove an entity from our internal
|
||||
list for housekeeping.
|
||||
:return A request response object
|
||||
"""
|
||||
resp = self.client.orders.delete(order_ref)
|
||||
if not expected_fail:
|
||||
self.created_entities.remove(order_ref)
|
||||
return resp
|
||||
|
||||
def delete_all_created_orders(self):
|
||||
"""Delete all of the orders that we have created."""
|
||||
orders_to_delete = [order for order in self.created_entities]
|
||||
for order_ref in orders_to_delete:
|
||||
self.delete_order(order_ref)
|
||||
@@ -1,107 +0,0 @@
|
||||
"""
|
||||
Copyright 2015 Rackspace
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
"""
|
||||
|
||||
from functionaltests.client.v1.behaviors import base_behaviors
|
||||
|
||||
|
||||
class SecretBehaviors(base_behaviors.BaseBehaviors):
|
||||
|
||||
def create_secret(self, data):
|
||||
"""Creates a Barbican client secret object.
|
||||
|
||||
This does not store the object in the database.
|
||||
|
||||
:param data: Data for creation of the barbican object.
|
||||
:return: Barbican client secret object
|
||||
"""
|
||||
return self.client.secrets.create(**data)
|
||||
|
||||
def store_secret(self, secret):
|
||||
"""Stores a secret object in the barbican datastore.
|
||||
|
||||
Creating a secret in the client only creates the Secret object.
|
||||
The secret is not saved to the database until a store is called.
|
||||
|
||||
:param secret: A barbican client secret object
|
||||
:return: The ref to the created secret
|
||||
"""
|
||||
resp = secret.store()
|
||||
|
||||
if resp:
|
||||
self.created_entities.append(resp)
|
||||
|
||||
return resp
|
||||
|
||||
def get_secret(self, secret_ref, payload_content_type=None):
|
||||
"""Retrieves a secret and its payload.
|
||||
|
||||
:param secret_ref: A secret reference
|
||||
:param payload_content_type: The secrets content type
|
||||
:return: A barbican secret object with all meta and payload
|
||||
information
|
||||
"""
|
||||
resp = self.client.secrets.get(
|
||||
secret_ref,
|
||||
payload_content_type=payload_content_type)
|
||||
|
||||
return resp
|
||||
|
||||
def update_secret(self, secret_ref, payload):
|
||||
"""Updates a secret.
|
||||
|
||||
:param secret_ref: HATEOS ref of the secret to be updated
|
||||
:return: It will return a string
|
||||
"""
|
||||
|
||||
resp = self.client.secrets.update(secret_ref, payload)
|
||||
|
||||
return resp
|
||||
|
||||
def get_secrets(self, limit=10, offset=0):
|
||||
"""Handles getting a list of secrets.
|
||||
|
||||
:param limit: limits number of returned secrets
|
||||
:param offset: represents how many records to skip before retrieving
|
||||
the list
|
||||
:return: A list of secret objects
|
||||
"""
|
||||
resp = self.client.secrets.list(limit=limit, offset=offset)
|
||||
|
||||
return resp
|
||||
|
||||
def delete_secret(self, secret_ref, expected_fail=False):
|
||||
"""Delete a secret.
|
||||
|
||||
:param secret_ref: HATEOS ref of the secret to be deleted
|
||||
:param expected_fail: If test is expected to fail the deletion
|
||||
:return: On failure will return a string
|
||||
"""
|
||||
resp = self.client.secrets.delete(secret_ref)
|
||||
|
||||
if not expected_fail:
|
||||
self.created_entities.remove(secret_ref)
|
||||
|
||||
return resp
|
||||
|
||||
def delete_all_created_secrets(self):
|
||||
"""Delete all of the secrets that we have created."""
|
||||
slist = []
|
||||
|
||||
for entity in self.created_entities:
|
||||
slist.append(entity)
|
||||
|
||||
for secret_ref in slist:
|
||||
self.delete_secret(secret_ref)
|
||||
Reference in New Issue
Block a user