aboutsummaryrefslogtreecommitdiff
path: root/client.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-21 16:42:06 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-21 16:42:06 +0100
commit352e343f51a7a923f50b275f188d82e08d8fa318 (patch)
tree5780c7506f02245f6c2108231e1dadf628f28518 /client.go
parentacb9c5d087924b77d83a3fc65813c19b65e90298 (diff)
Agree to TOS
Diffstat (limited to 'client.go')
-rw-r--r--client.go41
1 files changed, 20 insertions, 21 deletions
diff --git a/client.go b/client.go
index 4cb0aa9..16644c5 100644
--- a/client.go
+++ b/client.go
@@ -159,41 +159,40 @@ func (c *Client) parseHeader(r *http.Response) {
challenge cert-chain
*/
-func (c *Client) Register(a *Account) (*Registration, error) {
+func (c *Client) Register(a *Account) error {
r := &Registration{
Resource: ResNewReg,
Contact: a.Contact,
}
- _, err := c.post(c.Dir.NewReg, a, r)
- return r, err
-}
-
-// Agree to TOS
-func (c *Client) Agree(a *Account) (*Registration, error) {
- tos := c.Link["terms-of-service"]
- if tos == "" {
- return nil, errors.New("TOS agreed")
- }
- r := &Registration{
- Resource: ResRegister,
- Contact: a.Contact,
- Agreement: tos,
+ resp, err := c.post(c.Dir.NewReg, a, r)
+ switch resp.StatusCode {
+ case http.StatusConflict:
+ // Query Location
+ r.Resource = ResRegister
+ _, err = c.post(c.Location, a, r)
+ fallthrough
+ case http.StatusCreated:
+ // Agree to TOS
+ if tos := c.Link["terms-of-service"]; tos != "" {
+ r.Resource = ResRegister
+ r.Agreement = tos
+ _, err = c.post(c.Location, a, r)
+ }
}
- log.Println("TOS", tos)
- _, err := c.post(c.Location, a, r)
- return r, err
+ return err
}
-func (c *Client) Authorize(a *Account, domain string) (*Authorization, error) {
+func (c *Client) Authorize(a *Account, domain []string) error {
r := &Authorization{
Resource: ResNewAuthz,
Identifier: Identifier{
Type: IdentDNS,
- Value: domain,
+ Value: domain[0],
},
}
_, err := c.post(c.Dir.NewAuthz, a, r)
- return r, err
+ log.Println(r)
+ return err
}
func (c Client) String() string {