2020-02-03 10:16:02 +02:00
|
|
|
package auth
|
|
|
|
|
2020-02-26 15:42:32 +02:00
|
|
|
import (
|
2020-03-23 18:19:30 +02:00
|
|
|
"github.com/google/uuid"
|
2020-02-26 15:42:32 +02:00
|
|
|
)
|
|
|
|
|
2020-02-03 10:16:02 +02:00
|
|
|
var (
|
2020-02-24 17:07:27 +02:00
|
|
|
DefaultAuth = NewAuth()
|
2020-02-03 10:16:02 +02:00
|
|
|
)
|
|
|
|
|
2020-02-24 17:07:27 +02:00
|
|
|
func NewAuth(opts ...Option) Auth {
|
2020-03-23 18:19:30 +02:00
|
|
|
return &noop{}
|
2020-02-03 10:16:02 +02:00
|
|
|
}
|
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
type noop struct {
|
2020-02-26 00:15:44 +02:00
|
|
|
opts Options
|
|
|
|
}
|
2020-02-03 10:16:02 +02:00
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// String returns the name of the implementation
|
|
|
|
func (n *noop) String() string {
|
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init the auth
|
|
|
|
func (n *noop) Init(opts ...Option) {
|
2020-02-26 00:15:44 +02:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
2020-02-03 10:16:02 +02:00
|
|
|
}
|
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Options set for auth
|
|
|
|
func (n *noop) Options() Options {
|
2020-02-26 00:15:44 +02:00
|
|
|
return n.opts
|
2020-02-10 10:26:28 +02:00
|
|
|
}
|
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Generate a new account
|
|
|
|
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
|
|
|
options := NewGenerateOptions(opts...)
|
2020-02-26 15:42:32 +02:00
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
return &Account{
|
|
|
|
ID: id,
|
|
|
|
Roles: options.Roles,
|
|
|
|
Metadata: options.Metadata,
|
|
|
|
}, nil
|
2020-02-03 10:16:02 +02:00
|
|
|
}
|
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Grant access to a resource
|
|
|
|
func (n *noop) Grant(role string, res *Resource) error {
|
2020-02-03 10:16:02 +02:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Revoke access to a resource
|
|
|
|
func (n *noop) Revoke(role string, res *Resource) error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-02-26 15:42:32 +02:00
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Verify an account has access to a resource
|
|
|
|
func (n *noop) Verify(acc *Account, res *Resource) error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-02-26 15:42:32 +02:00
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Inspect a token
|
|
|
|
func (n *noop) Inspect(token string) (*Account, error) {
|
|
|
|
return &Account{ID: uuid.New().String()}, nil
|
2020-02-03 10:16:02 +02:00
|
|
|
}
|
2020-02-24 17:07:27 +02:00
|
|
|
|
2020-03-23 18:19:30 +02:00
|
|
|
// Refresh an account using a secret
|
|
|
|
func (n *noop) Refresh(secret string, opts ...RefreshOption) (*Token, error) {
|
|
|
|
return &Token{}, nil
|
2020-02-24 17:07:27 +02:00
|
|
|
}
|