How to use the nipyapi.utils function in nipyapi

To help you get started, we’ve selected a few nipyapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Chaffelson / nipyapi / tests / test_utils.py View on Github external
def test_dump(regress_flow_reg, fix_flow_serde):
    # Testing that we don't modify or lose information in the round trip
    # Processing in memory for json
    export_obj = json.loads(fix_flow_serde.raw.decode('utf-8'))
    ss_json = utils.dump(
        obj=export_obj,
        mode='json'
    )
    assert isinstance(ss_json, six.string_types)
    round_trip_json = utils.load(ss_json)
    with pytest.raises(AssertionError):
        _ = utils.dump('', 'FakeNews')
    with pytest.raises(TypeError):
        _ = utils.dump({None}, 'json')
    # Test Yaml
    ss_yaml = utils.dump(
        obj=export_obj,
        mode='yaml'
    )
    assert isinstance(ss_yaml, six.string_types)
    round_trip_yaml = utils.load(ss_yaml)
github Chaffelson / nipyapi / tests / test_security.py View on Github external
"""Tests for nipyapi security module."""

from __future__ import absolute_import
import pytest
from tests import conftest
import nipyapi

# Tells pytest to skip this module of security testing is not enabled.
pytestmark = pytest.mark.skipif(not conftest.test_security, reason='test_security disabled in Conftest')

# Useful for manual testing
if conftest.test_security:
    test_host = nipyapi.config.default_host
    nipyapi.utils.set_endpoint('https://' + test_host + ':18443/nifi-registry-api', True, True)
    nipyapi.utils.set_endpoint('https://' + test_host + ':8443/nifi-api', True, True)


def test_list_service_users():
    # This test suite makes extensive use of this call in fixtures
    pass


def test_get_service_user():
    # This test suite makes extensive use of this call in fixtures
    pass


def test_create_service_user():
    with pytest.raises(AssertionError):
        nipyapi.security.create_service_user(service='bob', identity='pie')
    with pytest.raises(AssertionError):
github Chaffelson / nipyapi / nipyapi / security.py View on Github external
def list_service_users(service='nifi'):
    """Lists all users of a given service, takes a service name as a string"""
    assert service in _valid_services
    with nipyapi.utils.rest_exceptions():
        out = getattr(nipyapi, service).TenantsApi().get_users()
    if service == 'nifi':
        return out.users
    return out
github Chaffelson / nipyapi / nipyapi / canvas.py View on Github external
identifier_type (str): 'id' or 'name', defaults to name
        bool_response (bool): If True, will return False if the Controller is
            not found - useful when testing for deletion completion

    Returns:

    """
    assert isinstance(identifier, six.string_types)
    assert identifier_type in ['name', 'id']
    handle = nipyapi.nifi.ControllerServicesApi()
    try:
        if identifier_type == 'id':
            out = handle.get_controller_service(identifier)
        else:
            obj = list_all_controllers()
            out = nipyapi.utils.filter_obj(obj, identifier, identifier_type)
    except nipyapi.nifi.rest.ApiException as e:
        if bool_response:
            return False
        raise ValueError(e.body)
    return out
github Chaffelson / nipyapi / nipyapi / templates.py View on Github external
def list_all_templates(native=True):
    """
    Gets a list of all templates on the canvas

    Returns:
        (list[TemplateEntity]): A list of TemplateEntity's
    """
    with nipyapi.utils.rest_exceptions():
        templates = nipyapi.nifi.FlowApi().get_templates()
    if not native:
        if templates:
            return templates.templates
        return None
    return templates
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
def create_registry_client(name, uri, description):
    """
    Creates a Registry Client in the NiFi Controller Services

    Args:
        name (str): The name of the new Client
        uri (str): The URI for the connection, such as 'http://registry:18080'
        description (str): A description for the Client

    Returns:
        (RegistryClientEntity): The new registry client object
    """
    assert isinstance(uri, six.string_types) and uri is not False
    assert isinstance(name, six.string_types) and name is not False
    assert isinstance(description, six.string_types)
    with nipyapi.utils.rest_exceptions():
        return nipyapi.nifi.ControllerApi().create_registry_client(
            body={
                'component': {
                    'uri': uri,
                    'name': name,
                    'description': description
                },
                'revision': {
                    'version': 0
                }
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
Args:
        bucket_id (str): UUID of the bucket holding the flow to be enumerated
        flow_id (str): UUID of the flow in the bucket to be enumerated
        registry_id (str): UUID of the registry client linking the bucket, only
            required if requesting flows via NiFi instead of directly Registry
        service (str): Accepts 'nifi' or 'registry', indicating which service
            to query

    Returns:
        list(VersionedFlowSnapshotMetadata) or
            (VersionedFlowSnapshotMetadataSetEntity)
    """
    assert service in ['nifi', 'registry']
    if service == 'nifi':
        with nipyapi.utils.rest_exceptions():
            return nipyapi.nifi.FlowApi().get_versions(
                registry_id=registry_id,
                bucket_id=bucket_id,
                flow_id=flow_id
            )
    else:
        with nipyapi.utils.rest_exceptions():
            return nipyapi.registry.BucketFlowsApi().get_flow_versions(
                bucket_id=bucket_id,
                flow_id=flow_id
            )
github Chaffelson / nipyapi / nipyapi / demo / bbende_howdoideploymyflow.py View on Github external
name='nipyapi_reg',
        image_name='chaffelson/nifi-registry',
        image_tag='0.1.0',
        ports={'18080/tcp': 18080},
        test_url='http://localhost:18080/nifi-registry'
    ),
    DockerContainer(
        name='nipyapi_solr',
        image_name='solr',
        image_tag='7.2.1',
        ports={'8983/tcp': 8983},
        test_url='http://localhost:8983'
    ),
]

nipyapi.utils.start_docker_containers(
    d_containers,
    d_network_name
)
github Chaffelson / nipyapi / nipyapi / agents.py View on Github external
def import_flow_to_canvas(flow_name, filename=None, yaml=True, overwrite=True):
    if overwrite:
        purge_canvas(flow_name)
    if not yaml or not filename:
        raise ValueError("We currently only support importing yaml from a file")
    # Read in Flow Def
    flow_def = nipyapi.utils.load(nipyapi.utils.fs_read(filename))
    # Validate Flow Def
    def_ver = flow_def.pop('NiPyAPI Agent Config Version')
    assert def_ver == 1, "Flow Definition version is bad"
    unique_names = set([i['name'] for j in [flow_def[x] for x in flow_def.keys()] for i in j])
    assert len(unique_names) == len(flow_def.keys()), "All Component names must be unique"
    if 'Processors' in flow_def:
        for proc in flow_def['Processors']:
            create_processor(
                flow_name=flow_name,
                name=proc['name'],
                type_name=proc['class'],
                schedule=proc['scheduling period'],
                properties=proc['Properties'],
                concurrency=proc['concurrency'] if 'concurrency' in proc else None
            )
    if 'Remote Process Groups' in flow_def:
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
to query

    Returns:
        list(VersionedFlowSnapshotMetadata) or
            (VersionedFlowSnapshotMetadataSetEntity)
    """
    assert service in ['nifi', 'registry']
    if service == 'nifi':
        with nipyapi.utils.rest_exceptions():
            return nipyapi.nifi.FlowApi().get_versions(
                registry_id=registry_id,
                bucket_id=bucket_id,
                flow_id=flow_id
            )
    else:
        with nipyapi.utils.rest_exceptions():
            return nipyapi.registry.BucketFlowsApi().get_flow_versions(
                bucket_id=bucket_id,
                flow_id=flow_id
            )