I have a string stored in the config as secret, af...
# general
c
I have a string stored in the config as secret, after retreival with config.requireSecret(‘name’) I actually need to manipulate it a bit, i.e. “unsecretify” it so that string operations work on it. How do I do that? It seems this is an Output<T> marked as secret and it just refuses to become anything else.
l
c
Oh yes… however, the output of an apply is another Output<T> which is marked secret, and round and round I go…
g
I think @broad-dog-22463 is working on that issue now, actually
c
Perhaps I dare to be a bit hopeful then? As it is I’m about to give up and use the aws secrets manager as this unfortunately is useless to me at this time.
Hehe, no, those turns out to be Secret(s) too… round and round…
l
Could you give us more information about your use case and what you're trying to do with the resulting string?
c
Oh, sure. Hm. I have a header/value pair used for simple token access verification in a web service. I need to store those in the state for easy access: I don’t want them in the code that ends up in the repository for obvious reasons. A separate program (in pulumi) will later pull thos head/value pairs, do a bit of splitting and lowercasing and store them in a firewall.
I figured that treating them as secrets as far as a the config goes (encrypted in the file) was a good idea, but… sort of hard to get at them.
Hm. I was wrong about aws secrets manager, that does work.
But it would have been a lot more convenient to use pulumi directly.
l
I may be misunderstanding something here, but I believe you should be able to use pulumi directly. When you run
.apply
on a secret, the callback will receive the raw value. You can manipulate that value within the apply (lowercase, add on addition strings to it, etc), and it will return a new secret.
Any other pulumi provider that you're calling should be able to accept that manipulated secret.
c
Ok… Let me give it a try.
It… sort of seems to work… the problem is the apply which adds that very asynchronous aspect to the whole… hm. But… it can be coded around I suppose.
An object is created in the apply. Is there a way of passing the value of that OUT of the apply function so that it can be used in the subsequent code?
l
In these cases, you almost always do this via apply. It's pretty rare that you actually need to escape and get the raw value. Can you share some sample code, perhaps we can help?
c
It’s fairly simple: based on the items above I have a function that creates an object in the system holding the header. The apply above is valid for one header of course. As I have more than one, that needs to be done sequentially in separate apply calls, external to each other. Later in the code I need the objects in order to create a final object organising the two.
l
You can use
.all
to coordinate multiple output values and then call
.apply
and manipulate the resulting array https://www.pulumi.com/docs/intro/concepts/programming-model/#all
c
Great, I will try that, thanks!
👍 1
I think a big problem stems from my inexperience with typescript… I’ll do some reading up on the concept of the callbacks and try to find some code to read. Right now it’s a bit of a dead end as I’m likely trying to work the mechanism the wrong way - in my experience when something “just don’t work” it’s usually because it in fact wasn’t intended to work that way, but was designed for a different approach.