2020-02-03 08:16:02 +00:00
|
|
|
package auth
|
|
|
|
|
2020-02-26 13:42:32 +00:00
|
|
|
import (
|
2020-03-23 16:19:30 +00:00
|
|
|
"github.com/google/uuid"
|
2020-02-26 13:42:32 +00:00
|
|
|
)
|
|
|
|
|
2020-02-03 08:16:02 +00:00
|
|
|
var (
|
2020-02-24 15:07:27 +00:00
|
|
|
DefaultAuth = NewAuth()
|
2020-02-03 08:16:02 +00:00
|
|
|
)
|
|
|
|
|
2020-02-24 15:07:27 +00:00
|
|
|
func NewAuth(opts ...Option) Auth {
|
2020-03-23 16:19:30 +00:00
|
|
|
return &noop{}
|
2020-02-03 08:16:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
type noop struct {
|
2020-02-25 22:15:44 +00:00
|
|
|
opts Options
|
|
|
|
}
|
2020-02-03 08:16:02 +00:00
|
|
|
|
2020-03-23 16:19:30 +00: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-25 22:15:44 +00:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
2020-02-03 08:16:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
// Options set for auth
|
|
|
|
func (n *noop) Options() Options {
|
2020-02-25 22:15:44 +00:00
|
|
|
return n.opts
|
2020-02-10 08:26:28 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
// Generate a new account
|
2020-04-01 17:20:02 +01:00
|
|
|
func (n *noop) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
2020-03-23 16:19:30 +00:00
|
|
|
options := NewGenerateOptions(opts...)
|
2020-02-26 13:42:32 +00:00
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
return &Account{
|
2020-04-01 14:25:00 +01:00
|
|
|
ID: id,
|
|
|
|
Roles: options.Roles,
|
2020-04-01 17:22:01 +01:00
|
|
|
Secret: options.Secret,
|
2020-04-01 14:25:00 +01:00
|
|
|
Metadata: options.Metadata,
|
2020-03-23 16:19:30 +00:00
|
|
|
}, nil
|
2020-02-03 08:16:02 +00:00
|
|
|
}
|
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
// Grant access to a resource
|
|
|
|
func (n *noop) Grant(role string, res *Resource) error {
|
2020-02-03 08:16:02 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
// Revoke access to a resource
|
|
|
|
func (n *noop) Revoke(role string, res *Resource) error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-02-26 13:42:32 +00:00
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
// Verify an account has access to a resource
|
|
|
|
func (n *noop) Verify(acc *Account, res *Resource) error {
|
|
|
|
return nil
|
|
|
|
}
|
2020-02-26 13:42:32 +00:00
|
|
|
|
2020-03-23 16:19:30 +00:00
|
|
|
// Inspect a token
|
|
|
|
func (n *noop) Inspect(token string) (*Account, error) {
|
2020-03-27 09:46:17 +00:00
|
|
|
return &Account{
|
2020-03-27 09:54:29 +00:00
|
|
|
ID: uuid.New().String(),
|
2020-03-27 09:46:17 +00:00
|
|
|
}, nil
|
2020-02-03 08:16:02 +00:00
|
|
|
}
|
2020-02-24 15:07:27 +00:00
|
|
|
|
2020-03-31 10:06:13 +01:00
|
|
|
// Token generation using an account id and secret
|
2020-04-01 14:25:00 +01:00
|
|
|
func (n *noop) Token(opts ...TokenOption) (*Token, error) {
|
2020-03-23 16:19:30 +00:00
|
|
|
return &Token{}, nil
|
2020-02-24 15:07:27 +00:00
|
|
|
}
|