2020-09-10 00:06:29 +03:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/google/uuid"
|
|
|
|
)
|
|
|
|
|
2020-12-08 00:38:37 +03:00
|
|
|
type noopAuth struct {
|
2020-09-10 00:06:29 +03:00
|
|
|
opts Options
|
|
|
|
}
|
|
|
|
|
|
|
|
// String returns the name of the implementation
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) String() string {
|
2020-09-10 00:06:29 +03:00
|
|
|
return "noop"
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init the auth
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Init(opts ...Option) {
|
2020-09-10 00:06:29 +03:00
|
|
|
for _, o := range opts {
|
|
|
|
o(&n.opts)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Options set for auth
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Options() Options {
|
2020-09-10 00:06:29 +03:00
|
|
|
return n.opts
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate a new account
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Generate(id string, opts ...GenerateOption) (*Account, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
options := NewGenerateOptions(opts...)
|
|
|
|
|
|
|
|
return &Account{
|
|
|
|
ID: id,
|
|
|
|
Secret: options.Secret,
|
|
|
|
Metadata: options.Metadata,
|
|
|
|
Scopes: options.Scopes,
|
|
|
|
Issuer: n.Options().Issuer,
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Grant access to a resource
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Grant(rule *Rule) error {
|
2020-09-10 00:06:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Revoke access to a resource
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Revoke(rule *Rule) error {
|
2020-09-10 00:06:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Rules used to verify requests
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Rules(opts ...RulesOption) ([]*Rule, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
return []*Rule{}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Verify an account has access to a resource
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
|
2020-09-10 00:06:29 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Inspect a token
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Inspect(token string) (*Account, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
uid, err := uuid.NewRandom()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &Account{ID: uid.String(), Issuer: n.Options().Issuer}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Token generation using an account id and secret
|
2020-12-08 00:38:37 +03:00
|
|
|
func (n *noopAuth) Token(opts ...TokenOption) (*Token, error) {
|
2020-09-10 00:06:29 +03:00
|
|
|
return &Token{}, nil
|
|
|
|
}
|
2020-12-08 00:38:37 +03:00
|
|
|
|
|
|
|
// NewAuth returns new noop auth
|
|
|
|
func NewAuth(opts ...Option) Auth {
|
|
|
|
return &noopAuth{opts: NewOptions(opts...)}
|
|
|
|
}
|