Backwards compatability fixes
This commit is contained in:
		| @@ -46,6 +46,7 @@ type Config struct { | |||||||
|  |  | ||||||
| 	// Legacy | 	// Legacy | ||||||
| 	CookieDomainsLegacy CookieDomains      `long:"cookie-domains" env:"COOKIE_DOMAINS" description:"DEPRECATED - Use \"cookie-domain\""` | 	CookieDomainsLegacy CookieDomains      `long:"cookie-domains" env:"COOKIE_DOMAINS" description:"DEPRECATED - Use \"cookie-domain\""` | ||||||
|  | 	CookieSecretLegacy  string             `long:"cookie-secret" env:"COOKIE_SECRET" description:"DEPRECATED - Use \"secret\""` | ||||||
| 	CookieSecureLegacy  string             `long:"cookie-secure" env:"COOKIE_SECURE" description:"DEPRECATED - Use \"insecure-cookie\""` | 	CookieSecureLegacy  string             `long:"cookie-secure" env:"COOKIE_SECURE" description:"DEPRECATED - Use \"insecure-cookie\""` | ||||||
| 	DomainsLegacy       CommaSeparatedList `long:"domains" env:"DOMAINS" description:"DEPRECATED - Use \"domain\""` | 	DomainsLegacy       CommaSeparatedList `long:"domains" env:"DOMAINS" description:"DEPRECATED - Use \"domain\""` | ||||||
| 	ClientIdLegacy      string             `long:"client-id" env:"CLIENT_ID" group:"DEPs" description:"DEPRECATED - Use \"providers.google.client-id\""` | 	ClientIdLegacy      string             `long:"client-id" env:"CLIENT_ID" group:"DEPs" description:"DEPRECATED - Use \"providers.google.client-id\""` | ||||||
| @@ -98,6 +99,9 @@ func NewConfig(args []string) (Config, error) { | |||||||
| 	// any further errors can be logged via logrus instead of printed? | 	// any further errors can be logged via logrus instead of printed? | ||||||
|  |  | ||||||
| 	// Backwards compatability | 	// Backwards compatability | ||||||
|  | 	if c.CookieSecretLegacy != "" && c.SecretString == "" { | ||||||
|  | 		c.SecretString = c.CookieSecretLegacy | ||||||
|  | 	} | ||||||
| 	if c.ClientIdLegacy != "" { | 	if c.ClientIdLegacy != "" { | ||||||
| 		c.Providers.Google.ClientId = c.ClientIdLegacy | 		c.Providers.Google.ClientId = c.ClientIdLegacy | ||||||
| 	} | 	} | ||||||
| @@ -222,7 +226,7 @@ func handlFlagError(err error) error { | |||||||
| 	return err | 	return err | ||||||
| } | } | ||||||
|  |  | ||||||
| var legacyFileFormat = regexp.MustCompile(`^([a-z-]+) ([\w\W]+)$`) | var legacyFileFormat = regexp.MustCompile(`(?m)^([a-z-]+) (.*)$`) | ||||||
|  |  | ||||||
| func convertLegacyToIni(name string) (io.Reader, error) { | func convertLegacyToIni(name string) (io.Reader, error) { | ||||||
| 	b, err := ioutil.ReadFile(name) | 	b, err := ioutil.ReadFile(name) | ||||||
|   | |||||||
| @@ -104,6 +104,7 @@ func TestConfigFlagBackwardsCompatability(t *testing.T) { | |||||||
| 		"--client-id=clientid", | 		"--client-id=clientid", | ||||||
| 		"--client-secret=verysecret", | 		"--client-secret=verysecret", | ||||||
| 		"--prompt=prompt", | 		"--prompt=prompt", | ||||||
|  | 		"--cookie-secret=veryverysecret", | ||||||
| 		"--lifetime=200", | 		"--lifetime=200", | ||||||
| 		"--cookie-secure=false", | 		"--cookie-secure=false", | ||||||
| 		"--cookie-domains=test1.com,example.org", | 		"--cookie-domains=test1.com,example.org", | ||||||
| @@ -129,6 +130,9 @@ func TestConfigFlagBackwardsCompatability(t *testing.T) { | |||||||
| 	expected3 := CommaSeparatedList{"test3.com", "example.org", "another3.net"} | 	expected3 := CommaSeparatedList{"test3.com", "example.org", "another3.net"} | ||||||
| 	assert.Equal(expected3, c.Whitelist, "should read legacy comma separated list whitelist") | 	assert.Equal(expected3, c.Whitelist, "should read legacy comma separated list whitelist") | ||||||
|  |  | ||||||
|  | 	// Name changed | ||||||
|  | 	assert.Equal([]byte("veryverysecret"), c.Secret) | ||||||
|  |  | ||||||
| 	// Google provider params used to be top level | 	// Google provider params used to be top level | ||||||
| 	assert.Equal("clientid", c.ClientIdLegacy) | 	assert.Equal("clientid", c.ClientIdLegacy) | ||||||
| 	assert.Equal("clientid", c.Providers.Google.ClientId, "--client-id should set providers.google.client-id") | 	assert.Equal("clientid", c.Providers.Google.ClientId, "--client-id should set providers.google.client-id") | ||||||
| @@ -170,7 +174,8 @@ func TestConfigFileBackwardsCompatability(t *testing.T) { | |||||||
| 	}) | 	}) | ||||||
| 	require.Nil(t, err) | 	require.Nil(t, err) | ||||||
|  |  | ||||||
| 	assert.Equal("/two", c.Path, "Variable in legacy config file should be read") | 	assert.Equal("/two", c.Path, "variable in legacy config file should be read") | ||||||
|  | 	assert.Equal("auth.legacy.com", c.AuthHost, "variable in legacy config file should be read") | ||||||
| } | } | ||||||
|  |  | ||||||
| func TestConfigParseEnvironment(t *testing.T) { | func TestConfigParseEnvironment(t *testing.T) { | ||||||
|   | |||||||
| @@ -1 +1,2 @@ | |||||||
| url-path two | url-path two | ||||||
|  | auth-host auth.legacy.com | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Thom Seddon
					Thom Seddon