From 8bab751938ecf11ca708c7091edae98eb03f28f5 Mon Sep 17 00:00:00 2001 From: Toni Kangas Date: Wed, 4 Sep 2024 17:47:46 +0300 Subject: [PATCH] feat(objsto): add custom domains support --- upcloud/load_balancer.go | 4 +++ upcloud/managed_object_storage.go | 5 +++ upcloud/request/load_balancer.go | 7 ++++ upcloud/request/managed_object_storage.go | 44 +++++++++++++++++++++++ upcloud/service/load_balancer.go | 6 ++++ upcloud/service/managed_object_storage.go | 22 ++++++++++++ 6 files changed, 88 insertions(+) diff --git a/upcloud/load_balancer.go b/upcloud/load_balancer.go index 0c5e9062..bd068a67 100644 --- a/upcloud/load_balancer.go +++ b/upcloud/load_balancer.go @@ -417,3 +417,7 @@ type LoadBalancerNodeNetwork struct { type LoadBalancerFrontendNetwork struct { Name string `json:"name,omitempty"` } + +type LoadBalancerDNSChallengeDomain struct { + Domain string `json:"domain"` +} diff --git a/upcloud/managed_object_storage.go b/upcloud/managed_object_storage.go index 4d3b14cc..f6cb7709 100644 --- a/upcloud/managed_object_storage.go +++ b/upcloud/managed_object_storage.go @@ -141,3 +141,8 @@ type ManagedObjectStorageMetrics struct { TotalObjects int `json:"total_objects"` TotalSizeBytes int `json:"total_size_bytes"` } + +type ManagedObjectStorageCustomDomain struct { + DomainName string `json:"domain_name"` + Type string `json:"type"` +} diff --git a/upcloud/request/load_balancer.go b/upcloud/request/load_balancer.go index 2e790a2a..c04924ea 100644 --- a/upcloud/request/load_balancer.go +++ b/upcloud/request/load_balancer.go @@ -728,3 +728,10 @@ func (r *ModifyLoadBalancerNetworkRequest) RequestURL() string { func (r *ModifyLoadBalancerNetworkRequest) MarshalJSON() ([]byte, error) { return json.Marshal(r.Network) } + +// GetLoadBalancerDNSChallengeDomainRequest represents a request to get domain for DNS challenge +type GetLoadBalancerDNSChallengeDomainRequest struct{} + +func (r *GetLoadBalancerDNSChallengeDomainRequest) RequestURL() string { + return "load-balancer/certificate-bundles/dns-challenge-domain" +} diff --git a/upcloud/request/managed_object_storage.go b/upcloud/request/managed_object_storage.go index 344bc4c1..8b9874c3 100644 --- a/upcloud/request/managed_object_storage.go +++ b/upcloud/request/managed_object_storage.go @@ -361,6 +361,50 @@ func (r *DetachManagedObjectStorageUserPolicyRequest) RequestURL() string { return fmt.Sprintf("%s/%s/users/%s/policies/%s", managedObjectStorageBasePath, r.ServiceUUID, r.Username, r.Name) } +// CreateManagedObjectStorageCustomDomainRequest represents a request for creating a policy +type CreateManagedObjectStorageCustomDomainRequest struct { + DomainName string `json:"domain_name"` + Type string `json:"type"` + ServiceUUID string `json:"-"` +} + +// RequestURL implements the Request interface +func (r *CreateManagedObjectStorageCustomDomainRequest) RequestURL() string { + return fmt.Sprintf("%s/%s/custom-domains", managedObjectStorageBasePath, r.ServiceUUID) +} + +// GetManagedObjectStorageCustomDomainsRequest represents a request for retrieving policies +type GetManagedObjectStorageCustomDomainsRequest struct { + ServiceUUID string `json:"-"` +} + +// RequestURL implements the Request interface +func (r *GetManagedObjectStorageCustomDomainsRequest) RequestURL() string { + return fmt.Sprintf("%s/%s/custom-domains", managedObjectStorageBasePath, r.ServiceUUID) +} + +// GetManagedObjectStorageCustomDomainRequest represents a request for retrieving details about a policy +type GetManagedObjectStorageCustomDomainRequest struct { + DomainName string `json:"-"` + ServiceUUID string `json:"-"` +} + +// RequestURL implements the Request interface +func (r *GetManagedObjectStorageCustomDomainRequest) RequestURL() string { + return fmt.Sprintf("%s/%s/custom-domains/%s", managedObjectStorageBasePath, r.ServiceUUID, r.DomainName) +} + +// DeleteManagedObjectStorageCustomDomainRequest represents a request to delete a policy +type DeleteManagedObjectStorageCustomDomainRequest struct { + ServiceUUID string `json:"-"` + DomainName string `json:"-"` +} + +// RequestURL implements the Request interface +func (r *DeleteManagedObjectStorageCustomDomainRequest) RequestURL() string { + return fmt.Sprintf("%s/%s/custom-domains/%s", managedObjectStorageBasePath, r.ServiceUUID, r.DomainName) +} + // WaitForManagedObjectStorageOperationalStateRequest represents a request to wait for a Managed Object Storage service // to enter a desired state type WaitForManagedObjectStorageOperationalStateRequest struct { diff --git a/upcloud/service/load_balancer.go b/upcloud/service/load_balancer.go index 8776cb4e..4c87ad5d 100644 --- a/upcloud/service/load_balancer.go +++ b/upcloud/service/load_balancer.go @@ -66,6 +66,7 @@ type LoadBalancer interface { DeleteLoadBalancerCertificateBundle(ctx context.Context, r *request.DeleteLoadBalancerCertificateBundleRequest) error // Networks ModifyLoadBalancerNetwork(ctx context.Context, r *request.ModifyLoadBalancerNetworkRequest) (*upcloud.LoadBalancerNetwork, error) + GetLoadBalancerDNSChallengeDomain(ctx context.Context, r *request.GetLoadBalancerDNSChallengeDomainRequest) (*upcloud.LoadBalancerDNSChallengeDomain, error) } // GetLoadBalancers retrieves a list of load balancers. @@ -422,3 +423,8 @@ func (s *Service) ModifyLoadBalancerNetwork(ctx context.Context, r *request.Modi n := upcloud.LoadBalancerNetwork{} return &n, s.modify(ctx, r, &n) } + +func (s *Service) GetLoadBalancerDNSChallengeDomain(ctx context.Context, r *request.GetLoadBalancerDNSChallengeDomainRequest) (*upcloud.LoadBalancerDNSChallengeDomain, error) { + var domain upcloud.LoadBalancerDNSChallengeDomain + return &domain, s.get(ctx, r.RequestURL(), &domain) +} diff --git a/upcloud/service/managed_object_storage.go b/upcloud/service/managed_object_storage.go index 1b4b2ded..582d1ddc 100644 --- a/upcloud/service/managed_object_storage.go +++ b/upcloud/service/managed_object_storage.go @@ -40,6 +40,10 @@ type ManagedObjectStorage interface { AttachManagedObjectStorageUserPolicy(ctx context.Context, r *request.AttachManagedObjectStorageUserPolicyRequest) error GetManagedObjectStorageUserPolicies(ctx context.Context, r *request.GetManagedObjectStorageUserPoliciesRequest) ([]upcloud.ManagedObjectStorageUserPolicy, error) DetachManagedObjectStorageUserPolicy(ctx context.Context, r *request.DetachManagedObjectStorageUserPolicyRequest) error + CreateManagedObjectStorageCustomDomain(ctx context.Context, r *request.CreateManagedObjectStorageCustomDomainRequest) error + GetManagedObjectStorageCustomDomains(ctx context.Context, r *request.GetManagedObjectStorageCustomDomainsRequest) ([]upcloud.ManagedObjectStorageCustomDomain, error) + GetManagedObjectStorageCustomDomain(ctx context.Context, r *request.GetManagedObjectStorageCustomDomainRequest) (*upcloud.ManagedObjectStorageCustomDomain, error) + DeleteManagedObjectStorageCustomDomain(ctx context.Context, r *request.DeleteManagedObjectStorageCustomDomainRequest) error WaitForManagedObjectStorageOperationalState(ctx context.Context, r *request.WaitForManagedObjectStorageOperationalStateRequest) (*upcloud.ManagedObjectStorage, error) WaitForManagedObjectStorageDeletion(ctx context.Context, r *request.WaitForManagedObjectStorageDeletionRequest) error } @@ -187,6 +191,24 @@ func (s *Service) DetachManagedObjectStorageUserPolicy(ctx context.Context, r *r return s.delete(ctx, r) } +func (s *Service) CreateManagedObjectStorageCustomDomain(ctx context.Context, r *request.CreateManagedObjectStorageCustomDomainRequest) error { + return s.create(ctx, r, nil) +} + +func (s *Service) GetManagedObjectStorageCustomDomains(ctx context.Context, r *request.GetManagedObjectStorageCustomDomainsRequest) ([]upcloud.ManagedObjectStorageCustomDomain, error) { + domains := make([]upcloud.ManagedObjectStorageCustomDomain, 0) + return domains, s.get(ctx, r.RequestURL(), &domains) +} + +func (s *Service) GetManagedObjectStorageCustomDomain(ctx context.Context, r *request.GetManagedObjectStorageCustomDomainRequest) (*upcloud.ManagedObjectStorageCustomDomain, error) { + domain := upcloud.ManagedObjectStorageCustomDomain{} + return &domain, s.get(ctx, r.RequestURL(), &domain) +} + +func (s *Service) DeleteManagedObjectStorageCustomDomain(ctx context.Context, r *request.DeleteManagedObjectStorageCustomDomainRequest) error { + return s.delete(ctx, r) +} + // WaitForManagedObjectStorageOperationalState blocks execution until the specified Managed Object Storage service // has entered the specified state. If the state changes favorably, service details is returned. The method will give up // after the specified timeout