Service => Service Auth

This commit is contained in:
Ben Toogood
2020-03-31 12:44:34 +01:00
parent 1222d076f2
commit d659e435c6
8 changed files with 106 additions and 26 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"time"
"github.com/micro/go-micro/v2/auth"
"github.com/micro/go-micro/v2/broker"
"github.com/micro/go-micro/v2/client/selector"
"github.com/micro/go-micro/v2/codec"
@@ -16,6 +17,7 @@ type Options struct {
ContentType string
// Plugged interfaces
Auth auth.Auth
Broker broker.Broker
Codecs map[string]codec.NewCodec
Registry registry.Registry
@@ -55,6 +57,8 @@ type CallOptions struct {
Retries int
// Request/Response timeout
RequestTimeout time.Duration
// Use the services own auth token
WithServicePrivileges bool
// Middleware for low level call func
CallWrappers []CallWrapper
@@ -99,6 +103,7 @@ func NewOptions(options ...Option) Options {
},
PoolSize: DefaultPoolSize,
PoolTTL: DefaultPoolTTL,
Auth: auth.DefaultAuth,
Broker: broker.DefaultBroker,
Selector: selector.DefaultSelector,
Registry: registry.DefaultRegistry,
@@ -119,6 +124,13 @@ func Broker(b broker.Broker) Option {
}
}
// Auth to be used when making a request
func Auth(a auth.Auth) Option {
return func(o *Options) {
o.Auth = a
}
}
// Codec to be used to encode/decode requests for a given content type
func Codec(contentType string, c codec.NewCodec) Option {
return func(o *Options) {
@@ -291,6 +303,14 @@ func WithDialTimeout(d time.Duration) CallOption {
}
}
// WithServicePrivileges is a CallOption which overrides the
// authorization header with the services own auth token
func WithServicePrivileges() CallOption {
return func(o *CallOptions) {
o.WithServicePrivileges = true
}
}
func WithMessageContentType(ct string) MessageOption {
return func(o *MessageOptions) {
o.ContentType = ct