forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
binding_converter.go
49 lines (41 loc) · 1.34 KB
/
binding_converter.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
package servicecatalog
import (
api "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/domain/servicecatalog/status"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/gqlschema"
)
type serviceBindingConverter struct {
extractor status.BindingExtractor
}
func (c *serviceBindingConverter) ToCreateOutputGQL(in *api.ServiceBinding) *gqlschema.CreateServiceBindingOutput {
if in == nil {
return nil
}
return &gqlschema.CreateServiceBindingOutput{
Name: in.Name,
Environment: in.Namespace,
ServiceInstanceName: in.Spec.ServiceInstanceRef.Name,
}
}
func (c *serviceBindingConverter) ToGQL(in *api.ServiceBinding) *gqlschema.ServiceBinding {
if in == nil {
return nil
}
return &gqlschema.ServiceBinding{
Name: in.Name,
ServiceInstanceName: in.Spec.ServiceInstanceRef.Name,
Environment: in.Namespace,
SecretName: in.Spec.SecretName,
Status: c.extractor.Status(in.Status.Conditions),
}
}
func (c *serviceBindingConverter) ToGQLs(in []*api.ServiceBinding) []gqlschema.ServiceBinding {
var result []gqlschema.ServiceBinding
for _, item := range in {
converted := c.ToGQL(item)
if converted != nil {
result = append(result, *converted)
}
}
return result
}