From 37e0c67165b83c8297e2ff20d6d71302f4d8c816 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 14 Feb 2016 20:00:16 +0100 Subject: split --- certificate.go | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) (limited to 'certificate.go') 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) { -- cgit v1.2.3