Skip to content

Commit

Permalink
fix: add expiration date and time for bindings
Browse files Browse the repository at this point in the history
* Add expiration date and time for bindings

* Add renew before field

* Fix tests
  • Loading branch information
KsaweryZietara authored Oct 9, 2024
1 parent c78d48d commit 1196157
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
1 change: 1 addition & 0 deletions domain/apiresponses/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ type BindingResponse struct {
VolumeMounts []domain.VolumeMount `json:"volume_mounts,omitempty"`
BackupAgentURL string `json:"backup_agent_url,omitempty"`
Endpoints []domain.Endpoint `json:"endpoints,omitempty"`
Metadata any `json:"metadata,omitempty"`
}

type GetBindingResponse struct {
Expand Down
29 changes: 20 additions & 9 deletions domain/service_broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,21 @@ type UnbindSpec struct {
}

type Binding struct {
IsAsync bool `json:"is_async"`
AlreadyExists bool `json:"already_exists"`
OperationData string `json:"operation_data"`
Credentials any `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"`
Endpoints []Endpoint `json:"endpoints,omitempty"`
IsAsync bool `json:"is_async"`
AlreadyExists bool `json:"already_exists"`
OperationData string `json:"operation_data"`
Credentials any `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"`
Endpoints []Endpoint `json:"endpoints,omitempty"`
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 @@ -208,6 +214,7 @@ type GetBindingSpec struct {
VolumeMounts []VolumeMount
Parameters any
Endpoints []Endpoint
Metadata BindingMetadata
}

type Endpoint struct {
Expand Down Expand Up @@ -236,6 +243,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 @@ -81,6 +81,11 @@ 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,
Expand All @@ -89,6 +94,7 @@ func (h APIHandler) Bind(w http.ResponseWriter, req *http.Request) {
VolumeMounts: binding.VolumeMounts,
BackupAgentURL: binding.BackupAgentURL,
Endpoints: binding.Endpoints,
Metadata: metadata,
})
return
}
Expand Down Expand Up @@ -140,5 +146,6 @@ func (h APIHandler) Bind(w http.ResponseWriter, req *http.Request) {
VolumeMounts: binding.VolumeMounts,
BackupAgentURL: binding.BackupAgentURL,
Endpoints: binding.Endpoints,
Metadata: metadata,
})
}
6 changes: 6 additions & 0 deletions handlers/get_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,19 @@ 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,
Endpoints: binding.Endpoints,
Metadata: metadata,
},
Parameters: binding.Parameters,
})
Expand Down

0 comments on commit 1196157

Please sign in to comment.