-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathstatic_token.go
40 lines (35 loc) · 1.08 KB
/
static_token.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
package scalingo
import (
"context"
)
// StaticTokenGenerator is an implementation of TokenGenerator which always return the same token.
// This token is provided to the constructor. The TokenGenerator is used by the Client to
// authenticate to the Scalingo API.
//
// Usage:
//
// t := GetStaticTokenGenerator("my-token")
// client := NewClient(ClientConfig{
// TokenGenerator: t,
// })
//
// Any subsequent calls to the Scalingo API will use this token to authenticate.
type StaticTokenGenerator struct {
token string
client *Client
}
// NewStaticTokenGenerator returns a new StaticTokenGenerator. The only argument is the token that
// will always be returned by this generator.
func NewStaticTokenGenerator(token string) *StaticTokenGenerator {
return &StaticTokenGenerator{
token: token,
}
}
// GetAccessToken always returns the configured token.
func (t *StaticTokenGenerator) GetAccessToken(context.Context) (string, error) {
return t.token, nil
}
// SetClient sets the client attribute of this token generator.
func (t *StaticTokenGenerator) SetClient(c *Client) {
t.client = c
}