How can I create a Cypher secret with a dynamic Variable?

Hello,

I want to read a cypher with a dynamic variable name, but syntactically, the call doesn’t go through.

Has anyone ever had this happen and gotten away with it?

One simple example in Powershell :

$commonName = “azr-server1”
$val1 =“<%=cypher.read(‘secret/’ + $commonName)%>”

Hi,

I’ve tried various ways of getting that interpolation (and variations of it) to work without success.

However, depending on your context you may be able to use an instance or server var (name?) to get the secret suffix.

The example mentioned below is from our [docs here] (bottom of section) (Variables — Morpheus Docs documentation)

cypher: <%=cypher.read('secret/' + zone.code)%>

To add to what @Ollie_Phillips mentioned, the Cypher is interpreted immediately, even before the script runs, since the templating happens immediately. Because of this, your variable $commonName won’t be populated with any data. However, as Ollie showed, using a value provided from Morpheus like zone.code or instance.name is available immediately.

One other idea is to use the API to add a Cypher, instead of using the variable method. This way it is ran with your script and you can use any of your variables:

1 Like

Thanks,

My need is indeed specific and doesn’t require Morpheus data variables.

I thought of the API, but the goal of the exercise was to obtain the cypher and put it in a Powershell file template.

I don’t necessarily want to distribute a token on the client side

Regards

Thinking about it, if you can run your script in an operational workflow you can do this via result chaining,

You need two tasks, this is an example setup:

Task 1 - Powershell - set the output to single value. Give the task a code of commonName or whatever, but be sure to reference that code in the second task.

$commonName = “azr-server1”
echo $commonName 

Task 2 - Powershell

$val1 = "<%=cypher.read('secret/' + results.commonName)%>"
echo $val1

Run as a workflow with Task1 then Task 2. In my very quick testing that works.