From bcdd79320b8a0041a5b123eaa04b329a572ed820 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 4 Oct 2017 21:26:40 +0100 Subject: [PATCH] rest: Add SetUserPass to create Authorization header --- rest/rest.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/rest/rest.go b/rest/rest.go index 812777234..e536f0b89 100644 --- a/rest/rest.go +++ b/rest/rest.go @@ -91,6 +91,15 @@ func (api *Client) SetSigner(signer SignerFn) *Client { return api } +// SetUserPass creates an Authorization header for all requests with +// the UserName and Password passed in +func (api *Client) SetUserPass(UserName, Password string) *Client { + req, _ := http.NewRequest("GET", "http://example.com", nil) + req.SetBasicAuth(UserName, Password) + api.SetHeader("Authorization", req.Header.Get("Authorization")) + return api +} + // Opts contains parameters for Call, CallJSON etc type Opts struct { Method string // GET, POST etc