Member since
08-29-2022
7
Posts
0
Kudos Received
0
Solutions
04-12-2023
07:22 AM
1 Kudo
you can use Keycloak to authenticate and obtain a token, which you can then use to make the GET request to the API. Here's an example of how you can do this:Set up a Keycloak client for your API. You can follow the Keycloak documentation to set up a client for your API.Use the Keycloak API to obtain an access token. You can use the /auth/realms/{realm_name}/protocol/openid-connect/token endpoint to obtain an access token. You will need to provide your Keycloak username and password, as well as the client ID and client secret for your API. Here's an example of how you can use the requests library in Python to obtain an access token:
import requests
url = 'http://<KEYCLOAK_HOST>/auth/realms/<REALM_NAME>/protocol/openid-connect/token'
payload = { 'client_id': '<CLIENT_ID>', 'client_secret': '<CLIENT_SECRET>', 'username': '<USERNAME>', 'password': '<PASSWORD>', 'grant_type': 'password' }
response = requests.post(url, data=payload)
access_token = response.json()['access_token']
This code will make a POST request to the Keycloak token endpoint and obtain an access token.
Use the access token to make the GET request to the API. You can use the Authorization header to include the access token in the GET request. Here's an example of how you can use the requests library in Python to make the GET request:
import requests
url = 'http://<API_HOST>/api/<API_ENDPOINT>'
headers = { 'Authorization': 'Bearer ' + access_token }
response = requests.get(url, headers=headers)
data = response.json()
You can use the ExecuteScript processor in NiFi to execute the Python code and obtain the data from the API. You can use the InvokeHTTP processor to make the initial GET request to the Keycloak sign-in page and extract the necessary information, such as the Keycloak username and password, to use in the Python code. You can use NiFi's built-in ExtractText processor to extract the necessary information from the InvokeHTTP response.
This code will make a GET request to the API with the access token included in the Authorization header. Sincerely, Hannah
... View more
03-22-2023
08:45 AM
@Jacccs Did you solve your problem? I have a similar case
... View more
12-05-2022
09:09 AM
@Jacccs Was the nifi-app.log created? If so, what was observed in that log? Please share the exact versions of NiFi you used. Have you tried using a Java JDK instead of Java JRE? Thanks, Matt
... View more
11-15-2022
07:51 AM
@Jacccs An example or detailed description of yoru use case may be helpful in providing the bets guidance for you. While the NiFi Expression Language (NEL) function anyMatchingAttribute expects a java regular expression that searches and returns values for multiple FlowFile attributes, that does not appear to be what you need??? Your attribute "attributeToSearch" implies only a single specific FlowFile attribute is desire to be checked if it contains some "${value}". If this is correct, you would be able to use the following NEL: ${literal("${${attributeToSearch}}"):contains('${value}')} For above NEL, let's assume a FlowFile with attribute "attributeToSearch" set to "username". A FlowFile attribute "username" set to "admin-matt". A FlowFile attribute "value" set to "admin". The result of above NEL statement would be true ${$attributeToSearch}} would first resolve to ${username} which would then resolve to "admin-matt". That "admin-matt" string would be then passed to the NEL contains function which will to check to see if that string contains the string "admin" within it. The result is a boolean "true" or "false". If you found that the provided solution(s) assisted you with your query, please take a moment to login and click Accept as Solution below each response that helped. Thank you, Matt
... View more
09-14-2022
11:43 AM
Hello I was using an updateRecord processor to concatenate several columns like so /new_columns= concat(/col1,/col2,/col3) however now the columns I need to concatenate are dynamic and I was wondering if there was a way to achieve something similar if the columns I needed to concatenate we named in an attribute. Thank you
... View more
Labels:
- Labels:
-
Apache NiFi
09-01-2022
12:05 PM
Hi , you can use QueryRecord Processor. For more information please see: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi/nifi-standard-nar/1.12.1/org.apache.nifi.processors.standard.QueryRecord/additionalDetails.html If you find this helpful please accept solution. Thanks
... View more
08-31-2022
03:02 PM
1 Kudo
Hi , Not sure if this is possible with out of the box processor. I can think of ReplaceText first to replace different delimiters like (-) or white-space (\s) to common delimiter like (,) however if there is a white space before or after other delimiters like (-) or (,) its not going to work. Another option is to use ExecuteScript processor where you try to read each line (after the header) from the flowfile content and then use string split function and try it with different delimiter, once you get two array elements you construct your new string with the new column header and delimiter and transfer to the success relationship.
... View more