Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions service/subscriptions/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ type Subscription struct {
ID *int `json:"id,omitempty"`
Name *string `json:"name,omitempty"`
Status *string `json:"status,omitempty"`
DeploymentType *string `json:"deploymentType,omitempty"`
PaymentMethod *string `json:"paymentMethodType,omitempty"`
PaymentMethodID *int `json:"paymentMethodId,omitempty"`
MemoryStorage *string `json:"memoryStorage,omitempty"`
Expand Down Expand Up @@ -186,6 +187,21 @@ func (o CreateVPCPeering) String() string {
return internal.ToString(o)
}

type CreateActiveActiveVPCPeering struct {
SourceRegion *string `json:"sourceRegion,omitempty"`
DestinationRegion *string `json:"destinationRegion,omitempty"`
AWSAccountID *string `json:"awsAccountId,omitempty"`
VPCId *string `json:"vpcId,omitempty"`
VPCCidrs []*string `json:"vpcCidrs,omitempty"`
Provider *string `json:"provider,omitempty"`
VPCProjectUID *string `json:"vpcProjectUid,omitempty"`
VPCNetworkName *string `json:"vpcNetworkName,omitempty"`
}

func (o CreateActiveActiveVPCPeering) String() string {
return internal.ToString(o)
}

type listVpcPeering struct {
Peerings []*VPCPeering `json:"peerings"`
}
Expand All @@ -209,6 +225,40 @@ func (o VPCPeering) String() string {
return internal.ToString(o)
}

type listActiveActiveVpcPeering struct {
SubscriptionId *int `json:"subscriptionId,omitempty"`
Regions []*ActiveActiveVpcRegion `json:"regions,omitempty"`
}

type ActiveActiveVpcRegion struct {
ID *int `json:"id,omitempty"`
SourceRegion *string `json:"region,omitempty"`
VPCPeerings []*ActiveActiveVPCPeering `json:"vpcPeerings,omitempty"`
}

type ActiveActiveVPCPeering struct {
ID *int `json:"id,omitempty"`
Status *string `json:"status,omitempty"`
RegionId *int `json:"regionId,omitempty"`
RegionName *string `json:"regionName,omitempty"`
AWSAccountID *string `json:"awsAccountId,omitempty"`
AWSPeeringID *string `json:"awsPeeringUid,omitempty"`
VPCId *string `json:"vpcUid,omitempty"`
VPCCidrs []*string `json:"vpcCidrs,omitempty"`
VPCCidr *string `json:"vpcCidr,omitempty"`
GCPProjectUID *string `json:"vpcProjectUid,omitempty"`
NetworkName *string `json:"vpcNetworkName,omitempty"`
RedisProjectUID *string `json:"redisProjectUid,omitempty"`
RedisNetworkName *string `json:"redisNetworkName,omitempty"`
CloudPeeringID *string `json:"cloudPeeringId,omitempty"`
SourceRegion *string `json:"sourceRegion,omitempty"`
DestinationRegion *string `json:"destinationRegion,omitempty"`
}

func (o ActiveActiveVPCPeering) String() string {
return internal.ToString(o)
}

type listSubscriptionResponse struct {
Subscriptions []*Subscription `json:"subscriptions"`
}
Expand Down Expand Up @@ -249,4 +299,7 @@ const (
VPCPeeringStatusPendingAcceptance = "pending-acceptance"
// Failed value of the `Status` field in `VPCPeering`
VPCPeeringStatusFailed = "failed"

SubscriptionDeploymentTypeSingleRegion = "single-region"
SubscriptionDeploymentTypeActiveActive = "active-active"
)
46 changes: 45 additions & 1 deletion service/subscriptions/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,33 @@ func (a *API) ListVPCPeering(ctx context.Context, id int) ([]*VPCPeering, error)
return peering.Peerings, nil
}

func (a *API) ListActiveActiveVPCPeering(ctx context.Context, id int) ([]*ActiveActiveVpcRegion, error) {
var task taskResponse
err := a.client.Get(ctx, fmt.Sprintf("get peerings for subscription %d", id), fmt.Sprintf("/subscriptions/%d/regions/peerings/", id), &task)
if err != nil {
return nil, wrap404Error(id, err)
}

a.logger.Printf("Waiting for subscription %d peering details to be retrieved", id)

var peering listActiveActiveVpcPeering
err = a.task.WaitForResource(ctx, *task.ID, &peering)
if err != nil {
return nil, err
}

// add vpcCidr to vpcCidrs slice if it exists
for i, region := range peering.Regions {
for j, vpcPeering := range region.VPCPeerings {
if vpcPeering.VPCCidr != nil {
peering.Regions[i].VPCPeerings[j].VPCCidrs = append(peering.Regions[i].VPCPeerings[j].VPCCidrs, vpcPeering.VPCCidr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking, is there a chance that the api will have the same cidr return in both the VPCCidr and VPCCidrs fields? e.g.
VPCCidr = "0.0.0.0/0" and VPCCidrs - ["0.0.0.0/0"] ?

In this case this function would return
.VPCCidrs = ["0.0.0.0/0", "0.0.0.0/0"]

However I do think the API returns
VPCCidr = null if there are multiple VPCCidrs
OR
VPCCidr = and VPCCidrs = null if there is only one cidr

If the above is correct, then I think the function is perfect as is, otherwise it may need a check to avoid two duplicate CIDRs in the VPCCidrs field. Does that make sense?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@greg-oc I believe that's the case, as it wouldn't make sense to have both fields set 👍🏼

}
}
}

return peering.Regions, nil
}

// CreateVPCPeering creates a new VPC peering from the subscription VPC and returns the identifier of the VPC peering.
func (a *API) CreateVPCPeering(ctx context.Context, id int, create CreateVPCPeering) (int, error) {
var task taskResponse
Expand All @@ -188,7 +215,7 @@ func (a *API) CreateVPCPeering(ctx context.Context, id int, create CreateVPCPeer
return id, nil
}

func (a *API) CreateActiveActiveVPCPeering(ctx context.Context, id int, create CreateVPCPeering) (int, error) {
func (a *API) CreateActiveActiveVPCPeering(ctx context.Context, id int, create CreateActiveActiveVPCPeering) (int, error) {
var task taskResponse
err := a.client.Post(ctx, fmt.Sprintf("create peering for subscription %d", id), fmt.Sprintf("/subscriptions/%d/regions/peerings/", id), create, &task)
if err != nil {
Expand Down Expand Up @@ -223,6 +250,23 @@ func (a *API) DeleteVPCPeering(ctx context.Context, subscription int, peering in
return nil
}

func (a *API) DeleteActiveActiveVPCPeering(ctx context.Context, subscription int, peering int) error {
var task taskResponse
err := a.client.Delete(ctx, fmt.Sprintf("deleting peering %d for subscription %d", peering, subscription), fmt.Sprintf("/subscriptions/%d/regions/peerings/%d", subscription, peering), &task)
if err != nil {
return err
}

a.logger.Printf("Waiting for peering %d for subscription %d to be deleted", peering, subscription)

err = a.task.Wait(ctx, *task.ID)
if err != nil {
return err
}

return nil
}

func wrap404Error(id int, err error) error {
if v, ok := err.(*internal.HTTPError); ok && v.StatusCode == http.StatusNotFound {
return &NotFound{id: id}
Expand Down