Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ukff committed Jul 10, 2024
1 parent 2c38506 commit 219135b
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ scripts/run.bat
scripts/**/*.js
scripts/**/*.js.map
coverage/
internal/
**/.DS_Store
.settings
**/.vs
Expand Down
18 changes: 18 additions & 0 deletions internal/api/requests/converters.go
Original file line number Diff line number Diff line change
@@ -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
}
8 changes: 8 additions & 0 deletions internal/api/requests/requests.go
Original file line number Diff line number Diff line change
@@ -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"`
}
83 changes: 83 additions & 0 deletions internal/api/responses/converters.go
Original file line number Diff line number Diff line change
@@ -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{}
}
58 changes: 58 additions & 0 deletions internal/api/responses/responses.go
Original file line number Diff line number Diff line change
@@ -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"`
}
Original file line number Diff line number Diff line change
@@ -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"`
}
32 changes: 32 additions & 0 deletions internal/service-manager/types/service_binding.go
Original file line number Diff line number Diff line change
@@ -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:"-"`
}

0 comments on commit 219135b

Please sign in to comment.