-
Notifications
You must be signed in to change notification settings - Fork 84
/
executor_provider.go
55 lines (47 loc) · 2 KB
/
executor_provider.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package accessstrategy
import (
"context"
"github.com/kyma-incubator/compass/components/director/pkg/credloader"
)
// ExecutorProvider defines an interface for access strategy executor provider
//
//go:generate mockery --name=ExecutorProvider --output=automock --outpkg=automock --case=underscore --disable-version-string
type ExecutorProvider interface {
Provide(accessStrategyType Type) (Executor, error)
}
// Provider is responsible to provides an access strategy executors
type Provider struct {
executors map[Type]Executor
}
// NewExecutorProvider returns a new access strategy executor provider based on type <-> executor mapping
func NewExecutorProvider(executors map[Type]Executor) *Provider {
return &Provider{
executors: executors,
}
}
// NewDefaultExecutorProvider returns a new access strategy executor provider with the default static type <-> executor mapping
func NewDefaultExecutorProvider(certCache credloader.CertCache, externalClientCertSecretName string) *Provider {
return &Provider{
executors: map[Type]Executor{
OpenAccessStrategy: &openAccessStrategyExecutor{},
CMPmTLSAccessStrategy: NewCMPmTLSAccessStrategyExecutor(certCache, nil, externalClientCertSecretName),
},
}
}
// NewExecutorProviderWithTenant returns a new access strategy executor provider by given tenant provider function
func NewExecutorProviderWithTenant(certCache credloader.CertCache, tenantProviderFunc func(ctx context.Context) (string, error), externalClientCertSecretName string) *Provider {
return &Provider{
executors: map[Type]Executor{
OpenAccessStrategy: &openAccessStrategyExecutor{},
CMPmTLSAccessStrategy: NewCMPmTLSAccessStrategyExecutor(certCache, tenantProviderFunc, externalClientCertSecretName),
},
}
}
// Provide provides an executor for a given access strategy if supported, UnsupportedErr otherwise
func (p *Provider) Provide(accessStrategyType Type) (Executor, error) {
executor, ok := p.executors[accessStrategyType]
if !ok {
return nil, UnsupportedErr
}
return executor, nil
}