forked from kyma-project/kyma
/
bind.go
38 lines (30 loc) · 1004 Bytes
/
bind.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
package broker
import (
"context"
"fmt"
"github.com/pkg/errors"
osb "github.com/pmorie/go-open-service-broker-client/v2"
"github.com/kyma-project/kyma/components/helm-broker/internal"
)
type bindService struct {
instanceBindDataGetter instanceBindDataGetter
}
func (svc *bindService) Bind(ctx context.Context, osbCtx osbContext, req *osb.BindRequest) (*osb.BindResponse, error) {
if len(req.Parameters) > 0 {
return nil, fmt.Errorf("helm-broker does not support configuration options for the service binding")
}
out, err := svc.instanceBindDataGetter.Get(internal.InstanceID(req.InstanceID))
if err != nil {
return nil, errors.Wrapf(err, "while getting bind data from storage for instance id: %q", req.InstanceID)
}
return &osb.BindResponse{
Credentials: svc.dtoFromModel(out.Credentials),
}, nil
}
func (*bindService) dtoFromModel(in internal.InstanceCredentials) map[string]interface{} {
dto := map[string]interface{}{}
for k, v := range in {
dto[k] = v
}
return dto
}