influxdb/mock/authorization.go

47 lines
912 B
Go
Raw Normal View History

package mock
import (
influxdb "github.com/influxdata/influxdb/v2"
)
// ensure Authorizer implements influxdb.Authorizer
var _ influxdb.Authorizer = (*Authorizer)(nil)
// Authorizer is an Authorizer for testing that can allow everything or use specific permissions
type Authorizer struct {
Permissions []influxdb.Permission
AllowAll bool
}
func NewMockAuthorizer(allowAll bool, permissions []influxdb.Permission) *Authorizer {
if allowAll {
return &Authorizer{
AllowAll: true,
}
}
return &Authorizer{
AllowAll: false,
Permissions: permissions,
}
}
func (a *Authorizer) PermissionSet() (influxdb.PermissionSet, error) {
if a.AllowAll {
return influxdb.OperPermissions(), nil
}
return a.Permissions, nil
}
func (a *Authorizer) Identifier() influxdb.ID {
return 1
}
func (a *Authorizer) GetUserID() influxdb.ID {
return 2
}
func (Authorizer) Kind() string {
return "mock"
}