Nipyapi version: 0.14.0
NiFi version: 1.11
NiFi-Registry version:
Python version:3.6
Operating System: Linux
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
INFO --user (hamza.bekkouri.ext#orange.com) already exist
Traceback (most recent call last):
File "add_user_to_project.py", line 56, in <module>
TenantApi.update_user_group(ug.id,userGroupEntity)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/apis/tenants_api.py", line 1142, in update_user_group
(data) = self.update_user_group_with_http_info(id, body, **kwargs)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/apis/tenants_api.py", line 1229, in update_user_group_with_http_info
collection_formats=collection_formats)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/api_client.py", line 326, in call_api
_return_http_data_only, collection_formats, _preload_content, _request_timeout)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/api_client.py", line 153, in __call_api
_request_timeout=_request_timeout)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/api_client.py", line 379, in request
body=body)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/rest.py", line 278, in PUT
body=body)
File "/home/nifi/.local/lib/python2.7/site-packages/nipyapi/nifi/rest.py", line 224, in request
raise ApiException(http_resp=r)
nipyapi.nifi.rest.ApiException: (400)
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"])
I don't find a solution to add user to an existing user
Related
I have a simple Python app that invokes a Vertex AI API that fails when it runs and I can't understand why. The application is as follows:
from google.cloud import aiplatform_v1
def sample_list_datasets():
client = aiplatform_v1.DatasetServiceClient()
request = aiplatform_v1.ListDatasetsRequest(
parent="projects/MYPROJECT/locations/us-central1",
)
page_result = client.list_datasets(request=request)
for response in page_result:
print(response)
sample_list_datasets()
when run, it fails with:
E0126 03:52:04.146970105 22462 hpack_parser.cc:1218] Error parsing metadata: error=invalid value key=content-type value=text/html; charset=UTF-8
Traceback (most recent call last):
File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable
return callable_(*args, **kwargs)
File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/grpc/_channel.py", line 946, in __call__
return _end_unary_response_blocking(state, call, False, None)
File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/grpc/_channel.py", line 849, in _end_unary_response_blocking
raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNIMPLEMENTED
details = "Received http2 header with status: 404"
debug_error_string = "UNKNOWN:Error received from peer ipv4:108.177.120.95:443 {created_time:"2023-01-26T03:52:04.147076255+00:00", grpc_status:12, grpc_message:"Received http2 header with status: 404"}"
>
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "run.py", line 25, in <module>
sample_list_datasets()
File "run.py", line 19, in sample_list_datasets
page_result = client.list_datasets(request=request)
File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/cloud/aiplatform_v1/services/dataset_service/client.py", line 1007, in list_datasets
metadata=metadata,
File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/api_core/gapic_v1/method.py", line 113, in __call__
return wrapped_func(*args, **kwargs)
File "/home/kolban/projects/vertex-ai/datasets/env/lib/python3.7/site-packages/google/api_core/grpc_helpers.py", line 74, in error_remapped_callable
raise exceptions.from_grpc_error(exc) from exc
google.api_core.exceptions.MethodNotImplemented: 501 Received http2 header with status: 404
What might I be doing wrong?
Changing the code to the following caused it to work:
from google.cloud import aiplatform_v1
from google.api_core.client_options import ClientOptions
def sample_list_datasets():
service_base_path='aiplatform.googleapis.com'
region='us-central1'
client_options = ClientOptions(api_endpoint=f"{region}-{service_base_path}")
client = aiplatform_v1.DatasetServiceClient(client_options=client_options)
request = aiplatform_v1.ListDatasetsRequest(
parent="projects/MYPROJECT/locations/us-central1",
)
# Make the request
page_result = client.list_datasets(request=request)
# Handle the response
for response in page_result:
print(response)
sample_list_datasets()
The resolution was hinted at in the documentation for the API request found here. At that article there is a code sample and in the code sample there are some comments and in the comments the following is written:
It may require specifying regional endpoints when creating the service
client as shown in:
https://googleapis.dev/python/google-api-core/latest/client_options.html
And this was the core clue. When we make Vertex AI calls we must specify where the request is to be sent. We do this by setting the api_endpoint option to a URL of the form [REGION]-aiplatform.googleapis.com.
I try to connect remotely to mongodb server from pycharm(with RDP).
this is thefunction that i run:
cluster = MongoClient("mongodb://admin:Passw0rd!#147.234.32.246:27017/NEG")
db = cluster["NEG"]
for word in Setting.dictionary_global.keys():
if word in db.list_collection_names():
collection = db[word]
for file in Setting.dictionary_global[word].keys():
if collection.find({"url":Setting.dictionary_global[word][file].url}):
continue
num_of_appearance = len(Setting.dictionary_global[word][file].indexes.get(word))
post = {"url": file, "title": Setting.dictionary_global[word][file].title,
"description": Setting.dictionary_global[word][file].description,"word in page": Setting.dictionary_global[word][file].indexes,"appearance": num_of_appearance, "date modified": Setting.dictionary_global[word][file].time}
collection.insert_one(post)
else:
collection = db.create_collection(word)
for file in Setting.dictionary_global[word].keys():
#print(Setting.dictionary_global)
num_of_appearance = len(Setting.dictionary_global[word][file].indexes.get(word))
post = {"url": file, "title": Setting.dictionary_global[word][file].title,
"description": Setting.dictionary_global[word][file].description,"word in page": Setting.dictionary_global[word][file].indexes, "appearance": num_of_appearance, "date modified":Setting.dictionary_global[word][file].time}
collection.insert_one(post)
and i get this error:
'''
Traceback (most recent call last):
File "C:/Users/edend/PycharmProjects/pythonProject11/main.py", line 118, in
crawler.start()
File "C:/Users/edend/PycharmProjects/pythonProject11/main.py", line 110, in start
insertDB()
File "C:\Users\edend\PycharmProjects\pythonProject11\DB.py", line 10, in insertDB
if word in db.list_collection_names():
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\database.py", line 863, in list_collection_names
for result in self.list_collections(session=session, **kwargs)]
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\database.py", line 825, in list_collections
return self.__client._retryable_read(
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py", line 1460, in _retryable_read
server = self._select_server(
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\mongo_client.py", line 1278, in _select_server
server = topology.select_server(server_selector)
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py", line 241, in select_server
return random.choice(self.select_servers(selector,
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py", line 199, in select_servers
server_descriptions = self._select_servers_loop(
File "C:\Users\edend\PycharmProjects\pythonProject11\venv\lib\site-packages\pymongo\topology.py", line 215, in _select_servers_loop
raise ServerSelectionTimeoutError(
pymongo.errors.ServerSelectionTimeoutError: 147.234.32.246:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 5ff3d15a2dcaa1e4fb3db4cd, topology_type: Single, servers: [<ServerDescription ('147.234.32.246', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('147.234.32.246:27017: timed out')>]>
'''
please help me im stuck and iv'e try everything
thank you in advance!!
Common causes:
MongoDB server is not running
MongoDB server is running on a different port
No connectivity between client and server (can you ping)
mongod.conf is configure to only allow local connections by default (set bind_ip_all?)
I have OpenSSL 1.1.1 with "Reference implementation of GOST engine" installed on Linux Mint.
I try to connect https-server using python-requests:
import requests
api = 'https://api.stage.mdlp.crtp.ru'
hdr = {'Content-Type': 'application/json;charset=UTF-8',
'User-Agent' : 'my_system',
'Cache-Control': 'no-cache',
'Accept-Language': 'en',
'Authorization': 'token None'}
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'GOST2012-GOST8912-GOST8912'
requests.packages.urllib3.contrib.pyopenssl.extract_from_urllib3()
cert_file = '/home/mi/soft/common/4.pem'
res = requests.get(api,headers = hdr,verify = cert_file)
The result is:
/home/mi/.local/lib/python2.7/site-packages/urllib3/connection.py:388: SubjectAltNameWarning: Certificate for api.stage.mdlp.crtp.ru has no `subjectAltName`, falling back to check for a `commonName` for now. This feature is being removed by major browsers and deprecated by RFC 2818. (See https://github.com/shazow/urllib3/issues/497 for details.)
SubjectAltNameWarning
Traceback (most recent call last):
File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/home/mi/soft/__main__.py", line 8, in
import test
File "/home/mi/soft/test.py", line 28, in
res = requests.get(api,headers = hdr,verify = cert_file)
File "/home/mi/.local/lib/python2.7/site-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/home/mi/.local/lib/python2.7/site-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/home/mi/.local/lib/python2.7/site-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/home/mi/.local/lib/python2.7/site-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/home/mi/.local/lib/python2.7/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='api.stage.mdlp.crtp.ru', port=443): Max retries exceeded with url: / (Caused by
SSLError(CertificateError("hostname 'api.stage.mdlp.crtp.ru' doesn't match u'api.stage.mdlp.crpt.ru'",),))
What is the reason of this error? What I can to do?
I have a lambda function in python and a dynamodb. When I make a call to dynamodb from within lambda handler function this call is successful. But call to dynamodb outside of the lambda handler function is not successful and gives access denied exception.
Lets say I have a table "List" in dynamodb. I put an item in dynamodb within lambda handler function. Code works fine and an item is added in the DB.
#lambdaModule
import boto3
class LambdaFunction:
def lambda_handler(self, event, context):
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('List')
table.put_item(
Item={
'username': 'janedoe',
'first_name': 'Jane',
'last_name': 'Doe',
'age': 25,
'account_type': 'standard_user',
}
)
But when I try to add item in the db from outside of lambda it gives me access denied error.
import boto3
class LambdaFunction:
def lambda_handler(self, event, context):
#Some logic
#Accessing dynamodb from outside of lambda function.
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('List')
table.put_item(
Item={
'username': 'janedoe',
'first_name': 'Jane',
'last_name': 'Doe',
'age': 25,
'account_type': 'standard_user',
}
)
Above code give following access denied error
"[ERROR] VerboseClientError: An error occurred (AccessDeniedException) on request (BA2U74TQ90HACN013TMF2BGEENVV4KQNSO5AEMVJF66Q9ASUAAJG) on table
(dev02-up-svc-fss-stack-BlockLists-1DRNZPW6GRDV0) when calling the DescribeTable operation: Traceback (most recent call last): File \
"/var/lang/lib/python3.7/imp.py\", line 234, in load_module return load_source(name, filename, file) File \"/var/la
ng/lib/python3.7/imp.py\", line 171, in load_source module = _load(spec) File \"<frozen importlib._bootstrap>\", line
696, in _load File \"<frozen importlib._bootstrap>\", line 677, in _load_unlocked File \"<frozen importlib._bootstrap_external>\",
line 728, in exec_module File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed File \"/var/task/score.py\",
line 179, in <module> class ScoreService(Service): File \"/var/task/score.py\", line 180, in ScoreService  
; ent = _name_dob_list.match(\"first_name\", \"last_name\", \"2000-12-12\") File \"/var/task/lists.py\", line 449, in match
obj = BlockLists.match(self.name, attribs, self.params_meta) File \"/var/task/lists.py\", line 359, in match params_a
s_string) File \"/var/task/pynamodb/models.py\", line 485, in get hash_key, range_key = cls._serialize_keys(hash_key, range_k
ey) File \"/var/task/pynamodb/models.py\", line 1372, in _serialize_keys hash_key = cls._hash_key_attribute().serialize(hash_k
ey) File \"/var/task/pynamodb/models.py\", line 1219, in _hash_key_attribute hash_keyname = cls._get_meta_data().hash_keyname&n
bsp; File \"/var/task/pynamodb/models.py\", line 1262, in _get_meta_data cls._meta_table = MetaTable(cls._get_connection().describe_ta
ble()) File \"/var/task/pynamodb/connection/table.py\", line 263, in describe_table return self.connection.describe_table(self.t
able_name) File \"/var/task/pynamodb/connection/base.py\", line 659, in describe_table tbl = self.get_meta_table(table_name, ref
I have given full access to db in template.yaml file.
LambdaFunction:
Type: AWS::Serverless::Function
Properties:
Handler: lambdaModule.lambda_handler
Events:
ScoreEvent:
Type: Api
Properties:
Path: /score
Method: POST
RestApiId: !Ref FraudScoreAPI
Policies:
- AmazonDynamoDBFullAccess
Not entirely sure but my first instinct suggests that once you are outside of the handler you are no longer in the Lambda's execution context and any permissions granted (via your stack) will not be visible. My suggestion here is to make the insert logic a function and call the function from within the handler method.
Here is what I have, I know this works without encryption and I can run
ansible-vault edit common.yml
with
ANSIBLE_VAULT_PASSWORD_FILE=~/.vault_pass.txt
set in the env.
from collections import namedtuple
from ansible.parsing.dataloader import DataLoader
from ansible.vars import VariableManager
from ansible.inventory import Inventory
from ansible.playbook import Playbook
from ansible.executor.playbook_executor import PlaybookExecutor
variable_manager = VariableManager()
loader = DataLoader()
inventory = Inventory(loader=loader, variable_manager=variable_manager, host_list='playbooks/hosts')
playbook_path = 'playbooks/' + PROJECT + '.yml'
Options = namedtuple('Options', ['connection', 'forks', 'become', 'become_method', 'become_user', 'check', 'listhosts', 'listtasks', 'listtags', 'syntax', 'module_path', 'vault_password_file'])
options = Options(connection='ssh', forks=5, become=None, become_method=None, become_user=None, check=False, listhosts=False, listtasks=False, listtags=False, syntax=False, module_path="", vault_password_file=os.environ['ANSIBLE_VAULT_PASSWORD_FILE'])
variable_manager.extra_vars = {'CAP_VERSION': CAP_VERSION, 'cluster': PROJECT + '-' + ENVIRONMENT, 'environ': ENVIRONMENT, 'rpm': rpmSource, 'VRSN': ARTI_BRANCH }
passwords = {}
pbex = PlaybookExecutor(playbooks=[playbook_path], inventory=inventory, variable_manager=variable_manager, loader=loader, options=options, passwords=passwords)
results = pbex.run()
It fails to decrypt the common.yml
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/ansible/ansible/lib/ansible/executor/playbook_executor.py", line 125, in run
all_vars = self._variable_manager.get_vars(loader=self._loader, play=play)
File "/opt/ansible/ansible/lib/ansible/vars/__init__.py", line 304, in get_vars
data = preprocess_vars(loader.load_from_file(vars_file))
File "/opt/ansible/ansible/lib/ansible/parsing/dataloader.py", line 119, in load_from_file
(file_data, show_content) = self._get_file_contents(file_name)
File "/opt/ansible/ansible/lib/ansible/parsing/dataloader.py", line 178, in _get_file_contents
data = self._vault.decrypt(data, filename=b_file_name)
File "/opt/ansible/ansible/lib/ansible/parsing/vault/__init__.py", line 264, in decrypt
raise AnsibleError(msg)
ansible.errors.AnsibleError: Decryption failed on /ansible/playbooks/vars/common.yml
In ansible 2.2.2 (not sure about other versions since the API can change frequently):
You can manually set the password in the python script like so:
loader = DataLoader()
loader.set_vault_password('mypass')
Or you could load the password from your vault password file:
import os
loader = DataLoader()
with open('{}/.vault_pass.txt'.format(os.path.expanduser('~')), 'r') as file:
loader.set_vault_password(file.read().splitlines()[0])
You can skip importing os and just put in your absolute path to the .vault_pass.txt file.
If you are sure your ANSIBLE_VAULT_PASSWORD_FILE is set in env:
import os
loader = DataLoader()
with open(os.environ['ANSIBLE_VAULT_PASSWORD_FILE'], 'r') as file:
loader.set_vault_password(file.read().splitlines()[0])