How to use the nipyapi.registry 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_security.py View on Github external
nipyapi.security.get_service_user_group(
            identifier='bob',
            identifier_type=dict())
    with pytest.raises(AssertionError):
        nipyapi.security.get_service_user_group(
            identifier='bob',
            identifier_type='id',
            service='bob')
    r1 = nipyapi.security.get_service_user_group(conftest.test_user_group_name)
    assert isinstance(r1, nipyapi.nifi.UserGroupEntity)
    assert r1.id == n_group.id
    r2 = nipyapi.security.get_service_user_group(
        identifier=conftest.test_user_group_name,
        service='registry'
    )
    assert isinstance(r2, nipyapi.registry.UserGroup)
    assert r2.identifier == r_group.identifier
github Chaffelson / nipyapi / nipyapi / security.py View on Github external
def update_access_policy(policy, service='nifi'):
    """
    Applies an updated access policy to the service indicated

    Args:
        policy (PolicyEntity): The policy object to submit
        service (str): 'nifi' or 'registry' to indicate the target service

    Returns:
        (PolicyEntity): The updated policy if successful

    """
    assert service in _valid_services
    assert isinstance(
        policy,
        nipyapi.registry.AccessPolicy if service == 'registry'
        else nipyapi.nifi.AccessPolicyEntity
    ), "Policy type {0} not vaid.".format(type(policy))
    with nipyapi.utils.rest_exceptions():
        return getattr(nipyapi, service).PoliciesApi().update_access_policy(
            id=policy.id if service == 'nifi' else policy.identifier,
            body=policy
        )
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
Writes a FlowSnapshot into a VersionedFlow as a new version update

    Note that this differs from save_flow_ver which creates a new Flow Version
    containing the snapshot. This function writes a snapshot to an existing
    Flow Version. Useful in migrating Flow Versions between environments.

    Args:
        flow (VersionedFlowObject): the VersionedFlow object to write to
        flow_snapshot (VersionedFlowSnapshot): the Snapshot to write into the
            VersionedFlow
        refresh (bool): Whether to refresh the object status before actioning

    Returns:
        The new (VersionedFlowSnapshot)
    """
    if not isinstance(flow_snapshot, nipyapi.registry.VersionedFlowSnapshot):
        raise ValueError("flow_snapshot must be an instance of a "
                         "registry.VersionedFlowSnapshot object, not an {0}"
                         .format(type(flow_snapshot)))
    with nipyapi.utils.rest_exceptions():
        if refresh:
            target_flow = get_flow_in_bucket(
                bucket_id=flow.bucket_identifier,
                identifier=flow.identifier,
                identifier_type='id'
            )
        else:
            target_flow = flow
        target_bucket = get_registry_bucket(
            target_flow.bucket_identifier, 'id'
        )
        # The current version of NiFi doesn't ignore link objects passed to it
github Chaffelson / nipyapi / nipyapi / demo / console.py View on Github external
uri=_insecure_rc_endpoint,
            description='NiPyApi Demo Console'
        )
    except ValueError:
        reg_client_0 = nipyapi.versioning.get_registry_client(_rc0)

log.info("Cleaning up old NiPyApi Console Registry Buckets")
bucket_0 = nipyapi.versioning.get_registry_bucket(_b0)
if bucket_0 is not None:
    nipyapi.versioning.delete_registry_bucket(bucket_0)
bucket_1 = nipyapi.versioning.get_registry_bucket(_b1)
if bucket_1 is not None:
    nipyapi.versioning.delete_registry_bucket(bucket_1)
log.info("Creating bucket_0 as new a Registry Bucket named %s", _b0)
bucket_0 = nipyapi.versioning.create_registry_bucket(_b0)
assert isinstance(bucket_0, nipyapi.registry.Bucket)
log.info("Creating bucket_1 as new a Registry Bucket named %s", _b1)
bucket_1 = nipyapi.versioning.create_registry_bucket(_b1)
assert isinstance(bucket_1, nipyapi.registry.Bucket)

log.info("Saving %s as a new Versioned Flow named %s in Bucket %s, and saving "
         "as variable ver_flow_info_0", _pg0, _vf0, _b0)
ver_flow_info_0 = nipyapi.versioning.save_flow_ver(
    process_group=process_group_0,
    registry_client=reg_client_0,
    bucket=bucket_0,
    flow_name=_vf0,
    desc='A Versioned Flow',
    comment='A Versioned Flow'
)
log.info("Creating ver_flow_0 as a copy of the new Versioned Flow object")
ver_flow_0 = nipyapi.versioning.get_flow_in_bucket(
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
identifier_type='id'
            )
        else:
            target_flow = flow
        target_bucket = get_registry_bucket(
            target_flow.bucket_identifier, 'id'
        )
        # The current version of NiFi doesn't ignore link objects passed to it
        bad_params = ['link']
        for obj in [target_bucket, target_flow]:
            for p in bad_params:
                obj.__setattr__(p, None)
        return nipyapi.registry.BucketFlowsApi().create_flow_version(
            bucket_id=target_bucket.identifier,
            flow_id=target_flow.identifier,
            body=nipyapi.registry.VersionedFlowSnapshot(
                flow=target_flow,
                bucket=target_bucket,
                flow_contents=flow_snapshot.flow_contents,
                snapshot_metadata=VfsMd(
                    version=target_flow.version_count + 1,
                    comments=flow_snapshot.snapshot_metadata.comments,
                    bucket_identifier=target_flow.bucket_identifier,
                    flow_identifier=target_flow.identifier
                ),
github Chaffelson / nipyapi / nipyapi / demo / console.py View on Github external
except ValueError:
        reg_client_0 = nipyapi.versioning.get_registry_client(_rc0)

log.info("Cleaning up old NiPyApi Console Registry Buckets")
bucket_0 = nipyapi.versioning.get_registry_bucket(_b0)
if bucket_0 is not None:
    nipyapi.versioning.delete_registry_bucket(bucket_0)
bucket_1 = nipyapi.versioning.get_registry_bucket(_b1)
if bucket_1 is not None:
    nipyapi.versioning.delete_registry_bucket(bucket_1)
log.info("Creating bucket_0 as new a Registry Bucket named %s", _b0)
bucket_0 = nipyapi.versioning.create_registry_bucket(_b0)
assert isinstance(bucket_0, nipyapi.registry.Bucket)
log.info("Creating bucket_1 as new a Registry Bucket named %s", _b1)
bucket_1 = nipyapi.versioning.create_registry_bucket(_b1)
assert isinstance(bucket_1, nipyapi.registry.Bucket)

log.info("Saving %s as a new Versioned Flow named %s in Bucket %s, and saving "
         "as variable ver_flow_info_0", _pg0, _vf0, _b0)
ver_flow_info_0 = nipyapi.versioning.save_flow_ver(
    process_group=process_group_0,
    registry_client=reg_client_0,
    bucket=bucket_0,
    flow_name=_vf0,
    desc='A Versioned Flow',
    comment='A Versioned Flow'
)
log.info("Creating ver_flow_0 as a copy of the new Versioned Flow object")
ver_flow_0 = nipyapi.versioning.get_flow_in_bucket(
    bucket_0.identifier,
    ver_flow_info_0.version_control_information.flow_id,
    'id'
github Chaffelson / nipyapi / nipyapi / utils.py View on Github external
def rest_exceptions():
    """Simple exception wrapper for Rest Exceptions"""
    try:
        yield
    except (nipyapi.nifi.rest.ApiException,
            nipyapi.registry.rest.ApiException) as e:
        raise ValueError(e.body)
github Chaffelson / nipyapi / nipyapi / security.py View on Github external
strict (bool): If True, will return error if user already present,
          if False will ignore the already exists

    Returns:
        Updated Policy object

    """
    assert service in _valid_services
    assert isinstance(
        policy,
        nipyapi.registry.AccessPolicy if service == 'registry'
        else nipyapi.nifi.AccessPolicyEntity
    )
    assert isinstance(
        user,
        nipyapi.registry.User if service == 'registry'
        else nipyapi.nifi.UserEntity
    )

    user_id = user.id if service == 'nifi' else user.identifier

    if refresh:
        policy_tgt = getattr(nipyapi, service).PoliciesApi().get_access_policy(
            policy.id if service == 'nifi' else policy.identifier
        )
    else:
        policy_tgt = policy

    assert isinstance(
        policy_tgt,
        nipyapi.registry.AccessPolicy if service == 'registry' else
        nipyapi.nifi.AccessPolicyEntity
github Chaffelson / nipyapi / nipyapi / versioning.py View on Github external
def list_registry_buckets():
    """
    Lists all available Buckets in the NiFi Registry

    Returns:
        (list[Bucket]) objects
    """
    with nipyapi.utils.rest_exceptions():
        return nipyapi.registry.BucketsApi().get_buckets()