mirror of
https://github.com/ceph/ceph-csi.git
synced 2024-11-14 10:20:20 +00:00
e5c5646963
Bumps [github.com/aws/aws-sdk-go-v2/service/sts](https://github.com/aws/aws-sdk-go-v2) from 1.16.13 to 1.16.17. - [Release notes](https://github.com/aws/aws-sdk-go-v2/releases) - [Changelog](https://github.com/aws/aws-sdk-go-v2/blob/main/CHANGELOG.md) - [Commits](https://github.com/aws/aws-sdk-go-v2/compare/v1.16.13...service/ram/v1.16.17) --- updated-dependencies: - dependency-name: github.com/aws/aws-sdk-go-v2/service/sts dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
51 lines
1.3 KiB
Go
51 lines
1.3 KiB
Go
package bearer
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// Token provides a type wrapping a bearer token and expiration metadata.
|
|
type Token struct {
|
|
Value string
|
|
|
|
CanExpire bool
|
|
Expires time.Time
|
|
}
|
|
|
|
// Expired returns if the token's Expires time is before or equal to the time
|
|
// provided. If CanExpires is false, Expired will always return false.
|
|
func (t Token) Expired(now time.Time) bool {
|
|
if !t.CanExpire {
|
|
return false
|
|
}
|
|
now = now.Round(0)
|
|
return now.Equal(t.Expires) || now.After(t.Expires)
|
|
}
|
|
|
|
// TokenProvider provides interface for retrieving bearer tokens.
|
|
type TokenProvider interface {
|
|
RetrieveBearerToken(context.Context) (Token, error)
|
|
}
|
|
|
|
// TokenProviderFunc provides a helper utility to wrap a function as a type
|
|
// that implements the TokenProvider interface.
|
|
type TokenProviderFunc func(context.Context) (Token, error)
|
|
|
|
// RetrieveBearerToken calls the wrapped function, returning the Token or
|
|
// error.
|
|
func (fn TokenProviderFunc) RetrieveBearerToken(ctx context.Context) (Token, error) {
|
|
return fn(ctx)
|
|
}
|
|
|
|
// StaticTokenProvider provides a utility for wrapping a static bearer token
|
|
// value within an implementation of a token provider.
|
|
type StaticTokenProvider struct {
|
|
Token Token
|
|
}
|
|
|
|
// RetrieveBearerToken returns the static token specified.
|
|
func (s StaticTokenProvider) RetrieveBearerToken(context.Context) (Token, error) {
|
|
return s.Token, nil
|
|
}
|