fix: pgsql user waiter
This commit is contained in:
parent
459120d3b3
commit
4189a5ebcb
7 changed files with 101 additions and 61 deletions
|
|
@ -2,7 +2,10 @@ package postgresflexalpha
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform-plugin-log/tflog"
|
||||
|
|
@ -40,7 +43,7 @@ type APIClientInstanceInterface interface {
|
|||
|
||||
// APIClientUserInterface Interface needed for tests
|
||||
type APIClientUserInterface interface {
|
||||
GetUserRequestExecute(ctx context.Context, projectId, region, instanceId string, userId int64) (
|
||||
GetUserRequestExecute(ctx context.Context, projectId, region, instanceId string, userId int32) (
|
||||
*postgresflex.GetUserResponse,
|
||||
error,
|
||||
)
|
||||
|
|
@ -202,3 +205,34 @@ func PartialUpdateInstanceWaitHandler(
|
|||
handler.SetTimeout(45 * time.Minute).SetSleepBeforeWait(30 * time.Second)
|
||||
return handler
|
||||
}
|
||||
|
||||
// CreateUserWaitHandler will wait for instance creation
|
||||
func CreateUserWaitHandler(
|
||||
ctx context.Context,
|
||||
a APIClientUserInterface,
|
||||
projectId, instanceId, region string,
|
||||
userId int64,
|
||||
) *wait.AsyncActionHandler[postgresflex.GetUserResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *postgresflex.GetUserResponse, err error) {
|
||||
if userId > math.MaxInt32 {
|
||||
return false, nil, fmt.Errorf("userId value is too big for int32")
|
||||
}
|
||||
userId32 := int32(userId)
|
||||
s, err := a.GetUserRequestExecute(ctx, projectId, region, instanceId, userId32)
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
if !ok {
|
||||
return false, nil, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError")
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
return false, nil, err
|
||||
}
|
||||
return false, nil, nil
|
||||
}
|
||||
return true, s, nil
|
||||
},
|
||||
)
|
||||
return handler
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue