Skip to content

Commit

Permalink
feat(dedibox): waiter service support
Browse files Browse the repository at this point in the history
  • Loading branch information
Laure-di committed Aug 1, 2024
1 parent 26666b0 commit 3202cce
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
1 change: 1 addition & 0 deletions internal/namespaces/dedibox/v1/custom_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package dedibox
40 changes: 38 additions & 2 deletions internal/namespaces/dedibox/v1/custom_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,49 @@ package dedibox

import (
"context"
"errors"
"fmt"
"github.com/scaleway/scaleway-cli/v2/internal/core"
"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1"
"github.com/scaleway/scaleway-sdk-go/scw"
"net/http"
"time"
)

const (
serviceActionTimeout = time.Minute * 60
)

const (
serviceActionCreate = iota
serviceActionDelete
)

func serviceCreateBuilder(c *core.Command) *core.Command {
c.WaitFunc = func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
api := dedibox.NewAPI(core.ExtractClient(ctx))
c.WaitFunc = waitForServiceFunc(serviceActionCreate)
return c
}

func waitForServiceFunc(action int) core.WaitFunc {
return func(ctx context.Context, argsI, respI interface{}) (interface{}, error) {
service, err := dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService(&dedibox.WaitForServiceRequest{

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-tests (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-and-test (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-and-test (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-and-test (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / build-and-test (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, ubuntu-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, ubuntu-latest)

undefined: dedibox.WaitForServiceRequest

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, macos-latest)

dedibox.NewAPI(core.ExtractClient(ctx)).WaitForService undefined (type *"github.com/scaleway/scaleway-sdk-go/api/dedibox/v1".API has no field or method WaitForService)

Check failure on line 30 in internal/namespaces/dedibox/v1/custom_service.go

View workflow job for this annotation

GitHub Actions / os-tests (1.22.x, macos-latest)

undefined: dedibox.WaitForServiceRequest
ServiceID: respI.(*dedibox.Service).ID,
Zone: argsI.(*dedibox.CreateServerRequest).Zone,
Timeout: scw.TimeDurationPtr(serviceActionTimeout),
RetryInterval: core.DefaultRetryInterval,
})
switch action {
case serviceActionCreate:
return service, err
case serviceActionDelete:
if err != nil {
notFoundError := &scw.ResourceNotFoundError{}
responseError := &scw.ResponseError{}
if errors.As(err, &responseError) && responseError.StatusCode == http.StatusNotFound || errors.As(err, &notFoundError) {
return fmt.Sprintf("Server %s successfully deleted.", respI.(*dedibox.Service).ID), nil
}
}
}
return nil, err
}
}

0 comments on commit 3202cce

Please sign in to comment.