Adding Expressions to Credentials

Hi I found out we can add Expressions to Credentials just like any other node but its always empty so is there a way I can point the expression to a workflow so I can pull API keys from Bitwarden or HTTP Request, maybe a file.

Cheers

Hi I found out we can add Expressions to Credentials just like any other node but it’s always empty so

Does the node have any input? Can you share the expression you are using?

there a way I can point the expression to a workflow so I can pull API keys from Bitwarden or HTTP Request, maybe a file.

You can point the expression to the input data of the node where you are using the expression. So, you can make an HTTP that returns the credentials and reference them in the next node.

Hi @RicardoE105

I have pasted some screenshots
So in here is the Cortex API where you can specify the instance URL , Key using Expression from the Gear button

However when I click on it it doesn’t show any node or variable like any other add expression during the workflow

so this is what I was asking how can I fill out any Credentials using Expressions.

Cheers :smile:

Do you have any other nodes in the workflow? The expression editor only shows nodes in the current workflow.

So you’d either want to pull the credentials by adding nodes to do so before the current node, or pass the credentials in using a webhook trigger.

@sirdavidoff

There is a file which I read using SSH

The file contain some passwords and API key I still need to clean it a bit using functions but still nothing is showing on the credentials expression

In the SSH node, is the file showing up as “binary data”? If yes, here’s the general flow:

  1. Ingest the file via Execute command node (could also use “Read binary file” node, if it’s just sitting on the filesystem)
  2. Convert that binary data into JSON data with “Move Binary Data” node
  3. In credentials view of the Cortex node, you should now be able to access the JSON data from the “Move Binary Data” node via Expression Editor.

Let us know how you get on!

hi @maxT

Its not binary file its config.ini file so I extract API key from it using function and should feed it to Cortex. I will try the workflow that you created above and keep you posted.

Cheers

1 Like

@MXA_Music in the case of an .ini file, the “Move binary data” node method won’t work. So if you’ve already got a function node extracting the API key, I recommend simply appending the API key to the JSON output payload of the function node: items[0].json.apiKey = {api key here};

@maxT

Thank you so much it worked so now i can read the file and update the API key and localhost from the file


and thats the final workflow

Once again thank you so much :blush:

2 Likes

That’s great to hear @MXA_Music - is there any chance you could post the code you used inside the FunctionItem node to help others in future?

@maxT

Absolutely its simple code

var key = []

get_all_keys = item.stdout.split("[keys]")[1]

get_hive_key = get_all_keys.split("hiveKey = ")[1]

key.push({
hiveKey : get_hive_key
});

return key

Treating the Conf.ini file as string and the output will look like this

[
  [
   {
     "hiveKey": "B6G1R7IBOJo0RIksEMzts2pGzSV6YCW4"
   }
  ]
]

and to read it from other nodes its

{{$node["FunctionItem"].json["0"]["hiveKey"]}}

Save this expression in the API Key samy thing can work for the URL as well

The Sample Conf.ini is below

; Section: sectionone
[sectionone]

domains = localhost
username = admin
password = admin
[keys]

hiveKey = B6G1R7IBOJo0RIksEMzts2pGzSV6YCW4

This just dummy data for testing :smiley:

1 Like