@@ -16,12 +16,18 @@ import (
1616
1717 std "github.com/scaleway/scaleway-sdk-go/api/std"
1818 "github.com/scaleway/scaleway-sdk-go/errors"
19+ "github.com/scaleway/scaleway-sdk-go/internal/async"
1920 "github.com/scaleway/scaleway-sdk-go/marshaler"
2021 "github.com/scaleway/scaleway-sdk-go/namegenerator"
2122 "github.com/scaleway/scaleway-sdk-go/parameter"
2223 "github.com/scaleway/scaleway-sdk-go/scw"
2324)
2425
26+ const (
27+ defaultDomainRetryInterval = 15 * time .Second
28+ defaultDomainTimeout = 5 * time .Minute
29+ )
30+
2531// always import dependencies
2632var (
2733 _ fmt.Stringer
@@ -3956,6 +3962,51 @@ func (s *API) GetSSLCertificate(req *GetSSLCertificateRequest, opts ...scw.Reque
39563962 return & resp , nil
39573963}
39583964
3965+ // WaitForSSLCertificateRequest is used by WaitForSSLCertificate method.
3966+ type WaitForSSLCertificateRequest struct {
3967+ GetSSLCertificateRequest
3968+ Timeout * time.Duration
3969+ RetryInterval * time.Duration
3970+ }
3971+
3972+ // WaitForSSLCertificate waits for the SSLCertificate to reach a terminal state.
3973+ func (s * API ) WaitForSSLCertificate (req * WaitForSSLCertificateRequest , opts ... scw.RequestOption ) (* SSLCertificate , error ) {
3974+ timeout := defaultDomainTimeout
3975+ if req .Timeout != nil {
3976+ timeout = * req .Timeout
3977+ }
3978+
3979+ retryInterval := defaultDomainRetryInterval
3980+ if req .RetryInterval != nil {
3981+ retryInterval = * req .RetryInterval
3982+ }
3983+ transientStatuses := map [SSLCertificateStatus ]struct {}{
3984+ SSLCertificateStatusPending : {},
3985+ }
3986+
3987+ res , err := async .WaitSync (& async.WaitSyncConfig {
3988+ Get : func () (interface {}, bool , error ) {
3989+ res , err := s .GetSSLCertificate (& GetSSLCertificateRequest {
3990+ DNSZone : req .DNSZone ,
3991+ }, opts ... )
3992+ if err != nil {
3993+ return nil , false , err
3994+ }
3995+
3996+ _ , isTransient := transientStatuses [res .Status ]
3997+
3998+ return res , ! isTransient , nil
3999+ },
4000+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
4001+ Timeout : timeout ,
4002+ })
4003+ if err != nil {
4004+ return nil , errors .Wrap (err , "waiting for SSLCertificate failed" )
4005+ }
4006+
4007+ return res .(* SSLCertificate ), nil
4008+ }
4009+
39594010// CreateSSLCertificate: Create a new TLS certificate or retrieve information about an existing TLS certificate.
39604011func (s * API ) CreateSSLCertificate (req * CreateSSLCertificateRequest , opts ... scw.RequestOption ) (* SSLCertificate , error ) {
39614012 var err error
@@ -4544,6 +4595,57 @@ func (s *RegistrarAPI) GetDomain(req *RegistrarAPIGetDomainRequest, opts ...scw.
45444595 return & resp , nil
45454596}
45464597
4598+ // WaitForDomainRequest is used by WaitForDomain method.
4599+ type WaitForDomainRequest struct {
4600+ RegistrarAPIGetDomainRequest
4601+ Timeout * time.Duration
4602+ RetryInterval * time.Duration
4603+ }
4604+
4605+ // WaitForDomain waits for the Domain to reach a terminal state.
4606+ func (s * RegistrarAPI ) WaitForDomain (req * WaitForDomainRequest , opts ... scw.RequestOption ) (* Domain , error ) {
4607+ timeout := defaultDomainTimeout
4608+ if req .Timeout != nil {
4609+ timeout = * req .Timeout
4610+ }
4611+
4612+ retryInterval := defaultDomainRetryInterval
4613+ if req .RetryInterval != nil {
4614+ retryInterval = * req .RetryInterval
4615+ }
4616+ transientStatuses := map [DomainStatus ]struct {}{
4617+ DomainStatusCreating : {},
4618+ DomainStatusRenewing : {},
4619+ DomainStatusXfering : {},
4620+ DomainStatusExpiring : {},
4621+ DomainStatusUpdating : {},
4622+ DomainStatusChecking : {},
4623+ DomainStatusDeleting : {},
4624+ }
4625+
4626+ res , err := async .WaitSync (& async.WaitSyncConfig {
4627+ Get : func () (interface {}, bool , error ) {
4628+ res , err := s .GetDomain (& RegistrarAPIGetDomainRequest {
4629+ Domain : req .Domain ,
4630+ }, opts ... )
4631+ if err != nil {
4632+ return nil , false , err
4633+ }
4634+
4635+ _ , isTransient := transientStatuses [res .Status ]
4636+
4637+ return res , ! isTransient , nil
4638+ },
4639+ IntervalStrategy : async .LinearIntervalStrategy (retryInterval ),
4640+ Timeout : timeout ,
4641+ })
4642+ if err != nil {
4643+ return nil , errors .Wrap (err , "waiting for Domain failed" )
4644+ }
4645+
4646+ return res .(* Domain ), nil
4647+ }
4648+
45474649// UpdateDomain: Update contacts for a specific domain or create a new contact.<br/>
45484650// If you add the same contact for multiple roles (owner, administrative, technical), only one ID will be created and used for all of the roles.
45494651func (s * RegistrarAPI ) UpdateDomain (req * RegistrarAPIUpdateDomainRequest , opts ... scw.RequestOption ) (* Domain , error ) {
0 commit comments