Skip to content

Commit

Permalink
feat(objsto): add custom domains support (#333)
Browse files Browse the repository at this point in the history
  • Loading branch information
kangasta authored Sep 6, 2024
1 parent ea556df commit 961ef78
Show file tree
Hide file tree
Showing 12 changed files with 549 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ See updating [Changelog example here](https://keepachangelog.com/en/1.0.0/)

## [Unreleased]

### Added
- managed object storage: support for custom domains
- managed load balancer: support for reading DNS challenge domain

## [8.7.1]

### Added
Expand Down
4 changes: 4 additions & 0 deletions upcloud/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,3 +417,7 @@ type LoadBalancerNodeNetwork struct {
type LoadBalancerFrontendNetwork struct {
Name string `json:"name,omitempty"`
}

type LoadBalancerDNSChallengeDomain struct {
Domain string `json:"domain"`
}
6 changes: 6 additions & 0 deletions upcloud/managed_object_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type (
type ManagedObjectStorage struct {
ConfiguredStatus ManagedObjectStorageConfiguredStatus `json:"configured_status"`
CreatedAt time.Time `json:"created_at"`
CustomDomains []ManagedObjectStorageCustomDomain `json:"custom_domains"`
Endpoints []ManagedObjectStorageEndpoint `json:"endpoints"`
Labels []Label `json:"labels"`
Name string `json:"name,omitempty"`
Expand Down Expand Up @@ -141,3 +142,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"`
}
12 changes: 12 additions & 0 deletions upcloud/managed_object_storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ func TestManagedObjectStorage(t *testing.T) {
&ManagedObjectStorage{
ConfiguredStatus: ManagedObjectStorageConfiguredStatusStarted,
CreatedAt: timeParse("2023-05-07T15:55:24.655776Z"),
CustomDomains: []ManagedObjectStorageCustomDomain{
{
DomainName: "objects.example.com",
Type: "public",
},
},
Endpoints: []ManagedObjectStorageEndpoint{
{
DomainName: "7mf5k.upbucket.com",
Expand Down Expand Up @@ -52,6 +58,12 @@ func TestManagedObjectStorage(t *testing.T) {
{
"configured_status": "started",
"created_at": "2023-05-07T15:55:24.655776Z",
"custom_domains": [
{
"domain_name": "objects.example.com",
"type": "public"
}
],
"endpoints": [
{
"domain_name": "7mf5k.upbucket.com",
Expand Down
7 changes: 7 additions & 0 deletions upcloud/request/load_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
66 changes: 66 additions & 0 deletions upcloud/request/managed_object_storage.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package request

import (
"encoding/json"
"fmt"

"github.com/UpCloudLtd/upcloud-go-api/v8/upcloud"
Expand Down Expand Up @@ -361,6 +362,71 @@ 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)
}

type ModifyCustomDomain struct {
DomainName string `json:"domain_name"`
Type string `json:"type"`
}

// ModifyManagedObjectStorageCustomDomainRequest represents a request for retrieving details about a policy
type ModifyManagedObjectStorageCustomDomainRequest struct {
DomainName string `json:"-"`
ServiceUUID string `json:"-"`
CustomDomain ModifyCustomDomain
}

// RequestURL implements the Request interface
func (r *ModifyManagedObjectStorageCustomDomainRequest) RequestURL() string {
return fmt.Sprintf("%s/%s/custom-domains/%s", managedObjectStorageBasePath, r.ServiceUUID, r.DomainName)
}

func (r *ModifyManagedObjectStorageCustomDomainRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(r.CustomDomain)
}

// 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 {
Expand Down
29 changes: 29 additions & 0 deletions upcloud/service/fixtures/loadbalancerdnschallenge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Accept:
- application/json
Content-Type:
- application/json
User-Agent:
- upcloud-go-api/8.7.1
url: https://api.upcloud.com/1.3/load-balancer/certificate-bundles/dns-challenge-domain
method: GET
response:
body: '{"domain":"_acme-challenge.750014ac94194e9f30c6ac66c3edc95d78d13241438d4566.upcloudlb.com"}'
headers:
Content-Length:
- "91"
Content-Type:
- application/json
Date:
- Fri, 06 Sep 2024 12:12:15 GMT
Strict-Transport-Security:
- max-age=63072000
status: 200 OK
code: 200
duration: ""
Loading

0 comments on commit 961ef78

Please sign in to comment.