authZ: more fixes
- fix naming and formatting - provide more context when erroring auth - do not capitalize errors - fix wrong documentation - remove ugly remoteError{} Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
7051dc2661
commit
bc21007445
3 changed files with 40 additions and 50 deletions
|
@ -20,15 +20,6 @@ const (
|
|||
defaultTimeOut = 30
|
||||
)
|
||||
|
||||
type remoteError struct {
|
||||
method string
|
||||
err string
|
||||
}
|
||||
|
||||
func (e *remoteError) Error() string {
|
||||
return fmt.Sprintf("Plugin Error: %s, %s", e.err, e.method)
|
||||
}
|
||||
|
||||
// NewClient creates a new plugin client (http).
|
||||
func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) {
|
||||
tr := &http.Transport{}
|
||||
|
@ -133,7 +124,7 @@ func (c *Client) callWithRetry(serviceMethod string, data io.Reader, retry bool)
|
|||
if resp.StatusCode != http.StatusOK {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, &remoteError{method: serviceMethod, err: err.Error()}
|
||||
return nil, fmt.Errorf("%s: %s", serviceMethod, err)
|
||||
}
|
||||
|
||||
// Plugins' Response(s) should have an Err field indicating what went
|
||||
|
@ -144,13 +135,13 @@ func (c *Client) callWithRetry(serviceMethod string, data io.Reader, retry bool)
|
|||
}
|
||||
remoteErr := responseErr{}
|
||||
if err := json.Unmarshal(b, &remoteErr); err != nil {
|
||||
return nil, &remoteError{method: serviceMethod, err: err.Error()}
|
||||
return nil, fmt.Errorf("%s: %s", serviceMethod, err)
|
||||
}
|
||||
if remoteErr.Err != "" {
|
||||
return nil, &remoteError{method: serviceMethod, err: remoteErr.Err}
|
||||
return nil, fmt.Errorf("%s: %s", serviceMethod, remoteErr.Err)
|
||||
}
|
||||
// old way...
|
||||
return nil, &remoteError{method: serviceMethod, err: string(b)}
|
||||
return nil, fmt.Errorf("%s: %s", serviceMethod, string(b))
|
||||
}
|
||||
return resp.Body, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue