From fefe585bb9ea8f7ae445ff2841a323d71fb2da34 Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne Date: Tue, 17 Sep 2024 12:43:27 -0400 Subject: [PATCH 1/6] feat: allow for vrouter partner config in update vxc call --- vxc.go | 24 ++++++++++++++++++++++++ vxc_types.go | 3 +++ 2 files changed, 27 insertions(+) diff --git a/vxc.go b/vxc.go index 7044f3b..0dc7a02 100644 --- a/vxc.go +++ b/vxc.go @@ -3,6 +3,7 @@ package megaport import ( "context" "encoding/json" + "errors" "fmt" "io" "net/http" @@ -90,6 +91,9 @@ type UpdateVXCRequest struct { AEndInnerVLAN *int BEndInnerVLAN *int + AEndPartnerConfig VXCPartnerConfiguration + BEndPartnerConfig VXCPartnerConfiguration + WaitForUpdate bool // Wait until the VXC updates before returning WaitForTime time.Duration // How long to wait for the VXC to update if WaitForUpdate is true (default is 5 minutes) } @@ -286,6 +290,26 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX update.BEndInnerVLAN = req.BEndInnerVLAN } + if req.AEndPartnerConfig != nil { + partnerConfig := req.AEndPartnerConfig + switch partnerConfig.(type) { + case *VXCOrderVrouterPartnerConfig: + update.BEndPartnerConfig = partnerConfig + default: + return nil, errors.New("b end partner config type not supported") + } + } + + if req.BEndPartnerConfig != nil { + partnerConfig := req.BEndPartnerConfig + switch partnerConfig.(type) { + case *VXCOrderVrouterPartnerConfig: + update.AEndPartnerConfig = partnerConfig + default: + return nil, errors.New("b end partner config type not supported") + } + } + clientReq, err := svc.Client.NewRequest(ctx, http.MethodPut, url, update) if err != nil { return nil, err diff --git a/vxc_types.go b/vxc_types.go index 1f39da9..8e9cd0d 100644 --- a/vxc_types.go +++ b/vxc_types.go @@ -189,6 +189,9 @@ type VXCUpdate struct { AEndProductUID string `json:"aEndProductUid,omitempty"` BEndProductUID string `json:"bEndProductUid,omitempty"` Term *int `json:"term,omitempty"` + + AEndPartnerConfig VXCPartnerConfiguration `json:"aEndConfig,omitempty"` + BEndPartnerConfig VXCPartnerConfiguration `json:"bEndConfig,omitempty"` } // VXCOrderResponse represents the response from the VXC Order API. From 941e8d58d5b0304c991982f3c898c0b40aa9a8d2 Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne Date: Tue, 17 Sep 2024 12:44:36 -0400 Subject: [PATCH 2/6] fix: misnamed a end partner config --- vxc.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vxc.go b/vxc.go index 0dc7a02..de0c28f 100644 --- a/vxc.go +++ b/vxc.go @@ -296,7 +296,7 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX case *VXCOrderVrouterPartnerConfig: update.BEndPartnerConfig = partnerConfig default: - return nil, errors.New("b end partner config type not supported") + return nil, errors.New("a end partner config type not supported") } } From b9916d4cb0847aba81b371f350103fd13ecfa478 Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne Date: Tue, 17 Sep 2024 12:45:11 -0400 Subject: [PATCH 3/6] fix: better error msg --- vxc.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/vxc.go b/vxc.go index de0c28f..76a259c 100644 --- a/vxc.go +++ b/vxc.go @@ -296,7 +296,7 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX case *VXCOrderVrouterPartnerConfig: update.BEndPartnerConfig = partnerConfig default: - return nil, errors.New("a end partner config type not supported") + return nil, errors.New("a end partner config type not supported for VXC update") } } @@ -306,7 +306,7 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX case *VXCOrderVrouterPartnerConfig: update.AEndPartnerConfig = partnerConfig default: - return nil, errors.New("b end partner config type not supported") + return nil, errors.New("b end partner config type not supported for VXC update") } } From 071966afb209d793753eb8471f6fbd2bc6b20ead Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne Date: Fri, 20 Sep 2024 11:04:25 -0400 Subject: [PATCH 4/6] fix: support other partner configurations for updating vxc --- vxc.go | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/vxc.go b/vxc.go index 76a259c..8efd2c0 100644 --- a/vxc.go +++ b/vxc.go @@ -3,7 +3,6 @@ package megaport import ( "context" "encoding/json" - "errors" "fmt" "io" "net/http" @@ -264,11 +263,13 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX url := svc.Client.BaseURL.JoinPath(path).String() update := &VXCUpdate{ - RateLimit: req.RateLimit, - AEndVLAN: req.AEndVLAN, - BEndVLAN: req.BEndVLAN, - Term: req.Term, - Shutdown: req.Shutdown, + RateLimit: req.RateLimit, + AEndVLAN: req.AEndVLAN, + BEndVLAN: req.BEndVLAN, + Term: req.Term, + Shutdown: req.Shutdown, + AEndPartnerConfig: req.AEndPartnerConfig, + BEndPartnerConfig: req.BEndPartnerConfig, } if req.Name != nil { @@ -290,26 +291,6 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX update.BEndInnerVLAN = req.BEndInnerVLAN } - if req.AEndPartnerConfig != nil { - partnerConfig := req.AEndPartnerConfig - switch partnerConfig.(type) { - case *VXCOrderVrouterPartnerConfig: - update.BEndPartnerConfig = partnerConfig - default: - return nil, errors.New("a end partner config type not supported for VXC update") - } - } - - if req.BEndPartnerConfig != nil { - partnerConfig := req.BEndPartnerConfig - switch partnerConfig.(type) { - case *VXCOrderVrouterPartnerConfig: - update.AEndPartnerConfig = partnerConfig - default: - return nil, errors.New("b end partner config type not supported for VXC update") - } - } - clientReq, err := svc.Client.NewRequest(ctx, http.MethodPut, url, update) if err != nil { return nil, err From 1416c21e137766f1143afff1b5fe7d87422e112b Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne Date: Thu, 26 Sep 2024 11:23:17 -0400 Subject: [PATCH 5/6] fix: only allow aend or vrouter partner config for aend and only vrouter for bend in vxc updates --- errors.go | 6 ++++++ vxc.go | 28 +++++++++++++++++++++------- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/errors.go b/errors.go index 88c6c33..18e5ab7 100644 --- a/errors.go +++ b/errors.go @@ -66,3 +66,9 @@ var ErrManagedAccountNotFound = errors.New("managed account not found") // ErrInvalidVLAN is returned when a VLAN is invalid var ErrInvalidVLAN = errors.New("invalid VLAN, must be between 0 and 4094") + +// ErrInvalidVXCAEndPartnerConfig is returned when an invalid VXC A-End partner config is provided +var ErrInvalidVXCAEndPartnerConfig = errors.New("invalid vxc a-end partner config") + +// ErrInvalidVXCBEndPartnerConfig is returned when an invalid VXC B-End partner config is provided +var ErrInvalidVXCBEndPartnerConfig = errors.New("invalid vxc b-end partner config") diff --git a/vxc.go b/vxc.go index 8efd2c0..44940aa 100644 --- a/vxc.go +++ b/vxc.go @@ -263,13 +263,27 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX url := svc.Client.BaseURL.JoinPath(path).String() update := &VXCUpdate{ - RateLimit: req.RateLimit, - AEndVLAN: req.AEndVLAN, - BEndVLAN: req.BEndVLAN, - Term: req.Term, - Shutdown: req.Shutdown, - AEndPartnerConfig: req.AEndPartnerConfig, - BEndPartnerConfig: req.BEndPartnerConfig, + RateLimit: req.RateLimit, + AEndVLAN: req.AEndVLAN, + BEndVLAN: req.BEndVLAN, + Term: req.Term, + Shutdown: req.Shutdown, + } + + // Only allow AENdPartnerConfig or VROUTER Partner Config for AEndPartnerConfig in VXC Updates + switch req.AEndPartnerConfig.(type) { + case VXCPartnerConfiguration, VXCOrderVrouterPartnerConfig: + update.AEndPartnerConfig = req.AEndPartnerConfig + default: + return nil, ErrInvalidVXCAEndPartnerConfig + } + + // Only allow Vrouter Partner Config for BEndPartnerConfig in VXC Updates + switch req.BEndPartnerConfig.(type) { + case VXCOrderVrouterPartnerConfig: + update.BEndPartnerConfig = req.BEndPartnerConfig + default: + return nil, ErrInvalidVXCBEndPartnerConfig } if req.Name != nil { From 508032b89c75cc5e13eca3ed5ca5fa1483b755f3 Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne Date: Thu, 26 Sep 2024 11:25:11 -0400 Subject: [PATCH 6/6] fix: add nil check for partner configs --- vxc.go | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/vxc.go b/vxc.go index 44940aa..9c1162a 100644 --- a/vxc.go +++ b/vxc.go @@ -270,20 +270,24 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX Shutdown: req.Shutdown, } - // Only allow AENdPartnerConfig or VROUTER Partner Config for AEndPartnerConfig in VXC Updates - switch req.AEndPartnerConfig.(type) { - case VXCPartnerConfiguration, VXCOrderVrouterPartnerConfig: - update.AEndPartnerConfig = req.AEndPartnerConfig - default: - return nil, ErrInvalidVXCAEndPartnerConfig - } - - // Only allow Vrouter Partner Config for BEndPartnerConfig in VXC Updates - switch req.BEndPartnerConfig.(type) { - case VXCOrderVrouterPartnerConfig: - update.BEndPartnerConfig = req.BEndPartnerConfig - default: - return nil, ErrInvalidVXCBEndPartnerConfig + if req.AEndPartnerConfig != nil { + // Only allow AENdPartnerConfig or VROUTER Partner Config for AEndPartnerConfig in VXC Updates + switch req.AEndPartnerConfig.(type) { + case VXCPartnerConfiguration, VXCOrderVrouterPartnerConfig: + update.AEndPartnerConfig = req.AEndPartnerConfig + default: + return nil, ErrInvalidVXCAEndPartnerConfig + } + } + + if req.BEndPartnerConfig != nil { + // Only allow Vrouter Partner Config for BEndPartnerConfig in VXC Updates + switch req.BEndPartnerConfig.(type) { + case VXCOrderVrouterPartnerConfig: + update.BEndPartnerConfig = req.BEndPartnerConfig + default: + return nil, ErrInvalidVXCBEndPartnerConfig + } } if req.Name != nil {