From ea51a23c63b779e190256dfb4e72573f0047dac5 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 10 Dec 2015 22:25:35 +0100 Subject: Add authz stub --- client.go | 19 +++++++++++++++++-- cmd/x/main.go | 20 ++++++++++++++------ messages.go | 4 ++-- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/client.go b/client.go index d1705e7..a046f84 100644 --- a/client.go +++ b/client.go @@ -135,6 +135,21 @@ func (c *Client) Register(a *Account) error { return err } -func (c *Client) Authorize(a *Account, d []string) error { - return nil +func (c *Client) Authorize(a *Account, domain string) error { + az := Authorization{ + Resource: ResNewAuthz, + Identifier: Identifier{ + Type: IdentDNS, + Value: domain, + }, + } + resp, err := c.post(a, c.Dir.NewAuthz, az) + if err != nil { + return err + } + defer resp.Body.Close() + ae := AuthorizationResp{} + err = json.NewDecoder(resp.Body).Decode(&ae) + log.Println(ae) + return err } diff --git a/cmd/x/main.go b/cmd/x/main.go index 6a7cae7..2ae8255 100644 --- a/cmd/x/main.go +++ b/cmd/x/main.go @@ -7,11 +7,6 @@ import ( ) func main() { - c, err := acme.NewClient(acme.LES) - if err != nil { - log.Fatal(err) - } - log.Printf("%+v\n", c) /* a, err := acme.NewAccount("another@example.com", acme.KeySize) @@ -26,7 +21,20 @@ func main() { } log.Printf("%+v\n", a) - err = a.SaveAccount(".acme/account.json") + /* + err = a.SaveAccount(".acme/account.json") + if err != nil { + log.Fatal(err) + } + */ + + c, err := acme.NewClient(acme.LES) + if err != nil { + log.Fatal(err) + } + log.Printf("%+v\n", c) + + err = c.Authorize(a, "example.com") if err != nil { log.Fatal(err) } diff --git a/messages.go b/messages.go index c270f32..4ddaa42 100644 --- a/messages.go +++ b/messages.go @@ -64,8 +64,8 @@ type AuthorizationResp struct { // Identifier ... type Identifier struct { - Type string `json:"type"` // dns - Value string `json:"value"` // example.com + Type IdentType `json:"type"` // dns + Value string `json:"value"` // example.com } // Challege ... -- cgit v1.2.3