-
Notifications
You must be signed in to change notification settings - Fork 13
/
rpcauth.go
42 lines (35 loc) · 982 Bytes
/
rpcauth.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
36
37
38
39
40
41
42
package watchmanager
import (
"context"
)
type rpcCredential interface {
GetRequestMetadata(ctx context.Context, in ...string) (map[string]string, error)
RequireTransportSecurity() bool
}
type rpcAuth struct {
tenantID string
tokenGetter TokenGetter
}
// newRPCAuth - Create a new RPC authenticator which uses the token getter to fetch token
func newRPCAuth(tenantID string, tokenGetter TokenGetter) rpcCredential {
auth := rpcAuth{
tenantID: tenantID,
tokenGetter: tokenGetter,
}
return auth
}
// GetRequestMetadata - sets the http header prior to transport
func (t rpcAuth) GetRequestMetadata(_ context.Context, _ ...string) (map[string]string, error) {
token, err := t.tokenGetter()
if err != nil {
return nil, err
}
return map[string]string{
"x-axway-tenant-id": t.tenantID,
"authorization": "Bearer " + token,
}, nil
}
// RequireTransportSecurity - leave as false for now
func (rpcAuth) RequireTransportSecurity() bool {
return false
}