Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add macaroon support to csclient.Params #82

Merged
merged 2 commits into from
Mar 30, 2016
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions csclient/csclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"gopkg.in/errgo.v1"
"gopkg.in/juju/charm.v6-unstable"
"gopkg.in/macaroon-bakery.v1/httpbakery"
"gopkg.in/macaroon.v1"

"gopkg.in/juju/charmrepo.v2-unstable/csclient/params"
)
Expand Down Expand Up @@ -73,6 +74,10 @@ type Params struct {
// If nil, no interaction will be allowed. This field
// is ignored if BakeryClient is provided.
VisitWebPage func(url *url.URL) error

// Auth holds a list of macaroons that will be added to the cookie jar of
// the HTTP Client that is used by this client.
Auth macaroon.Slice
}

type httpClient interface {
Expand All @@ -94,6 +99,15 @@ func New(p Params) *Client {
VisitWebPage: p.VisitWebPage,
}
}
if len(p.Auth) > 0 {
url, err := url.Parse(p.URL)
// A non-nil error here will get caught at request time when we try
// to parse the URL, and without a valid URL, the macaroons don't matter
// anyway.
if err == nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is bad. In discussion with Roger, it was decided that it was better to avoid a breaking change at this time (by forcing New to return an error), so we're just swallowing it for now, though as stated in the comment, the failure to parse would mean that requests will inevitably fail with the same parse failure, at which point, the use of macaroons is moot.

httpbakery.SetCookie(bclient.Jar, url, p.Auth)
}
}
return &Client{
bclient: bclient,
params: p,
Expand Down