auth

Paddy 2014-10-22 Parent:0f80a3e391b8 Child:a5987795707e

55:cfab12566289 Browse Files

Update Context with new CheckEndpoint and CountEndpoints. Update the Context.CheckEndpoint method to pass through the new "strict" parameter that controls how URLs are checked for validation. Add a Context.CountEndpoints method to safely access the number of endpoints in stored for the client in the associent ClientStore. Finally, remove the error return from Context.Render, as we'd only ever want to log that, anyways. So we may as well just log it from the central function.

context.go

     1.1 --- a/context.go	Wed Oct 22 00:26:39 2014 -0400
     1.2 +++ b/context.go	Wed Oct 22 00:29:05 2014 -0400
     1.3 @@ -4,6 +4,7 @@
     1.4  	"errors"
     1.5  	"html/template"
     1.6  	"io"
     1.7 +	"log"
     1.8  	"time"
     1.9  
    1.10  	"code.secondbit.org/uuid"
    1.11 @@ -21,11 +22,14 @@
    1.12  	tokens   TokenStore
    1.13  }
    1.14  
    1.15 -func (c Context) Render(out io.Writer, name string, data interface{}) error {
    1.16 +func (c Context) Render(out io.Writer, name string, data interface{}) {
    1.17  	if c.template == nil {
    1.18 -		return ErrNoTemplate
    1.19 +		log.Println(ErrNoTemplate)
    1.20  	}
    1.21 -	return c.template.ExecuteTemplate(out, name, data)
    1.22 +	err := c.template.ExecuteTemplate(out, name, data)
    1.23 +	if err != nil {
    1.24 +		log.Println("Error executing template", name, ":", err)
    1.25 +	}
    1.26  }
    1.27  
    1.28  func (c Context) GetClient(id uuid.ID) (Client, error) {
    1.29 @@ -77,11 +81,11 @@
    1.30  	return c.clients.RemoveEndpoint(client, endpoint)
    1.31  }
    1.32  
    1.33 -func (c Context) CheckEndpoint(client uuid.ID, URI string) (bool, error) {
    1.34 +func (c Context) CheckEndpoint(client uuid.ID, URI string, strict bool) (bool, error) {
    1.35  	if c.clients == nil {
    1.36  		return false, ErrNoClientStore
    1.37  	}
    1.38 -	return c.clients.CheckEndpoint(client, URI)
    1.39 +	return c.clients.CheckEndpoint(client, URI, strict)
    1.40  }
    1.41  
    1.42  func (c Context) ListEndpoints(client uuid.ID, num, offset int) ([]Endpoint, error) {
    1.43 @@ -91,6 +95,13 @@
    1.44  	return c.clients.ListEndpoints(client, num, offset)
    1.45  }
    1.46  
    1.47 +func (c Context) CountEndpoints(client uuid.ID) (int64, error) {
    1.48 +	if c.clients == nil {
    1.49 +		return 0, ErrNoClientStore
    1.50 +	}
    1.51 +	return c.clients.CountEndpoints(client)
    1.52 +}
    1.53 +
    1.54  func (c Context) GetGrant(code string) (Grant, error) {
    1.55  	if c.grants == nil {
    1.56  		return Grant{}, ErrNoGrantStore