forked from IBM/ibmcloud-storage-volume-lib
/
authentication.go
35 lines (29 loc) · 1.07 KB
/
authentication.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*******************************************************************************
* IBM Confidential
* OCO Source Materials
* IBM Cloud Container Service, 5737-D43
* (C) Copyright IBM Corp. 2018, 2019 All Rights Reserved.
* The source code for this program is not published or otherwise divested of
* its trade secrets, irrespective of what has been deposited with
* the U.S. Copyright Office.
******************************************************************************/
package client
import (
"errors"
)
// ErrAuthenticationRequired is returned if a request is made before an authentication
// token has been provided to the client
var ErrAuthenticationRequired = errors.New("Authentication token required")
type authenticationHandler struct {
authToken string
resourceGroup string
}
// Before is called before each request
func (a *authenticationHandler) Before(request *Request) error {
request.resourceGroup = a.resourceGroup
if a.authToken == "" {
return ErrAuthenticationRequired
}
request.headers.Set("Authorization", "Bearer "+a.authToken)
return nil
}