https://pulumi.com logo
#general
Title
# general
r

red-airline-54646

10/25/2023, 8:20 AM
how to convert a pulumi.StringOutput into regular string? this doesn't work
fmt.Print(string(githubPAT.Value()))
p

plain-parrot-21984

10/25/2023, 8:24 AM
Have you tried asking https://www.pulumi.com/ai ?
r

red-airline-54646

10/25/2023, 8:25 AM
will try 🙂
Copy code
strgithubPAT := githubPAT.Value().ToStringOutput().ApplyT(func(s string) (string, error) {
		// Now you can work with 's' as a standard Go string
		// Here we're just passing it through
		return s, nil
	}).(pulumi.StringOutput)

	// Export the string
	ctx.Export("outputS", strgithubPAT)
how can i pass it to this?
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s",  strgithubPAT))
m

melodic-tomato-39005

10/25/2023, 8:32 AM
You can’t. This is often a bit surprising, see here for the reason. You need to do whatever you need to do with the string inside
ApplyT
.
p

plain-parrot-21984

10/25/2023, 8:33 AM
Just to mention, there's also
pulumi.Sprintf()
instead of
fmt.Sprintf()
r

red-airline-54646

10/25/2023, 8:40 AM
it doesn't like the
pulumi.Sprintf
bcoz
Set
requires a string?
it doesn't complain with
fmt.Sprintf
but preview shows Unauthorized meaning something off with the conversion of pulumi string to regular go string.
Copy code
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", githubPAT.Value().ApplyT(func(value string) string {
		return value
	})))
p

plain-parrot-21984

10/25/2023, 9:00 AM
I'm sorry to say that I'm no expert on this myself. I usually ask the AI to provide a solution and test it out, but I haven't been using Pulumi or Go for that matter long enough to provide expert help here 😞
r

red-airline-54646

10/25/2023, 9:01 AM
no worries. will share it too once i figured it out :)
2 Views