From f7948bb221bd0145f68e3e02b3ea8fc6f0e512be Mon Sep 17 00:00:00 2001 From: Alberto Pinon Formoso Date: Wed, 26 Feb 2025 09:21:31 -0600 Subject: [PATCH 1/2] fix json request response --- partner_interconnect_attachments.go | 54 +++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/partner_interconnect_attachments.go b/partner_interconnect_attachments.go index 3ac05c7..dcb8ab6 100644 --- a/partner_interconnect_attachments.go +++ b/partner_interconnect_attachments.go @@ -2,6 +2,7 @@ package godo import ( "context" + "encoding/json" "fmt" "net/http" "time" @@ -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 { @@ -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 @@ -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"` From 6e46cd038d3324388692ccfe6efaf7c44f895674 Mon Sep 17 00:00:00 2001 From: Alberto Pinon Formoso Date: Thu, 27 Feb 2025 09:49:57 -0600 Subject: [PATCH 2/2] VPC-3920: fix local asn req json --- partner_interconnect_attachments_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/partner_interconnect_attachments_test.go b/partner_interconnect_attachments_test.go index d104b3d..10eddd7 100644 --- a/partner_interconnect_attachments_test.go +++ b/partner_interconnect_attachments_test.go @@ -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" },