forked from kyma-project/kyma
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class_converter.go
59 lines (50 loc) · 1.8 KB
/
class_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
50
51
52
53
54
55
56
57
58
59
package servicecatalog
import (
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/gqlschema"
"github.com/kyma-project/kyma/components/ui-api-layer/internal/resource"
"github.com/pkg/errors"
)
type classConverter struct{}
func (c *classConverter) ToGQL(in *v1beta1.ClusterServiceClass) (*gqlschema.ServiceClass, error) {
if in == nil {
return nil, nil
}
var externalMetadata map[string]interface{}
var err error
if in.Spec.ExternalMetadata != nil {
externalMetadata, err = resource.ExtractRawToMap("ExternalMetadata", in.Spec.ExternalMetadata.Raw)
if err != nil {
return nil, errors.Wrapf(err, "while converting externalMetadata for ServiceClass `%s`", in.Name)
}
}
providerDisplayName := resource.ToStringPtr(externalMetadata["providerDisplayName"])
imageUrl := resource.ToStringPtr(externalMetadata["imageUrl"])
documentationUrl := resource.ToStringPtr(externalMetadata["documentationUrl"])
displayName := resource.ToStringPtr(externalMetadata["displayName"])
class := gqlschema.ServiceClass{
Name: in.Name,
ExternalName: in.Spec.ExternalName,
DisplayName: displayName,
Description: in.Spec.Description,
ProviderDisplayName: providerDisplayName,
ImageUrl: imageUrl,
DocumentationUrl: documentationUrl,
CreationTimestamp: in.CreationTimestamp.Time,
Tags: in.Spec.Tags,
}
return &class, nil
}
func (c *classConverter) ToGQLs(in []*v1beta1.ClusterServiceClass) ([]gqlschema.ServiceClass, error) {
var result []gqlschema.ServiceClass
for _, u := range in {
converted, err := c.ToGQL(u)
if err != nil {
return nil, err
}
if converted != nil {
result = append(result, *converted)
}
}
return result, nil
}