/
credentials.go
54 lines (45 loc) · 1.98 KB
/
credentials.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
43
44
45
46
47
48
49
50
51
52
53
54
package credentials
import (
"context"
"github.com/ydb-platform/ydb-go-sdk/v3/internal/credentials"
)
// Credentials is an interface of YDB credentials required for connect with YDB
type Credentials interface {
// Token must return actual token or error
Token(ctx context.Context) (string, error)
}
// NewAccessTokenCredentials makes access token credentials object
// Passed options redefines default values of credentials object internal fields
func NewAccessTokenCredentials(
accessToken string, opts ...credentials.AccessTokenCredentialsOption,
) *credentials.AccessToken {
return credentials.NewAccessTokenCredentials(accessToken, opts...)
}
// NewAnonymousCredentials makes anonymous credentials object
// Passed options redefines default values of credentials object internal fields
func NewAnonymousCredentials(
opts ...credentials.AnonymousCredentialsOption,
) *credentials.Anonymous {
return credentials.NewAnonymousCredentials(opts...)
}
// NewStaticCredentials makes static credentials object
func NewStaticCredentials(
user, password, authEndpoint string, opts ...credentials.StaticCredentialsOption,
) *credentials.Static {
return credentials.NewStaticCredentials(user, password, authEndpoint, opts...)
}
// NewOauth2TokenExchangeCredentials makes OAuth 2.0 token exchange protocol credentials object
// https://www.rfc-editor.org/rfc/rfc8693
func NewOauth2TokenExchangeCredentials(
opts ...credentials.Oauth2TokenExchangeCredentialsOption,
) (Credentials, error) {
return credentials.NewOauth2TokenExchangeCredentials(opts...)
}
// NewJWTTokenSource makes JWT token source for OAuth 2.0 token exchange credentials
func NewJWTTokenSource(opts ...credentials.JWTTokenSourceOption) (credentials.TokenSource, error) {
return credentials.NewJWTTokenSource(opts...)
}
// NewFixedTokenSource makes fixed token source for OAuth 2.0 token exchange credentials
func NewFixedTokenSource(token, tokenType string) credentials.TokenSource {
return credentials.NewFixedTokenSource(token, tokenType)
}