Ejemplo n.º 1
0
def delete_particular_service_key(key_guid):
    """Deletes a particular service key.

    Args:
        key_guid (str): GUID of a service key
    """
    command_suffix = ['/v2/service_keys/{}'.format(key_guid), '-X', 'DELETE', '-d', '']
    cf_cli.get_command_output(CF_CURL + command_suffix)
Ejemplo n.º 2
0
def delete_service_binding(binding):
    """Deletes a service binding.

    Args:
        binding (dict): JSON representing a service binding. Has "metadata" and "entity" keys.
    """
    binding_url = binding['metadata']['url']
    cmd_output = cf_cli.get_command_output(CF_CURL + [binding_url, '-X', 'DELETE'])
    if cmd_output:
        raise cf_cli.CommandFailedError('Failed to delete a service binding. CF response: {}'
                                        .format(cmd_output))
Ejemplo n.º 3
0
def create_service_key(service_guid, key_name):
    """Creates a service key for particular service instance.

    Args:
        service_guid (str): GUID of a service instance (can be user-provided).
        key_name (str): Name of the newly created service key.
    """
    params = {'service_instance_guid': service_guid, 'name': key_name}
    command_suffix = ['/v2/service_keys', '-X', 'POST', '-d', json.dumps(params)]
    cmd_output = cf_cli.get_command_output(CF_CURL + command_suffix)
    response_json = json.loads(cmd_output)
    if 'error_code' not in response_json:
        return response_json
    else:
        raise cf_cli.CommandFailedError(
            'Failed to create a service key {} for service with guid {}.\n'
            'Response body: {}'.format(key_name, service_guid, response_json))
Ejemplo n.º 4
0
def cf_curl_get(path):
    """Calls "cf curl" with a given path.

    Args:
        path (str): CF API path,
            e.g. /v2/user_provided_service_instances/8b89a54b-b292-49eb-a8c4-2396ec038120

    Returns:
        dict: JSON returned by the endpoint.
    """
    cmd_output = cf_cli.get_command_output(CF_CURL + [path])
    response_json = json.loads(cmd_output)
    if 'error_code' not in response_json:
        return response_json
    else:
        raise cf_cli.CommandFailedError('Failed GET on CF API path {}\n'
                                        'Response body: {}'.format(path, response_json))
Ejemplo n.º 5
0
def create_service_binding(service_guid, app_guid):
    """Creates a binding between a service and an application.

    Args:
        service_guid (str): GUID of a service instance (can be user-provided).
        app_guid (str): Applications' GUID.
    """
    params = {'service_instance_guid': service_guid, 'app_guid': app_guid}
    command_suffix = ['/v2/service_bindings', '-X', 'POST', '-d', json.dumps(params)]
    cmd_output = cf_cli.get_command_output(CF_CURL + command_suffix)
    response_json = json.loads(cmd_output)
    if 'error_code' not in response_json:
        return response_json
    else:
        raise cf_cli.CommandFailedError(
            'Failed to create a binding between service {} and app {}.\n'
            'Response body: {}'.format(service_guid, app_guid, response_json))