I would like to retrieve a Github secret content from a script via Golang, that is executed from Github actions.
In this particular situation, the secret value stored in Github secrets has a space. I mean the secret value is: JWT <token-string>
.
The way to retrieve Github secrets from any script in any language as long they are executed in Github actions runners is by reading them as environment variables. So what I am doing is to read it in this way: (Please see the Authorization:
element in the slice of string below)
func MyTestFunction(t *testing.T, serverURL string) {
type AppLogin struct {
token string
}
method := "GET"
headers := map[string][]string{
"Content-Type": []string{"application/json, text/plain, */*"},
"Authorization": []string{os.Getenv("USER_JWT")},
}
The thing is that I am not getting the value from Github secrets when running Github action runner. I know this is happening since I tried to print it in this way, but nothing comes up:
fmt.Println("My JWT", os.Getenv("USER_JWT"))
I am afraid it is happening because that space between "JWT "
and the token, I mean JWT <token-string>
.
Here says:
Secret names can only contain alphanumeric characters ([a-z], [A-Z], [0-9]) or underscores (_). Spaces are not allowed.
As an important fact, my token secret value also contains .
character in its value. The value is something like this:
JWT xxxxxxx8888xxxxdsdsfsfsf9.eyJxxxxxxx8888xxxxdsdsfsfsf9.Tfgxadsdsfsfsasasad_s7sdsdsfgsgcs
So I believe, that is the reason why I cannot get the secret value.
I am not sure how I can fetch this from my Golang script, I even tried to modify the Github secret value just having it as a value the <token-string>
in order to avoid the space in the value, and I am calling it from go in this way:
"Authorization": []string{"JWT ", os.Getenv("SPECKLE_USER_JWT")}
But it did not work.
I read here that when calling secrets with special characters from github actions we have to escape them with single quotes ' '
but this process is from .yaml
file github actions.
The previous solution alternatives I am trying to, they works on my local machine, since my bash cli is able to get environment variables with spaces in their values. I am not sure how can I - let's say "escape" - a secret with space in a string as I have from golang.