2020-10-30 17:06:34 +00:00
|
|
|
package influxdb
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform/errors"
|
|
|
|
)
|
2020-10-30 17:06:34 +00:00
|
|
|
|
|
|
|
var (
|
|
|
|
// ErrCredentialsUnauthorized is the error returned when CredentialsV1 cannot be
|
|
|
|
// authorized.
|
2021-03-30 18:10:02 +00:00
|
|
|
ErrCredentialsUnauthorized = &errors.Error{
|
|
|
|
Code: errors.EUnauthorized,
|
2020-10-30 17:06:34 +00:00
|
|
|
Msg: "Unauthorized",
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// SchemeV1 is an enumeration of supported authorization types
|
|
|
|
type SchemeV1 string
|
|
|
|
|
|
|
|
const (
|
|
|
|
// SchemeV1Basic indicates the credentials came from an Authorization header using the BASIC scheme
|
|
|
|
SchemeV1Basic SchemeV1 = "basic"
|
|
|
|
|
2020-10-30 18:12:36 +00:00
|
|
|
// SchemeV1Token indicates the credentials came from an Authorization header using the Token scheme
|
2020-10-30 17:06:34 +00:00
|
|
|
SchemeV1Token SchemeV1 = "token"
|
|
|
|
|
2020-10-30 18:12:36 +00:00
|
|
|
// SchemeV1URL indicates the credentials came from the u and p query parameters
|
2020-10-30 17:06:34 +00:00
|
|
|
SchemeV1URL SchemeV1 = "url"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CredentialsV1 encapsulates the required credentials to authorize a v1 HTTP request.
|
|
|
|
type CredentialsV1 struct {
|
|
|
|
Scheme SchemeV1
|
|
|
|
Username string
|
|
|
|
Token string
|
|
|
|
}
|
|
|
|
|
|
|
|
type AuthorizerV1 interface {
|
|
|
|
Authorize(ctx context.Context, v1 CredentialsV1) (*Authorization, error)
|
|
|
|
}
|