Files
go-micro/auth/noop.go
T

92 lines
1.6 KiB
Go
Raw Normal View History

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 (
DefaultAuth = NewAuth()
2020-02-03 08:16:02 +00:00
)
func NewAuth(opts ...Option) Auth {
2020-12-12 19:06:43 +00:00
options := Options{}
for _, o := range opts {
o(&options)
}
return &noop{
opts: options,
}
2020-02-03 08:16:02 +00:00
}
2020-12-12 20:08:39 +00:00
func NewRules() Rules {
return new(noopRules)
}
2020-03-23 16:19:30 +00:00
type noop struct {
opts Options
}
2020-12-12 20:08:39 +00:00
type noopRules struct{}
2022-09-30 16:27:07 +02:00
// String returns the name of the implementation.
2020-03-23 16:19:30 +00:00
func (n *noop) String() string {
return "noop"
}
2022-09-30 16:27:07 +02:00
// Init the auth.
2020-03-23 16:19:30 +00:00
func (n *noop) Init(opts ...Option) {
for _, o := range opts {
o(&n.opts)
}
}
2022-09-30 16:27:07 +02:00
// Options set for auth.
2020-03-23 16:19:30 +00:00
func (n *noop) Options() Options {
return n.opts
}
2022-09-30 16:27:07 +02: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
return &Account{
ID: id,
Secret: options.Secret,
Metadata: options.Metadata,
Scopes: options.Scopes,
2020-05-22 12:24:37 +01:00
Issuer: n.Options().Namespace,
2020-02-26 13:42:32 +00:00
}, nil
}
2022-09-30 16:27:07 +02:00
// Grant access to a resource.
2020-12-12 20:08:39 +00:00
func (n *noopRules) Grant(rule *Rule) error {
2020-03-23 16:19:30 +00:00
return nil
}
2022-09-30 16:27:07 +02:00
// Revoke access to a resource.
2020-12-12 20:08:39 +00:00
func (n *noopRules) Revoke(rule *Rule) error {
2020-03-23 16:19:30 +00:00
return nil
}
2020-05-20 11:59:01 +01:00
// Rules used to verify requests
2022-09-30 16:27:07 +02:00
// Verify an account has access to a resource.
2020-12-12 20:08:39 +00:00
func (n *noopRules) Verify(acc *Account, res *Resource, opts ...VerifyOption) error {
return nil
2020-05-20 11:59:01 +01:00
}
2020-12-12 20:08:39 +00:00
func (n *noopRules) List(opts ...ListOption) ([]*Rule, error) {
return []*Rule{}, nil
2020-03-23 16:19:30 +00:00
}
2022-09-30 16:27:07 +02:00
// Inspect a token.
2020-03-23 16:19:30 +00:00
func (n *noop) Inspect(token string) (*Account, error) {
2020-05-22 12:40:34 +01:00
return &Account{ID: uuid.New().String(), Issuer: n.Options().Namespace}, nil
2020-03-23 16:19:30 +00:00
}
2022-09-30 16:27:07 +02: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-03 08:16:02 +00:00
}