Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix partner interconnect attachment json request response #796

Merged
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
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{
Copy link
Member

Choose a reason for hiding this comment

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

Would the tests need to be updated to reflect this change as well?
https://github.com/digitalocean/godo/blob/main/partner_interconnect_attachments_test.go#L22

Copy link
Contributor Author

Choose a reason for hiding this comment

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

true, the update should be the json response of the request.
Done 6e46cd0

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