From 404741fbbf1252ed2cc14250c15b14a2c6d19550 Mon Sep 17 00:00:00 2001 From: Lewis Marshall Date: Sun, 22 Jun 2014 13:56:42 +0100 Subject: [PATCH] bootstrap: Support setting the Controller domain Signed-off-by: Lewis Marshall --- add_route_action.go | 1 + bootstrapper/manifest.json | 6 +++--- gen_tls_cert_action.go | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/add_route_action.go b/add_route_action.go index 08a924ead7..ca336ad726 100644 --- a/add_route_action.go +++ b/add_route_action.go @@ -42,6 +42,7 @@ func (a *AddRouteAction) Run(s *State) error { return err } route := a.Route.HTTPRoute() + route.Domain = interpolate(s, route.Domain) route.TLSCert = cert.Cert route.TLSKey = cert.PrivateKey a.Route = route.ToRoute() diff --git a/bootstrapper/manifest.json b/bootstrapper/manifest.json index d5920dc28a..a0c97905dd 100644 --- a/bootstrapper/manifest.json +++ b/bootstrapper/manifest.json @@ -180,7 +180,7 @@ { "id": "controller-cert", "action": "gen-tls-cert", - "hosts": ["localhost", "127.0.0.1"] + "hosts": ["{{ or (getenv `CONTROLLER_DOMAIN`) `localhost` }}", "127.0.0.1"] }, { "id": "strowger-wait", @@ -206,12 +206,12 @@ "type": "http", "config": { "service": "flynn-controller", - "domain": "localhost" + "domain": "{{ or (getenv `CONTROLLER_DOMAIN`) `localhost` }}" } }, { "id": "log-complete", "action": "log", - "output": "Flynn bootstrapping complete. Install flynn-cli and paste the line below into a new terminal window:\n\nflynn server-add -g localhost:2201 -p {{ (index .StepData `controller-cert`).Pin }} default https://localhost:8081 {{ (index .StepData `controller-key`).Data }}" + "output": "Flynn bootstrapping complete. Install flynn-cli and paste the line below into a new terminal window:\n\nflynn server-add -g localhost:2201 -p {{ (index .StepData `controller-cert`).Pin }} default https://{{ or (getenv `CONTROLLER_DOMAIN`) `localhost` }}:8081 {{ (index .StepData `controller-key`).Data }}" } ] diff --git a/gen_tls_cert_action.go b/gen_tls_cert_action.go index 30dd85a539..21c7676797 100644 --- a/gen_tls_cert_action.go +++ b/gen_tls_cert_action.go @@ -42,11 +42,11 @@ func (c *TLSCert) String() string { func (a *GenTLSCertAction) Run(s *State) (err error) { data := &TLSCert{} s.StepData[a.ID] = data - data.Cert, data.PrivateKey, data.Pin, err = a.generateCert() + data.Cert, data.PrivateKey, data.Pin, err = a.generateCert(s) return } -func (a *GenTLSCertAction) generateCert() (cert, privKey, pin string, err error) { +func (a *GenTLSCertAction) generateCert(s *State) (cert, privKey, pin string, err error) { priv, err := rsa.GenerateKey(rand.Reader, 2048) if err != nil { return @@ -66,10 +66,11 @@ func (a *GenTLSCertAction) generateCert() (cert, privKey, pin string, err error) } for _, h := range a.Hosts { - if ip := net.ParseIP(h); ip != nil { + host := interpolate(s, h) + if ip := net.ParseIP(host); ip != nil { template.IPAddresses = append(template.IPAddresses, ip) } else { - template.DNSNames = append(template.DNSNames, h) + template.DNSNames = append(template.DNSNames, host) } }