Skip to content

Commit

Permalink
fix partner interconnect attachment json request response (#796)
Browse files Browse the repository at this point in the history
* fix json request response

* VPC-3920: fix local asn req json
  • Loading branch information
apinonformoso authored Feb 27, 2025
1 parent 8a2012e commit 8d24e45
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
54 changes: 52 additions & 2 deletions partner_interconnect_attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package godo

import (
"context"
"encoding/json"
"fmt"
"net/http"
"time"
Expand Down Expand Up @@ -60,7 +61,7 @@ type partnerInterconnectAttachmentRequestBody struct {
// VPCIDs is the IDs of the VPCs to which the Partner Interconnect Attachment is connected
VPCIDs []string `json:"vpc_ids,omitempty"`
// BGP is the BGP configuration of the Partner Interconnect Attachment
BGP *BGP `json:"bgp,omitempty"`
BGP *BGPInput `json:"bgp,omitempty"`
}

func (req *PartnerInterconnectAttachmentCreateRequest) buildReq() *partnerInterconnectAttachmentRequestBody {
Expand All @@ -73,7 +74,13 @@ func (req *PartnerInterconnectAttachmentCreateRequest) buildReq() *partnerInterc
}

if req.BGP != (BGP{}) {
request.BGP = &req.BGP
request.BGP = &BGPInput{
LocalASN: req.BGP.LocalASN,
LocalRouterIP: req.BGP.LocalRouterIP,
PeerASN: req.BGP.PeerASN,
PeerRouterIP: req.BGP.PeerRouterIP,
AuthKey: req.BGP.AuthKey,
}
}

return request
Expand All @@ -99,6 +106,49 @@ type BGP struct {
// LocalRouterIP is the local router IP
LocalRouterIP string `json:"local_router_ip,omitempty"`
// PeerASN is the peer ASN
PeerASN int `json:"peer_asn,omitempty"`
// PeerRouterIP is the peer router IP
PeerRouterIP string `json:"peer_router_ip,omitempty"`
// AuthKey is the authentication key
AuthKey string `json:"auth_key,omitempty"`
}

func (b *BGP) UnmarshalJSON(data []byte) error {
type Alias BGP
aux := &struct {
LocalASN *int `json:"local_asn,omitempty"`
LocalRouterASN *int `json:"local_router_asn,omitempty"`
PeerASN *int `json:"peer_asn,omitempty"`
PeerRouterASN *int `json:"peer_router_asn,omitempty"`
*Alias
}{
Alias: (*Alias)(b),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}

if aux.LocalASN != nil {
b.LocalASN = *aux.LocalASN
} else if aux.LocalRouterASN != nil {
b.LocalASN = *aux.LocalRouterASN
}

if aux.PeerASN != nil {
b.PeerASN = *aux.PeerASN
} else if aux.PeerRouterASN != nil {
b.PeerASN = *aux.PeerRouterASN
}
return nil
}

// BGPInput represents the BGP configuration of a Partner Interconnect Attachment.
type BGPInput struct {
// LocalASN is the local ASN
LocalASN int `json:"local_router_asn,omitempty"`
// LocalRouterIP is the local router IP
LocalRouterIP string `json:"local_router_ip,omitempty"`
// PeerASN is the peer ASN
PeerASN int `json:"peer_router_asn,omitempty"`
// PeerRouterIP is the peer router IP
PeerRouterIP string `json:"peer_router_ip,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion partner_interconnect_attachments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ var vInterconnectTestJSON = `
"bgp":{
"local_asn":64532,
"local_router_ip":"169.250.0.1",
"peer_router_asn":133937,
"peer_asn":133937,
"peer_router_ip":"169.250.0.6",
"auth_key":"my-auth-key"
},
Expand Down

0 comments on commit 8d24e45

Please sign in to comment.