Typescript newbie question: Is there a way to type...
# typescript
s
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
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
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
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
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