-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathauthenticator.go
More file actions
40 lines (32 loc) · 824 Bytes
/
authenticator.go
File metadata and controls
40 lines (32 loc) · 824 Bytes
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 sink
import (
"os"
"github.com/streamingfast/substreams/client"
)
type authenticator struct {
apiKeyEnvVar string
apiTokenEnvVar string
}
func newAuthenticator(apiKeyEnvVar string, apiTokenEnvVar string) *authenticator {
return &authenticator{
apiKeyEnvVar: apiKeyEnvVar,
apiTokenEnvVar: apiTokenEnvVar,
}
}
func (a *authenticator) GetApiKey() string {
return a.apiKeyEnvVar
}
func (a *authenticator) GetApiToken() string {
return a.apiTokenEnvVar
}
func (a *authenticator) GetTokenAndType() (authToken string, authType client.AuthType) {
apiKeyFromEnv := os.Getenv(a.apiKeyEnvVar)
if apiKeyFromEnv != "" {
return apiKeyFromEnv, client.ApiKey
}
apiTokenFromEnv := os.Getenv(a.apiTokenEnvVar)
if apiTokenFromEnv != "" {
return apiTokenFromEnv, client.JWT
}
return "", client.None
}