From c49a0bf48ea10b54dbac3480716d9786a0ce8411 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 31 Jan 2016 23:15:27 +0100 Subject: Split files (experimental) --- register.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 register.go (limited to 'register.go') diff --git a/register.go b/register.go new file mode 100644 index 0000000..e002853 --- /dev/null +++ b/register.go @@ -0,0 +1,48 @@ +package acme + +import ( + "net" + "time" + + "github.com/square/go-jose" +) + +// Registration Objects +type Registration struct { + Resource Resource `json:"resource"` // new-reg + Contact Contacts `json:"contact,omitempty"` + Agreement string `json:"agreement,omitempty"` + Authorizations string `json:"authorizations,omitempty"` + Certificates string `json:"certificates,omitempty"` + ID int `json:"id,omitempty"` + Key *jose.JsonWebKey `json:"key,omitempty"` + InitialIP *net.IP `json:"initialIp,omitempty"` // not in draft + CreatedAt *time.Time `json:"createdAt,omitempty"` +} + +func (p *Provider) Register(s Signer, c Contacts) error { + // first step: new-reg + req := &Registration{ + Resource: ResNewReg, + Contact: c, + } + resp, err := p.post(p.NewReg, s, req) + if err != nil { + return err + } + resp.Body.Close() + ns := parseHeader(resp) + + // second step: reg, agree to tos + req = &Registration{ + Resource: ResReg, + Agreement: ns.Link["terms-of-service"], + } + resp, err = p.post(ns.Location, s, req) + if err != nil { + return err + } + resp.Body.Close() + + return nil +} -- cgit v1.2.3