forked from kyma-project/kyma
/
lastop.go
45 lines (34 loc) · 999 Bytes
/
lastop.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
package broker
import (
"context"
"github.com/pkg/errors"
osb "github.com/pmorie/go-open-service-broker-client/v2"
"github.com/kyma-project/kyma/components/helm-broker/internal"
)
type getLastOperationService struct {
getter operationGetter
}
func (svc *getLastOperationService) GetLastOperation(ctx context.Context, osbCtx osbContext, req *osb.LastOperationRequest) (*osb.LastOperationResponse, error) {
iID := internal.InstanceID(req.InstanceID)
var opID internal.OperationID
if req.OperationKey != nil {
opID = internal.OperationID(*req.OperationKey)
}
op, err := svc.getter.Get(iID, opID)
switch {
case IsNotFoundError(err):
return nil, err
case err != nil:
return nil, errors.Wrap(err, "while getting instance operation")
}
var descPtr *string
if op.StateDescription != nil {
desc := *op.StateDescription
descPtr = &desc
}
resp := osb.LastOperationResponse{
State: osb.LastOperationState(op.State),
Description: descPtr,
}
return &resp, nil
}