Files
kubernetes/Godeps/_workspace/src/github.com/rackspace/gophercloud/reauth.go
Angus Lees 9bed117119 Add github.com/rackspace/gophercloud package as a dependency.
Note this also pulls in:
github.com/kr/text
github.com/mitchellh/mapstructure
github.com/racker/perigee
github.com/tonnerre/golang-pretty
2014-10-15 14:09:27 +11:00

37 lines
1.1 KiB
Go

package gophercloud
import (
"github.com/racker/perigee"
)
// WithReauth wraps a Perigee request fragment with logic to perform re-authentication
// if it's deemed necessary.
//
// Do not confuse this function with WithReauth()! Although they work together to support reauthentication,
// WithReauth() actually contains the decision-making logic to determine when to perform a reauth,
// while WithReauthHandler() is used to configure what a reauth actually entails.
func (c *Context) WithReauth(ap AccessProvider, f func() error) error {
err := f()
cause, ok := err.(*perigee.UnexpectedResponseCodeError)
if ok && cause.Actual == 401 {
err = c.reauthHandler(ap)
if err == nil {
err = f()
}
}
return err
}
// This is like WithReauth above but returns a perigee Response object
func (c *Context) ResponseWithReauth(ap AccessProvider, f func() (*perigee.Response, error)) (*perigee.Response, error) {
response, err := f()
cause, ok := err.(*perigee.UnexpectedResponseCodeError)
if ok && cause.Actual == 401 {
err = c.reauthHandler(ap)
if err == nil {
response, err = f()
}
}
return response, err
}