Read enviroments secrets from github
danieeeld2 opened this issue · comments
I have a Go 1.21
project, and I am using Koanf
as configuration library. I have the configuration key-values
in a YALM
file, but this file cannot be upload to github, because is not secure. Also, we have a cirrus-test
in github, that tests the code before merge. As a consequence, we need some of those key-values
to instance the koanf configuration; so we decided to create some github secrets and try to read them, but we didn't achive it. We tried to create the secrets directly and, also, create an enviroment in github and, in it, the secrets; but the code doesn't recognise it. The code is the following:
if err := k.Load(env.Provider("LOGISTICSROUTES_", ".", func(s string) string {
return strings.Replace(strings.ToLower(strings.TrimPrefix(s, "LOGISTICSROUTES_")), "_", ".", -1)
}), nil); err != nil {
return nil, err
}
}
k.Print()
This is the code from the example EnvReadingExample
When I do k.Print()
, it is empty. Also, we changed the prefix LOGISTICSROUTES_
to ""
and we saw that it is not reading the github variables.
Sorry, missed this message. Did you figure this out? Your code snippet looks fine.
Sorry, missed this message. Did you figure this out? Your code snippet looks fine.
Yes, I was misunderstanding what the teacher was asking us. I was trying to read secret variables in a github environment and that is only possible from github actions. Sorry for the confusion. Should I close the issue or do you close it?
I solved it by creating an actions that reads the variables and creates a local environment, and then using the code fragment referenced above.