Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Packager config mods #338

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions packager/util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@ type Config struct {
Port int
CertFile string // This must be the full certificate chain.
KeyFile string // Just for the first cert, obviously.

// NewCertFile will be read/write. CertFile and NewCertFile will be set when both
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about for the first sentence, "When set, both CertFile and NewCertFile will be read/write." (Though, as you're probably aware, the user-facing documentation is in amppkg.example.toml.)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

// are valid and that once CertFile becomes invalid, NewCertFile will replace it
// (CertFile = NewCertFile) and NewCertFile will be set to empty. This will also
// apply to disk copies as well (which we may require to be some sort of shared
// filesystem, if multiple replicas of ammpackager are running).
NewCertFile string // The new full certificate chain replacing the expired one.
twifkak marked this conversation as resolved.
Show resolved Hide resolved
NewKeyFile string // For the first cert in NewCertFile.
AutoRenewCert bool // Should we auto-renew cert? Defaults to false.
OCSPCache string
ForwardedRequestHeaders []string
URLSet []URLSet
Expand All @@ -55,13 +59,14 @@ type URLPattern struct {
}

type ACMEConfig struct {
Prod *ACMEServerConfig
Staging *ACMEServerConfig
Production *ACMEServerConfig
Development *ACMEServerConfig
}

type ACMEServerConfig struct {
DiscoURL string // ACME Production Directory Resource URL
AccountURL string // ACME Account URL
DiscoURL string // ACME Directory Resource URL
AccountURL string // ACME Account URL. If non-empty, we
// will auto-renew cert via ACME.
}

// TODO(twifkak): Extract default values into a function separate from the one
Expand Down
22 changes: 9 additions & 13 deletions packager/util/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,11 @@ func TestInvalidQueryRE(t *testing.T) {
`))), "QueryRE must be a valid regexp")
}

func TestOptionalAutoRenewCertAndKey(t *testing.T) {
func TestOptionalNewCert(t *testing.T) {
config, err := ReadConfig([]byte(`
CertFile = "cert.pem"
KeyFile = "key.pem"
NewCertFile = "newcert.pem"
NewKeyFile = "newkey.pem"
AutoRenewCert = false
OCSPCache = "/tmp/ocsp"
[[URLSet]]
[URLSet.Sign]
Expand All @@ -192,8 +190,6 @@ func TestOptionalAutoRenewCertAndKey(t *testing.T) {
CertFile: "cert.pem",
KeyFile: "key.pem",
NewCertFile: "newcert.pem",
AutoRenewCert: false,
NewKeyFile: "newkey.pem",
OCSPCache: "/tmp/ocsp",
URLSet: []URLSet{{
Sign: &URLPattern{
Expand All @@ -215,12 +211,12 @@ func TestOptionalACMEConfig(t *testing.T) {
[URLSet.Sign]
Domain = "example.com"
[ACMEConfig]
[ACMEConfig.Prod]
[ACMEConfig.Production]
DiscoURL = "prod.disco.url"
AccountURL = "prod.account.url"
[ACMEConfig.Staging]
DiscoURL = "staging.disco.url"
AccountURL = "staging.account.url"
[ACMEConfig.Development]
DiscoURL = "dev.disco.url"
AccountURL = "dev.account.url"
`))
require.NoError(t, err)
assert.Equal(t, Config{
Expand All @@ -229,13 +225,13 @@ func TestOptionalACMEConfig(t *testing.T) {
KeyFile: "key.pem",
OCSPCache: "/tmp/ocsp",
ACMEConfig: &ACMEConfig{
Prod: &ACMEServerConfig{
Production: &ACMEServerConfig{
DiscoURL: "prod.disco.url",
AccountURL: "prod.account.url",
},
Staging: &ACMEServerConfig{
DiscoURL: "staging.disco.url",
AccountURL: "staging.account.url",
Development: &ACMEServerConfig{
DiscoURL: "dev.disco.url",
AccountURL: "dev.account.url",
},
},
URLSet: []URLSet{{
Expand Down