diff --git a/.gitignore b/.gitignore index c68d56062..dbff347d9 100644 --- a/.gitignore +++ b/.gitignore @@ -221,7 +221,6 @@ scripts/run.bat scripts/**/*.js scripts/**/*.js.map coverage/ -internal/ **/.DS_Store .settings **/.vs diff --git a/internal/api/requests/converters.go b/internal/api/requests/converters.go new file mode 100644 index 000000000..550e08f20 --- /dev/null +++ b/internal/api/requests/converters.go @@ -0,0 +1,18 @@ +package requests + +import ( + "github.com/kyma-project/btp-manager/internal/service-manager/types/requests" +) + +func CreateServiceBindingVM(request CreateServiceBinding) requests.CreateServiceBindingRequestPayload { + payload := requests.CreateServiceBindingRequestPayload{ + Name: request.Name, + ServiceInstanceID: request.ServiceInstanceId, + Parameters: []byte(request.Parameters), + Labels: map[string][]string{}, + } + payload.Labels["_clusterid"] = append(payload.Labels["_clusterid"], payload.Name) + payload.Labels["_namespace"] = append(payload.Labels["_namespace"], request.Namespace) + payload.Labels["_k8sname"] = append(payload.Labels["_k8sname"], request.Name) + return payload +} diff --git a/internal/api/requests/requests.go b/internal/api/requests/requests.go new file mode 100644 index 000000000..dfc40abe3 --- /dev/null +++ b/internal/api/requests/requests.go @@ -0,0 +1,8 @@ +package requests + +type CreateServiceBinding struct { + Name string `json:"name"` + Namespace string `json:"namespace"` + ServiceInstanceId string `json:"serviceInstanceId"` + Parameters string `json:"parameters"` +} diff --git a/internal/api/responses/converters.go b/internal/api/responses/converters.go new file mode 100644 index 000000000..082435c20 --- /dev/null +++ b/internal/api/responses/converters.go @@ -0,0 +1,83 @@ +package responses + +import ( + "github.com/kyma-project/btp-manager/internal/service-manager/types" + v1 "k8s.io/api/core/v1" +) + +func ToSecretVM(list v1.SecretList) Secrets { + secrets := Secrets{ + Items: []Secret{}, + } + for _, secret := range list.Items { + secrets.Items = append( + secrets.Items, Secret{ + Name: secret.Name, + Namespace: secret.Namespace, + }, + ) + } + return secrets +} + +func ToServiceOfferingsVM(offerings *types.ServiceOfferings) ServiceOfferings { + toReturn := ServiceOfferings{ + NumItems: len(offerings.ServiceOfferings), + Items: []ServiceOffering{}, + } + + for _, offering := range offerings.ServiceOfferings { + imageUrl, _ := offering.MetadataValueByFieldName(types.ServiceOfferingImageUrl) + displayName, _ := offering.MetadataValueByFieldName(types.ServiceOfferingDisplayName) + supportUrl, _ := offering.MetadataValueByFieldName(types.ServiceOfferingSupportURL) + documentationUrl, _ := offering.MetadataValueByFieldName(types.ServiceOfferingDocumentationUrl) + offering := ServiceOffering{ + ID: offering.ID, + Description: offering.Description, + CatalogID: offering.CatalogID, + CatalogName: offering.CatalogName, + Metadata: ServiceOfferingMetadata{ + ImageUrl: imageUrl, + DisplayName: displayName, + SupportUrl: supportUrl, + DocumentationUrl: documentationUrl, + }, + } + toReturn.Items = append(toReturn.Items, offering) + } + return toReturn +} + +func ToServiceOfferingDetailsVM(details *types.ServiceOfferingDetails) ServiceOfferingDetails { + toReturn := ServiceOfferingDetails{ + Plans: []ServiceOfferingPlan{}, + } + + toReturn.LongDescription, _ = details.MetadataValueByFieldName(types.ServiceOfferingLongDescription) + + for _, plan := range details.ServicePlans.ServicePlans { + toReturn.Plans = append(toReturn.Plans, ServiceOfferingPlan{ + Name: plan.Name, + Description: plan.Description, + }) + } + + return toReturn +} + +func ToServiceBindingsVM(bindings *types.ServiceBindings) ServiceBindings { + toReturn := ServiceBindings{ + Items: []ServiceBinding{}, + } + + for _, _ = range bindings.ServiceBindings { + n := ServiceBinding{} + toReturn.Items = append(toReturn.Items, n) + } + + return toReturn +} + +func ToServiceBindingVM(binding *types.ServiceBinding) ServiceBindings { + return ServiceBindings{} +} diff --git a/internal/api/responses/responses.go b/internal/api/responses/responses.go new file mode 100644 index 000000000..d4160f771 --- /dev/null +++ b/internal/api/responses/responses.go @@ -0,0 +1,58 @@ +package responses + +type Secrets struct { + Items []Secret `json:"items"` +} + +type Secret struct { + Name string `json:"name"` + Namespace string `json:"namespace"` +} + +type ServiceOfferings struct { + NumItems int `json:"numItems"` + Items []ServiceOffering `json:"items"` +} + +type ServiceOffering struct { + ID string `json:"id"` + Description string `json:"description"` + CatalogID string `json:"catalogID"` + CatalogName string `json:"catalogName"` + Metadata ServiceOfferingMetadata `json:"metadata"` +} + +type ServiceOfferingMetadata struct { + ImageUrl string `json:"imageUrl"` + DisplayName string `json:"displayName"` + DocumentationUrl string `json:"documentationUrl"` + SupportUrl string `json:"supportUrl"` +} + +type ServiceInstances struct { + Items []ServiceInstance `json:"items"` +} + +type ServiceInstance struct { + Name string `json:"name"` + Namespace string `json:"namespace"` +} + +type ServiceOfferingDetails struct { + LongDescription string `json:"longDescription"` + Plans []ServiceOfferingPlan `json:"plans"` +} + +type ServiceOfferingPlan struct { + Name string `json:"name"` + Description string `json:"description"` +} + +type ServiceBinding struct { + Name string `json:"name"` + Namespace string `json:"namespace"` +} + +type ServiceBindings struct { + Items []ServiceBinding `json:"items"` +} diff --git a/internal/service-manager/types/requests/CreateServiceBindingRequestPayload.go b/internal/service-manager/types/requests/CreateServiceBindingRequestPayload.go new file mode 100644 index 000000000..9f1f0a6f1 --- /dev/null +++ b/internal/service-manager/types/requests/CreateServiceBindingRequestPayload.go @@ -0,0 +1,15 @@ +package requests + +import ( + "encoding/json" + + "github.com/kyma-project/btp-manager/internal/service-manager/types" +) + +type CreateServiceBindingRequestPayload struct { + Name string `json:"name"` + ServiceInstanceID string `json:"service_instance_id" yaml:"service_instance_id,omitempty"` + Parameters json.RawMessage `json:"parameters,omitempty" yaml:"parameters,omitempty"` + Labels types.Labels `json:"labels,omitempty" yaml:"labels,omitempty"` + BindResource json.RawMessage `json:"bind_resource" yaml:"bind_resource"` +} diff --git a/internal/service-manager/types/service_binding.go b/internal/service-manager/types/service_binding.go new file mode 100644 index 000000000..92d171987 --- /dev/null +++ b/internal/service-manager/types/service_binding.go @@ -0,0 +1,32 @@ +package types + +import "encoding/json" + +// ServiceBinding defines the data of a service instance. +type ServiceBinding struct { + Common + Labels Labels `json:"labels,omitempty" yaml:"labels,omitempty"` + PagingSequence int64 `json:"-" yaml:"-"` + + Credentials json.RawMessage `json:"credentials,omitempty" yaml:"credentials,omitempty"` + + ServiceInstanceID string `json:"service_instance_id" yaml:"service_instance_id,omitempty"` + ServiceInstanceName string `json:"service_instance_name,omitempty" yaml:"service_instance_name,omitempty"` + + SyslogDrainURL string `json:"syslog_drain_url,omitempty" yaml:"syslog_drain_url,omitempty"` + RouteServiceURL string `json:"route_service_url,omitempty"` + VolumeMounts json.RawMessage `json:"-" yaml:"-"` + Endpoints json.RawMessage `json:"-" yaml:"-"` + Context json.RawMessage `json:"context,omitempty" yaml:"context,omitempty"` + Parameters json.RawMessage `json:"parameters,omitempty" yaml:"parameters,omitempty"` + BindResource json.RawMessage `json:"-" yaml:"-"` + + Namespace string `json:"namespace"` + Name string `json:"name"` +} + +// ServiceBindings wraps an array of service bindings +type ServiceBindings struct { + ServiceBindings []ServiceBinding `json:"items" yaml:"items"` + Vertical bool `json:"-" yaml:"-"` +}