aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-02-14 20:00:16 +0100
committerDimitri Sokolyuk <demon@dim13.org>2016-02-14 20:00:16 +0100
commit37e0c67165b83c8297e2ff20d6d71302f4d8c816 (patch)
tree723386163f5807def94482d77e1c9f57cfe2cf10
parent62e11e40ae1c3b6ce09227a6a7595eb3128bb965 (diff)
split
-rw-r--r--certificate.go30
1 files changed, 19 insertions, 11 deletions
diff --git a/certificate.go b/certificate.go
index 292059a..195d56f 100644
--- a/certificate.go
+++ b/certificate.go
@@ -8,29 +8,37 @@ type CSR struct {
}
func (p *Provider) Bundle(s Signer, d *Desire) error {
- d.cert = make([]*x509.Certificate, 2)
- // first step: post csr
- csr, err := d.CSR()
+ crt, up, err := p.RequestCert(s, d)
+ if err != nil {
+ return err
+ }
+ ca, err := p.GetCert(up)
if err != nil {
return err
}
+ d.cert = []*x509.Certificate{crt, ca}
+ return nil
+}
+
+func (p *Provider) RequestCert(s Signer, d *Desire) (*x509.Certificate, string, error) {
+ csr, err := d.CSR()
+ if err != nil {
+ return nil, "", err
+ }
req := &CSR{
Resource: ResNewCert,
CSR: csr,
}
resp, err := p.post(p.NewCert, s, req)
if err != nil {
- return err
+ return nil, "", err
}
- d.cert[0], err = parseCert(resp)
+ ns := parseHeader(resp)
+ crt, err := parseCert(resp)
if err != nil {
- return err
+ return nil, "", err
}
- ns := parseHeader(resp)
-
- // second step: cet CA
- d.cert[1], err = p.GetCert(ns.Link["up"])
- return err
+ return crt, ns.Link["up"], nil
}
func (p *Provider) GetCert(uri string) (*x509.Certificate, error) {