Skip to content

Commit 35c31e9

Browse files
authored
[keyvault] refactor restore poller in azadmin (Azure#20556)
* refactor pollers
1 parent f3ef14e commit 35c31e9

File tree

4 files changed

+13
-221
lines changed

4 files changed

+13
-221
lines changed

sdk/security/keyvault/azadmin/backup/internal/pollers/restore_poller.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"net/http"
1818

1919
"github.com/Azure/azure-sdk-for-go/sdk/azcore/runtime"
20+
"github.com/Azure/azure-sdk-for-go/sdk/internal/poller"
2021
)
2122

2223
func pollHelper(ctx context.Context, endpoint string, pl runtime.Pipeline, update func(resp *http.Response) (string, error)) error {
@@ -43,7 +44,7 @@ func resultHelper[T any](resp *http.Response, failed bool, out *T) error {
4344
}
4445

4546
defer resp.Body.Close()
46-
if !statusCodeValid(resp) || failed {
47+
if !poller.StatusCodeValid(resp) || failed {
4748
// the LRO failed. unmarshall the error and update state
4849
return runtime.NewResponseError(resp)
4950
}
@@ -99,15 +100,15 @@ func NewRestorePoller[T any](pl runtime.Pipeline, resp *http.Response, finalStat
99100
if asyncURL == "" {
100101
return nil, errors.New("response is missing Azure-AsyncOperation header")
101102
}
102-
if !isValidURL(asyncURL) {
103+
if !poller.IsValidURL(asyncURL) {
103104
return nil, fmt.Errorf("invalid polling URL %s", asyncURL)
104105
}
105106
// check for provisioning state. if the operation is a RELO
106107
// and terminates synchronously this will prevent extra polling.
107108
// it's ok if there's no provisioning state.
108-
state, _ := getProvisioningState(resp)
109+
state, _ := poller.GetProvisioningState(resp)
109110
if state == "" {
110-
state = statusInProgress
111+
state = poller.StatusInProgress
111112
}
112113
p := &restorePoller[T]{
113114
pl: pl,
@@ -124,17 +125,17 @@ func NewRestorePoller[T any](pl runtime.Pipeline, resp *http.Response, finalStat
124125

125126
// Done returns true if the LRO is in a terminal state.
126127
func (p *restorePoller[T]) Done() bool {
127-
return isTerminalState(p.CurState)
128+
return poller.IsTerminalState(p.CurState)
128129
}
129130

130131
// Poll retrieves the current state of the LRO.
131132
func (p *restorePoller[T]) Poll(ctx context.Context) (*http.Response, error) {
132133
err := pollHelper(ctx, p.AsyncURL, p.pl, func(resp *http.Response) (string, error) {
133-
if !statusCodeValid(resp) {
134+
if !poller.StatusCodeValid(resp) {
134135
p.resp = resp
135136
return "", runtime.NewResponseError(resp)
136137
}
137-
state, err := getStatus(resp)
138+
state, err := poller.GetStatus(resp)
138139
if err != nil {
139140
return "", err
140141
} else if state == "" {
@@ -153,9 +154,9 @@ func (p *restorePoller[T]) Poll(ctx context.Context) (*http.Response, error) {
153154
func (p *restorePoller[T]) Result(ctx context.Context, out *T) error {
154155
if p.resp.StatusCode == http.StatusNoContent {
155156
return nil
156-
} else if failed(p.CurState) {
157+
} else if poller.Failed(p.CurState) {
157158
return runtime.NewResponseError(p.resp)
158159
}
159160

160-
return resultHelper(p.resp, failed(p.CurState), out)
161+
return resultHelper(p.resp, poller.Failed(p.CurState), out)
161162
}

sdk/security/keyvault/azadmin/backup/internal/pollers/utils_poller.go

Lines changed: 0 additions & 209 deletions
This file was deleted.

sdk/security/keyvault/azadmin/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.18
55
require (
66
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0
77
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1
8-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0
8+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0
99
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.9.0
1010
github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v0.8.0
1111
github.com/google/uuid v1.3.0

sdk/security/keyvault/azadmin/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0 h1:rTnT/Jrcm+figWlYz4Ixzt0SJ
22
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.4.0/go.mod h1:ON4tFdPTwRcgWEaVDrN3584Ef+b7GgSJaXxe5fW9t4M=
33
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1 h1:T8quHYlUGyb/oqtSTwqlCr1ilJHrDv+ZtpSfo+hm1BU=
44
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.2.1/go.mod h1:gLa1CL2RNE4s7M3yopJ/p0iq5DdY6Yv5ZUt9MTRZOQM=
5-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0 h1:leh5DwKv6Ihwi+h60uHtn6UWAxBbZ0q8DwQVMzf61zw=
6-
github.com/Azure/azure-sdk-for-go/sdk/internal v1.2.0/go.mod h1:eWRD7oawr1Mu1sLCawqVc0CUiF43ia3qQMxLscsKQ9w=
5+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0 h1:sXr+ck84g/ZlZUOZiNELInmMgOsuGwdjjVkEIde0OtY=
6+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.3.0/go.mod h1:okt5dMMTOFjX/aovMlrjvvXoPMBVSPzk9185BT0+eZM=
77
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.9.0 h1:TOFrNxfjslms5nLLIMjW7N0+zSALX4KiGsptmpb16AA=
88
github.com/Azure/azure-sdk-for-go/sdk/keyvault/azkeys v0.9.0/go.mod h1:EAyXOW1F6BTJPiK2pDvmnvxOHPxoTYWoqBeIlql+QhI=
99
github.com/Azure/azure-sdk-for-go/sdk/keyvault/internal v0.7.0 h1:Lg6BW0VPmCwcMlvOviL3ruHFO+H9tZNqscK0AeuFjGM=

0 commit comments

Comments
 (0)