Chaffelson / nipyapi

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

update existing user group Error #201

Closed hamzabekkouri closed 11 months ago

hamzabekkouri commented 4 years ago

Description

I want to add a user (already exist or just created ) to the existing user group inside info with API ?

What I Did

import nipyapi
import urllib3
from UserManagement import add_user
from nipyapi import config, canvas
from nipyapi import security
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)

status = None
#admin_email = args["email"]
#zone = args["zone"]

nifi = "https://sdrginnifi0101:8081/nifi-api"
config.nifi_config.host = nifi
config.nifi_config.verify_ssl = False
client_cer = "/opt/application/sdr/apps/nifi/conf/client.cer"
client_key = "/opt/application/sdr/apps/nifi/conf/client.key"
security.set_service_ssl_context(service="nifi", client_cert_file=client_cer, client_key_file=client_key)

user_list = []
root_id = canvas.get_root_pg_id() # id of rot canvas of nifi
pg = canvas.get_process_group(root_id, "id")  # ProcessGroupEntity
email_list=["hamza.bekkouri@gmail.com"]
ug = security.get_service_user_group("p10092", identifier_type='identity', service='nifi')

if len(email_list) == 1:
    add_user(email_list[0])
    user = security.get_service_user(email_list[0], identifier_type="identity", service="nifi")
    userGroupDto = nipyapi.nifi.models.user_group_dto.UserGroupDTO(users=[user],access_policies=ug.component.access_policies)
    userGroupEntity = nipyapi.nifi.models.user_group_entity.UserGroupEntity(component=userGroupDto)
else:
    for mail in email_list:
        add_user(mail)
        user = security.get_service_user(mail, identifier_type="identity", service="nifi")
        user_list.append(user)
    userGroupDto = nipyapi.nifi.models.user_group_dto.UserGroupDTO(access_policies=ug.component.access_policies,users=user_list)
    userGroupEntity = nipyapi.nifi.models.user_group_entity.UserGroupEntity(component=userGroupDto)
TenantApi = nipyapi.nifi.apis.tenants_api.TenantsApi(api_client=None)
TenantApi.update_user_group(ug.id,userGroupEntity)

ERROR

Reason: Bad Request HTTP response headers: HTTPHeaderDict({'Content-Length': '614', 'X-XSS-Protection': '1; mode=block', 'Content-Security-Policy': "frame-ancestors 'self'", 'Strict-Transport-Security': 'max-age=31540000', 'Vary': 'Accept-Encoding', 'Server': 'Jetty(9.4.19.v20190610)', 'Date': 'Sat, 06 Jun 2020 22:53:14 GMT', 'X-Frame-Options': 'SAMEORIGIN', 'Content-Type': 'text/plain'}) HTTP response body: Unrecognized field "accessPolicies" (class org.apache.nifi.web.api.dto.TenantDTO), not marked as ignorable (6 known properties: "parentGroupId", "versionedComponentId", "position", "id", "identity", "configurable"]) at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 77] (through reference chain: org.apache.nifi.web.api.entity.UserGroupEntity["component"]->org.apache.nifi.web.api.dto.UserGroupDTO["users"]->java.util.HashSet[0]->org.apache.nifi.web.api.entity.TenantEntity["component"]->org.apache.nifi.web.api.dto.TenantDTO["accessPolicies"])

Urgency

Please give a brief description of how critical this issue is to you.
For example, if it's blocking your Production environment, or perhaps you are just notifying us of something you found but isn't blocking your workflow.

Mr. @Chaffelson I am asking if you have any tricks to that with nipyapi