fix: clean up code
This commit is contained in:
parent
36eccc52c3
commit
7181f87aba
41 changed files with 875 additions and 682 deletions
|
|
@ -108,7 +108,7 @@ func CreateInstanceWaitHandler(
|
|||
)
|
||||
if extendedTimeout < 3 {
|
||||
maxWait += time.Minute * 5
|
||||
extendedTimeout = extendedTimeout + 1
|
||||
extendedTimeout++
|
||||
if *s.Network.AccessScope == "SNA" {
|
||||
ready := true
|
||||
if s.Network == nil || s.Network.InstanceAddress == nil {
|
||||
|
|
@ -228,7 +228,7 @@ func GetUserByIdWaitHandler(
|
|||
if userId > math.MaxInt32 {
|
||||
return false, nil, fmt.Errorf("userId value is too big for int32")
|
||||
}
|
||||
userId32 := int32(userId)
|
||||
userId32 := int32(userId) //nolint:gosec // we need to convert databaseId to int32 because API expects int32
|
||||
s, err := a.GetUserRequestExecute(ctx, projectId, region, instanceId, userId32)
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
|
|
@ -239,9 +239,11 @@ func GetUserByIdWaitHandler(
|
|||
switch oapiErr.StatusCode {
|
||||
case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable:
|
||||
case http.StatusNotFound:
|
||||
tflog.Warn(ctx, "api responded with status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
})
|
||||
tflog.Warn(
|
||||
ctx, "api responded with status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
},
|
||||
)
|
||||
return false, nil, nil
|
||||
default:
|
||||
return false, nil, err
|
||||
|
|
@ -262,7 +264,7 @@ func GetDatabaseByIdWaitHandler(
|
|||
) *wait.AsyncActionHandler[postgresflex.GetDatabaseResponse] {
|
||||
handler := wait.New(
|
||||
func() (waitFinished bool, response *postgresflex.GetDatabaseResponse, err error) {
|
||||
dbId32 := int32(databaseId)
|
||||
dbId32 := int32(databaseId) //nolint:gosec // we need to convert databaseId to int32 because API expects int32
|
||||
s, err := a.GetDatabaseRequestExecute(ctx, projectId, region, instanceId, dbId32)
|
||||
if err != nil {
|
||||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
|
|
@ -272,14 +274,18 @@ func GetDatabaseByIdWaitHandler(
|
|||
}
|
||||
switch oapiErr.StatusCode {
|
||||
case http.StatusBadGateway, http.StatusGatewayTimeout, http.StatusServiceUnavailable:
|
||||
tflog.Warn(ctx, "api responded with 50[2,3,4] status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
})
|
||||
tflog.Warn(
|
||||
ctx, "api responded with 50[2,3,4] status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
},
|
||||
)
|
||||
return false, nil, nil
|
||||
case http.StatusNotFound:
|
||||
tflog.Warn(ctx, "api responded with 404 status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
})
|
||||
tflog.Warn(
|
||||
ctx, "api responded with 404 status", map[string]interface{}{
|
||||
"status": oapiErr.StatusCode,
|
||||
},
|
||||
)
|
||||
return false, nil, nil
|
||||
default:
|
||||
return false, nil, err
|
||||
|
|
|
|||
|
|
@ -54,7 +54,12 @@ type APIClientInterface interface {
|
|||
instanceId string,
|
||||
) (*sqlserverflex.ListRolesResponse, error)
|
||||
|
||||
ListUsersRequest(ctx context.Context, projectId string, region string, instanceId string) sqlserverflex.ApiListUsersRequestRequest
|
||||
ListUsersRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
) sqlserverflex.ApiListUsersRequestRequest
|
||||
|
||||
ListUsersRequestExecute(
|
||||
ctx context.Context,
|
||||
|
|
@ -256,7 +261,10 @@ func CreateDatabaseWaitHandler(
|
|||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
if !ok {
|
||||
return false, nil, fmt.Errorf("get database - could not convert error to oapierror.GenericOpenAPIError: %s", err.Error())
|
||||
return false, nil, fmt.Errorf(
|
||||
"get database - could not convert error to oapierror.GenericOpenAPIError: %s",
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
return false, nil, err
|
||||
|
|
@ -318,7 +326,10 @@ func WaitForUserWaitHandler(
|
|||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
if !ok {
|
||||
return false, nil, fmt.Errorf("Wait (list users) could not convert error to oapierror.GenericOpenAPIError: %s", err.Error())
|
||||
return false, nil, fmt.Errorf(
|
||||
"wait (list users) could not convert error to oapierror.GenericOpenAPIError: %s",
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
return false, nil, err
|
||||
|
|
|
|||
|
|
@ -116,7 +116,6 @@ func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
|||
}, nil
|
||||
}
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
//stateSuccess := utils.Ptr(InstanceStateSuccess)
|
||||
instanceId := utils.Ptr("foo")
|
||||
tests := []struct {
|
||||
desc string
|
||||
|
|
@ -160,7 +159,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
// Storage: nil,
|
||||
// Version: nil,
|
||||
// },
|
||||
//},
|
||||
// },
|
||||
{
|
||||
desc: "create_failed",
|
||||
instanceId: *instanceId,
|
||||
|
|
|
|||
|
|
@ -54,7 +54,12 @@ type APIClientInterface interface {
|
|||
instanceId string,
|
||||
) (*sqlserverflex.ListRolesResponse, error)
|
||||
|
||||
ListUsersRequest(ctx context.Context, projectId string, region string, instanceId string) sqlserverflex.ApiListUsersRequestRequest
|
||||
ListUsersRequest(
|
||||
ctx context.Context,
|
||||
projectId string,
|
||||
region string,
|
||||
instanceId string,
|
||||
) sqlserverflex.ApiListUsersRequestRequest
|
||||
|
||||
ListUsersRequestExecute(
|
||||
ctx context.Context,
|
||||
|
|
@ -162,9 +167,17 @@ func CreateInstanceWaitHandler(
|
|||
}
|
||||
return true, s, nil
|
||||
case strings.ToLower(InstanceStateUnknown):
|
||||
return true, nil, fmt.Errorf("create failed for instance %s with status %s", instanceId, InstanceStateUnknown)
|
||||
return true, nil, fmt.Errorf(
|
||||
"create failed for instance %s with status %s",
|
||||
instanceId,
|
||||
InstanceStateUnknown,
|
||||
)
|
||||
case strings.ToLower(InstanceStateFailed):
|
||||
return true, nil, fmt.Errorf("create failed for instance %s with status %s", instanceId, InstanceStateFailed)
|
||||
return true, nil, fmt.Errorf(
|
||||
"create failed for instance %s with status %s",
|
||||
instanceId,
|
||||
InstanceStateFailed,
|
||||
)
|
||||
case strings.ToLower(InstanceStatePending), strings.ToLower(InstanceStateProcessing):
|
||||
tflog.Info(
|
||||
ctx, "request is being handled", map[string]interface{}{
|
||||
|
|
@ -268,7 +281,10 @@ func CreateDatabaseWaitHandler(
|
|||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
if !ok {
|
||||
return false, nil, fmt.Errorf("get database - could not convert error to oapierror.GenericOpenAPIError: %s", err.Error())
|
||||
return false, nil, fmt.Errorf(
|
||||
"get database - could not convert error to oapierror.GenericOpenAPIError: %s",
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
return false, nil, err
|
||||
|
|
@ -330,7 +346,10 @@ func WaitForUserWaitHandler(
|
|||
var oapiErr *oapierror.GenericOpenAPIError
|
||||
ok := errors.As(err, &oapiErr)
|
||||
if !ok {
|
||||
return false, nil, fmt.Errorf("Wait (list users) could not convert error to oapierror.GenericOpenAPIError: %s", err.Error())
|
||||
return false, nil, fmt.Errorf(
|
||||
"wait (list users) could not convert error to oapierror.GenericOpenAPIError: %s",
|
||||
err.Error(),
|
||||
)
|
||||
}
|
||||
if oapiErr.StatusCode != http.StatusNotFound {
|
||||
return false, nil, err
|
||||
|
|
|
|||
|
|
@ -116,7 +116,6 @@ func (a *apiClientInstanceMocked) GetInstanceRequestExecute(
|
|||
}, nil
|
||||
}
|
||||
func TestCreateInstanceWaitHandler(t *testing.T) {
|
||||
//stateSuccess := utils.Ptr(InstanceStateSuccess)
|
||||
instanceId := utils.Ptr("foo")
|
||||
tests := []struct {
|
||||
desc string
|
||||
|
|
@ -160,7 +159,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
|
|||
// Storage: nil,
|
||||
// Version: nil,
|
||||
// },
|
||||
//},
|
||||
// },
|
||||
{
|
||||
desc: "create_failed",
|
||||
instanceId: *instanceId,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue