-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathoperation_status_response.go
59 lines (51 loc) · 2.06 KB
/
operation_status_response.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package framework
import (
"fmt"
)
// ErrUnknownOperationState is an error indicating that a string is not a known operation state.
type ErrUnknownOperationState string
// Error is the error interface implementation.
func (e ErrUnknownOperationState) Error() string {
return fmt.Sprintf("unknown operation state '%s'", string(e))
}
// OperationState represents the state returned in a "get operation status" call. This type
// implements fmt.Stringer.
type OperationState string
// String is the fmt.Stringer interface implementation.
func (l OperationState) String() string {
return string(l)
}
const (
// OperationStateSucceeded is the OperationState indicating that the operation has succeeded
OperationStateSucceeded OperationState = "succeeded"
// OperationStateFailed is the OperationState indicating that the operation has failed.
OperationStateFailed OperationState = "failed"
// OperationStateInProgress is the OperationState indicating that the operation is still in
// progress.
OperationStateInProgress OperationState = "in progress"
// OperationStateGone is the OperationState indicating that the service broker has deleted the
// service instance in question. In the case of async deprovisioning, this is an indicator of
// success.
OperationStateGone OperationState = "gone"
)
// OperationStatusResponse represents a response to a OperationStatusRequest.
type OperationStatusResponse struct {
State string
}
// GetState returns the OperationState corresponding to a OperationStatusResponse instance's
// State attribute, or an error if that State attribute does not correspond to a valid
// OperationState.
func (o *OperationStatusResponse) GetState() (OperationState, error) {
switch o.State {
case OperationStateSucceeded.String():
return OperationStateSucceeded, nil
case OperationStateFailed.String():
return OperationStateFailed, nil
case OperationStateInProgress.String():
return OperationStateInProgress, nil
case OperationStateGone.String():
return OperationStateGone, nil
default:
return OperationState(""), ErrUnknownOperationState(o.State)
}
}