Skip to content

Commit

Permalink
Merge pull request #1 from kyma-project/add-binding-metadata
Browse files Browse the repository at this point in the history
Add binding metadata
  • Loading branch information
kyma-bot authored Oct 17, 2024
2 parents 5ccf339 + 3801c1e commit 60727c4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
1 change: 1 addition & 0 deletions domain/apiresponses/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type BindingResponse struct {
RouteServiceURL string `json:"route_service_url,omitempty"`
VolumeMounts []domain.VolumeMount `json:"volume_mounts,omitempty"`
BackupAgentURL string `json:"backup_agent_url,omitempty"`
Metadata any `json:"metadata,omitempty"`
}

type GetBindingResponse struct {
Expand Down
27 changes: 19 additions & 8 deletions domain/service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,20 @@ type UnbindSpec struct {
}

type Binding struct {
IsAsync bool `json:"is_async"`
AlreadyExists bool `json:"already_exists"`
OperationData string `json:"operation_data"`
Credentials interface{} `json:"credentials"`
SyslogDrainURL string `json:"syslog_drain_url"`
RouteServiceURL string `json:"route_service_url"`
BackupAgentURL string `json:"backup_agent_url,omitempty"`
VolumeMounts []VolumeMount `json:"volume_mounts"`
IsAsync bool `json:"is_async"`
AlreadyExists bool `json:"already_exists"`
OperationData string `json:"operation_data"`
Credentials interface{} `json:"credentials"`
SyslogDrainURL string `json:"syslog_drain_url"`
RouteServiceURL string `json:"route_service_url"`
BackupAgentURL string `json:"backup_agent_url,omitempty"`
VolumeMounts []VolumeMount `json:"volume_mounts"`
Metadata BindingMetadata `json:"metadata,omitempty"`
}

type BindingMetadata struct {
ExpiresAt string `json:"expires_at,omitempty"`
RenewBefore string `json:"renew_before,omitempty"`
}

type GetBindingSpec struct {
Expand All @@ -206,6 +212,7 @@ type GetBindingSpec struct {
RouteServiceURL string
VolumeMounts []VolumeMount
Parameters interface{}
Metadata BindingMetadata
}

func (d ProvisionDetails) GetRawContext() json.RawMessage {
Expand All @@ -228,6 +235,10 @@ func (m InstanceMetadata) IsEmpty() bool {
return len(m.Attributes) == 0 && len(m.Labels) == 0
}

func (m BindingMetadata) IsEmpty() bool {
return len(m.ExpiresAt) == 0 && len(m.RenewBefore) == 0
}

func (d UpdateDetails) GetRawContext() json.RawMessage {
return d.RawContext
}
Expand Down
7 changes: 7 additions & 0 deletions handlers/bind.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,19 @@ func (h APIHandler) Bind(w http.ResponseWriter, req *http.Request) {
return
}

var metadata any
if !binding.Metadata.IsEmpty() {
metadata = binding.Metadata
}

if binding.AlreadyExists {
h.respond(w, http.StatusOK, requestId, apiresponses.BindingResponse{
Credentials: binding.Credentials,
SyslogDrainURL: binding.SyslogDrainURL,
RouteServiceURL: binding.RouteServiceURL,
VolumeMounts: binding.VolumeMounts,
BackupAgentURL: binding.BackupAgentURL,
Metadata: metadata,
})
return
}
Expand Down Expand Up @@ -142,5 +148,6 @@ func (h APIHandler) Bind(w http.ResponseWriter, req *http.Request) {
RouteServiceURL: binding.RouteServiceURL,
VolumeMounts: binding.VolumeMounts,
BackupAgentURL: binding.BackupAgentURL,
Metadata: metadata,
})
}
6 changes: 6 additions & 0 deletions handlers/get_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,18 @@ func (h APIHandler) GetBinding(w http.ResponseWriter, req *http.Request) {
return
}

var metadata any
if !binding.Metadata.IsEmpty() {
metadata = binding.Metadata
}

h.respond(w, http.StatusOK, requestId, apiresponses.GetBindingResponse{
BindingResponse: apiresponses.BindingResponse{
Credentials: binding.Credentials,
SyslogDrainURL: binding.SyslogDrainURL,
RouteServiceURL: binding.RouteServiceURL,
VolumeMounts: binding.VolumeMounts,
Metadata: metadata,
},
Parameters: binding.Parameters,
})
Expand Down

0 comments on commit 60727c4

Please sign in to comment.