Chaffelson / nipyapi

A convenient Python wrapper for Apache NiFi
Other
245 stars 76 forks source link

Create a standardSSLcontextservice controller #231

Closed omkaringale closed 3 years ago

omkaringale commented 3 years ago

Description

Trying to setup a ssl service to get data from a site in a secure way using getHTTP processor

What I Did

canvas.create_controller(pg_1,'org.apache.nifi.ssl.StandardSSLContextService',name=None) Error : __AssertionError Traceback (most recent call last)

in ----> 1 canvas.create_controller(pg_1,'org.apache.nifi.ssl.StandardSSLContextService',name=None) ~\AppData\Roaming\Python\Python38\site-packages\nipyapi\canvas.py in create_controller(parent_pg, controller, name) 1064 1065 """ -> 1066 assert isinstance(controller, nipyapi.nifi.DocumentedTypeDTO) 1067 assert isinstance(parent_pg, nipyapi.nifi.ProcessGroupEntity) 1068 assert name is None or isinstance(name, six.string_types) AssertionError:__ I set up a controller manually and added the trust store filename and password using the library: `entity = nipyapi.nifi.FlowApi().get_controller_services_from_group(pg_1.id, include_ancestor_groups=False).controller_services` `entity.component.properties['Truststore Filename'] = 'path'` `entity.component.properties['Truststore Password'] = 'password'` Wanted this process to be automated. I am new to both NiFi and nipyapi. Does anyone have a basic example this process? ### Urgency Not set up a production environment using python yet. Still in the development phase.
Chaffelson commented 3 years ago

It is expecting you to pass in the Controller Service definition as an object, not just the name of the class. You can find the one you want by filtering the canvas.list_all_controller_types method by name, I could add a convenience function for this if you think it'd be helpful?

omkaringale commented 3 years ago

Created a separate function to filter the name from the list def get_controller_custom(identifier,identifier_type='name'): controller_list = nipyapi.canvas.list_all_controller_types() return nipyapi.utils.filter_obj(controller_list, identifier, identifier_type) Thanks for your help!!!

Chaffelson commented 3 years ago

Added this for the next release, should do the job similar to get_processor_type

def get_controller_type(identifier, identifier_type='name', greedy=True):
    """
    Gets the abstract object describing a controller, or list thereof

    Args:
        identifier (str): the string to filter the list for
        identifier_type (str): the field to filter on, set in config.py
        greedy (bool): False for exact match, True for greedy match

    Returns:
        None for no matches, Single Object for unique match,
        list(Objects) for multiple matches

    """
    with nipyapi.utils.rest_exceptions():
        obj = list_all_controller_types
    if obj:
        return nipyapi.utils.filter_obj(
            obj, identifier, identifier_type, greedy=greedy
        )
    return obj