etcd-production-setup icon indicating copy to clipboard operation
etcd-production-setup copied to clipboard

add etcd-ca method to generate certs

Open yichengq opened this issue 9 years ago • 8 comments

for github.com/coreos/etcd-ca

yichengq avatar Mar 12 '15 21:03 yichengq

Hi @jakubdyszkiewicz I never encounter this issue. Could you show your code execute result and terminal when extracting the environment variable?

In general, it's not possible.

TonyPythoneer avatar Aug 18 '19 13:08 TonyPythoneer

Well... it is possible. Take a look:

Complete sample code:

package main

import (
	"fmt"
	"github.com/kelseyhightower/envconfig"
)

type Something struct {
	User string `envconfig:"user"`
}


func main() {
	something := Something{}
	err := envconfig.Process("my_app", &something)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Value is: %v", something.User)
}

terminal output

jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ echo $MY_APP_USER


jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ echo $USER
jakub.dyszkiewicz

jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ ./sample-go
Value is: jakub.dyszkiewicz

jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ set -gx MY_APP_USER other_user

jakub.dyszkiewicz in /Users/jakub.dyszkiewicz/dev/sample-go
❯❯❯ ./sample-go
Value is: other_user

jakubdyszkiewicz avatar Aug 18 '19 14:08 jakubdyszkiewicz

It's wired. Could you push a PR with your case in unittest makes CI job help validate?

It's because CI is the role of neutral referee. If we have any issue happens in personal computer, the best solution is to add more test for this repo.

TonyPythoneer avatar Aug 18 '19 14:08 TonyPythoneer

@jakubdyszkiewicz I ran into a similar issue and while investigating I found this is specifically triggered when using the envconfig struct tag to specify the environment variable name. When using this tag it will fall back to the environment value specified even when using a prefix.

I believe this is the intended behavior based on this note in the README:

If envconfig can't find an environment variable in the form PREFIX_MYVAR, and there is a struct tag defined, it will try to populate your variable with an environment variable that directly matches the envconfig tag in your struct definition:

aqtodd avatar Oct 02 '19 21:10 aqtodd

Here's a playground snippet demonstrating the difference: https://play.golang.org/p/KssTfMgXED1


import (
	"fmt"
	"os"
	"github.com/kelseyhightower/envconfig"
)

type ImplicitTest struct {
	User string
}

type ExplicitTest struct {
	User string `envconfig:"USER"`
}

func main() {
	os.Setenv("USER", "test")

	implicitTest := ImplicitTest{}
	envconfig.MustProcess("my_app", &implicitTest)
	fmt.Printf("The value of ImplicitTest.User: \"%s\"\n", implicitTest.User)
	
	explicitTest := ExplicitTest{}
	envconfig.MustProcess("my_app", &explicitTest)
	fmt.Printf("The value of ExplicitTest.User: \"%s\"\n", explicitTest.User)
}

output:

The value of ImplicitTest.User: ""
The value of ExplicitTest.User: "test"

aqtodd avatar Oct 02 '19 21:10 aqtodd

Same problem here.

limoli avatar Nov 27 '19 19:11 limoli

Hi. I think this PR is the complete solution. https://github.com/kelseyhightower/envconfig/pull/214

pr0n1x avatar Jul 10 '24 11:07 pr0n1x

I realized that there is no way to fix this problem without partial backward compatibility break. This wrong (IMHO) behavior is the author's decision (it's obvious if you look at the unit tests). Using new 'no_pfx' tag is trade-off but quite fit solution. See second commit in my PR https://github.com/kelseyhightower/envconfig/pull/214

pr0n1x avatar Jul 16 '24 06:07 pr0n1x