https://pulumi.com logo
#typescript
Title
# typescript
s

stocky-island-3676

09/06/2019, 5:26 PM
Typescript newbie question: Is there a way to type the resulting
data
values of a Kubernetes
Secret.get()
such as (in pseudo-language):
Copy code
type ServiceAccountSecretData = [ 
  "ca.crt": string,
  "namespace": string,
  "token": string,
]
The “only” thing I’ve come up yet is with
type SecretData = { [key: string]: string }
(see attached snippet).
w

white-balloon-205

09/06/2019, 9:24 PM
The
.data
itself will be a
{ [id: string]: string}
map as you note, where the values of each entry are base64-encoded binary content. So I think the code you have above is about right - though it's likely you want to base64 decode the value before returning it. I am honestly not exactly sure why this property is typed as
object
instead of
{ [key: string]: string }
as
stringData
is.
s

stocky-island-3676

09/09/2019, 3:14 PM
Ok. So, there isn’t a Typescript way to unmarshal the
.data
object with a specific type kind of like the
ServiceAccountSecretData
I mentioned? Didn’t find a reason for why the
Secret.data
isn’t of type
stringData
, yet.
Secret.stringData
itself is a “write-only convenience method”. Hard to find out when it was introduced as the
provider.ts
was splitted here: https://github.com/pulumi/pulumi-kubernetes/pull/480/files?file-filters%5B%5D=.ts#diff-f68b8bd99be4835ca9d8a3c3a820df9dR48
w

white-balloon-205

09/09/2019, 3:22 PM
You can cast the
object
to
{ [id: string]: string }
, as that is the type the value actually will have. But you’ll need to wrote actual deserialization code to base64 decode and parse the contents of you have some more specific data you are trying to extract.
s

stocky-island-3676

09/09/2019, 3:30 PM
Sure. I know. My code snippet works out. Wouldn’t it be more convenient to already have this field as type
{ [key: string]: string }
? Convenience for infrastructure coding. That’s what Pulumi is about in the long-run, isn’t it?
BTW: There was open confusion about getting Secrets in general: https://stackoverflow.com/questions/52523443/pulumi-retrieve-kubernetes-secret-value