/
resource.go
54 lines (41 loc) · 1.25 KB
/
resource.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
package tenantclients
import (
"context"
infrastructurev1alpha3 "github.com/giantswarm/apiextensions/v6/pkg/apis/infrastructure/v1alpha3"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/giantswarm/tenantcluster/v6/pkg/tenantcluster"
)
const (
Name = "tenantclients"
)
type Config struct {
Logger micrologger.Logger
Tenant tenantcluster.Interface
ToClusterFunc func(ctx context.Context, v interface{}) (infrastructurev1alpha3.AWSCluster, error)
}
type Resource struct {
logger micrologger.Logger
tenant tenantcluster.Interface
toClusterFunc func(ctx context.Context, v interface{}) (infrastructurev1alpha3.AWSCluster, error)
}
func New(config Config) (*Resource, error) {
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.Tenant == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Tenant must not be empty", config)
}
if config.ToClusterFunc == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.ToClusterFunc must not be empty", config)
}
r := &Resource{
logger: config.Logger,
tenant: config.Tenant,
toClusterFunc: config.ToClusterFunc,
}
return r, nil
}
func (r *Resource) Name() string {
return Name
}