From e36b3aa60e6a2f476f17918108dd70ca0d692131 Mon Sep 17 00:00:00 2001 From: MegaportPhilipBrowne <117773195+MegaportPhilipBrowne@users.noreply.github.com> Date: Tue, 21 May 2024 10:28:14 -0400 Subject: [PATCH] fix: support cost centre in buying MCR and Port, fix Marketplace Visibility so it doesn't omit in Product Update Calls, Fix A-End and B-End UID in VXC Update (#32) * fix: product marketplace visibility as pointer to bool so it doesnt get omitted, add support for cost centre in port creation, change a-end and b-end to strings * fix: support cost centre in buying mcr * fix: pass cost centre into port order and remove conditional * fix: marketplace visibility into pointer * fix: make mve always false marketplace visibility --- mcr.go | 7 ++++++- mcr_integration_test.go | 2 +- mcr_test.go | 2 +- mcr_types.go | 1 + mve.go | 7 ++++--- mve_test.go | 2 +- port.go | 30 +++++++++++++++++------------- port_integration_test.go | 2 +- port_test.go | 2 +- port_types.go | 1 + product.go | 2 +- product_test.go | 2 +- vxc.go | 27 ++++++++++++++++++--------- vxc_test.go | 4 ++-- vxc_types.go | 18 +++++++++--------- 15 files changed, 65 insertions(+), 44 deletions(-) diff --git a/mcr.go b/mcr.go index f6c81a9..093280f 100644 --- a/mcr.go +++ b/mcr.go @@ -48,6 +48,7 @@ type BuyMCRRequest struct { Term int PortSpeed int MCRAsn int + CostCentre string WaitForProvision bool // Wait until the MCR provisions before returning WaitForTime time.Duration // How long to wait for the MCR to provision if WaitForProvision is true (default is 5 minutes) @@ -74,7 +75,7 @@ type ModifyMCRRequest struct { MCRID string Name string CostCentre string - MarketplaceVisibility bool + MarketplaceVisibility *bool WaitForUpdate bool // Wait until the MCR updates before returning WaitForTime time.Duration // How long to wait for the MCR to update if WaitForUpdate is true (default is 5 minutes) @@ -118,6 +119,10 @@ func (svc *MCRServiceOp) BuyMCR(ctx context.Context, req *BuyMCRRequest) (*BuyMC Config: MCROrderConfig{}, } + if req.CostCentre != "" { + order.CostCentre = req.CostCentre + } + order.Config.ASN = req.MCRAsn mcrOrders := []MCROrder{ diff --git a/mcr_integration_test.go b/mcr_integration_test.go index d69aaff..ccbd28e 100644 --- a/mcr_integration_test.go +++ b/mcr_integration_test.go @@ -92,7 +92,7 @@ func (suite *MCRIntegrationTestSuite) TestMCRLifecycle() { MCRID: mcrId, Name: newMCRName, CostCentre: "", - MarketplaceVisibility: mcr.MarketplaceVisibility, + MarketplaceVisibility: &mcr.MarketplaceVisibility, WaitForUpdate: true, WaitForTime: 5 * time.Minute, }) diff --git a/mcr_test.go b/mcr_test.go index 0287348..80bacef 100644 --- a/mcr_test.go +++ b/mcr_test.go @@ -243,7 +243,7 @@ func (suite *MCRClientTestSuite) TestModifyMCR() { MCRID: productUid, Name: "test-mcr-updated", CostCentre: "US", - MarketplaceVisibility: false, + MarketplaceVisibility: PtrTo(false), } jblobGet := `{ "message": "Product [36b3f68e-2f54-4331-bf94-f8984449365f] has been updated", diff --git a/mcr_types.go b/mcr_types.go index 2e77ae9..f7cf064 100644 --- a/mcr_types.go +++ b/mcr_types.go @@ -8,6 +8,7 @@ type MCROrder struct { Term int `json:"term"` Type string `json:"productType"` PortSpeed int `json:"portSpeed"` + CostCentre string `json:"costCentre"` Config MCROrderConfig `json:"config"` } diff --git a/mve.go b/mve.go index 53f18da..b225942 100644 --- a/mve.go +++ b/mve.go @@ -55,8 +55,9 @@ type BuyMVEResponse struct { // ModifyMVERequest represents a request to modify an MVE type ModifyMVERequest struct { - MVEID string - Name string + MVEID string + Name string + MarketplaceVisibility *bool WaitForUpdate bool // Wait until the MCVEupdates before returning WaitForTime time.Duration // How long to wait for the MVE to update if WaitForUpdate is true (default is 5 minutes) @@ -255,7 +256,7 @@ func (svc *MVEServiceOp) ModifyMVE(ctx context.Context, req *ModifyMVERequest) ( ProductType: PRODUCT_MVE, Name: req.Name, CostCentre: "", - MarketplaceVisibility: false, + MarketplaceVisibility: PtrTo(false), } _, err := svc.Client.ProductService.ModifyProduct(ctx, modifyProductReq) if err != nil { diff --git a/mve_test.go b/mve_test.go index 06531bb..75a399f 100644 --- a/mve_test.go +++ b/mve_test.go @@ -415,7 +415,7 @@ func (suite *MVEClientTestSuite) TestModifyMVE() { ProductType: PRODUCT_MVE, Name: req.Name, CostCentre: "", - MarketplaceVisibility: false, + MarketplaceVisibility: PtrTo(false), } path := fmt.Sprintf("/v2/product/%s/%s", PRODUCT_MVE, productUid) suite.mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { diff --git a/port.go b/port.go index ac81fbd..80acdb1 100644 --- a/port.go +++ b/port.go @@ -52,6 +52,7 @@ type BuyPortRequest struct { LagCount int `json:"lagCount"` // A lag count of 1 or higher will order the port as a single LAG MarketPlaceVisibility bool `json:"marketPlaceVisibility"` DiversityZone string `json:"diversityZone"` + CostCentre string `json:"costCentre"` WaitForProvision bool // Wait until the VXC provisions before returning WaitForTime time.Duration // How long to wait for the VXC to provision if WaitForProvision is true (default is 5 minutes) @@ -71,7 +72,7 @@ type GetPortRequest struct { type ModifyPortRequest struct { PortID string Name string - MarketplaceVisibility bool + MarketplaceVisibility *bool CostCentre string WaitForUpdate bool // Wait until the Port updates before returning @@ -130,19 +131,22 @@ func (svc *PortServiceOp) BuyPort(ctx context.Context, req *BuyPortRequest) (*Bu if req.Term != 1 && req.Term != 12 && req.Term != 24 && req.Term != 36 { return nil, ErrInvalidTerm } + portOrder := PortOrder{ + Name: req.Name, + Term: req.Term, + ProductType: "MEGAPORT", + PortSpeed: req.PortSpeed, + LocationID: req.LocationId, + DiversityZone: req.DiversityZone, + Virtual: false, + Market: req.Market, + LagPortCount: req.LagCount, + MarketplaceVisibility: req.MarketPlaceVisibility, + CostCentre: req.CostCentre, + } + buyOrder = []PortOrder{ - { - Name: req.Name, - Term: req.Term, - ProductType: "MEGAPORT", - PortSpeed: req.PortSpeed, - LocationID: req.LocationId, - DiversityZone: req.DiversityZone, - Virtual: false, - Market: req.Market, - LagPortCount: req.LagCount, - MarketplaceVisibility: req.MarketPlaceVisibility, - }, + portOrder, } responseBody, responseError := svc.Client.ProductService.ExecuteOrder(ctx, buyOrder) diff --git a/port_integration_test.go b/port_integration_test.go index 22af077..e97db27 100644 --- a/port_integration_test.go +++ b/port_integration_test.go @@ -182,7 +182,7 @@ func (suite *PortIntegrationTestSuite) testModifyPort(c *Client, ctx context.Con PortID: portId, Name: newPortName, CostCentre: "", - MarketplaceVisibility: portInfo.MarketplaceVisibility, + MarketplaceVisibility: &portInfo.MarketplaceVisibility, WaitForUpdate: true, WaitForTime: 5 * time.Minute, }) diff --git a/port_test.go b/port_test.go index c4090f1..f2b5bc2 100644 --- a/port_test.go +++ b/port_test.go @@ -297,7 +297,7 @@ func (suite *PortClientTestSuite) TestModifyPort() { PortID: productUid, Name: "updated-test-product", CostCentre: "US", - MarketplaceVisibility: false, + MarketplaceVisibility: PtrTo(false), } jblob := `{ "message": "Product [36b3f68e-2f54-4331-bf94-f8984449365f] has been updated", diff --git a/port_types.go b/port_types.go index 1106f68..adbbffe 100644 --- a/port_types.go +++ b/port_types.go @@ -10,6 +10,7 @@ type PortOrder struct { CreateDate int64 `json:"createDate"` Virtual bool `json:"virtual"` Market string `json:"market"` + CostCentre string `json:"costCentre,omitempty"` LagPortCount int `json:"lagPortCount,omitempty"` MarketplaceVisibility bool `json:"marketplaceVisibility"` DiversityZone string `json:"diversityZone"` diff --git a/product.go b/product.go index 236c7ee..af67fa3 100644 --- a/product.go +++ b/product.go @@ -40,7 +40,7 @@ type ModifyProductRequest struct { ProductType string Name string `json:"name,omitempty"` CostCentre string `json:"costCentre,omitempty"` - MarketplaceVisibility bool `json:"marketplaceVisibility,omitempty"` + MarketplaceVisibility *bool `json:"marketplaceVisibility,omitempty"` } // ModifyProductResponse represents a response from the Megaport Products API after modifying a product. diff --git a/product_test.go b/product_test.go index 2437399..0cf7e1e 100644 --- a/product_test.go +++ b/product_test.go @@ -168,7 +168,7 @@ func (suite *ProductClientTestSuite) TestModifyProduct() { ProductType: productType, Name: "updated-test-product", CostCentre: "US", - MarketplaceVisibility: false, + MarketplaceVisibility: PtrTo(false), } path := fmt.Sprintf("/v2/product/%s/%s", productType, productUid) suite.mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { diff --git a/vxc.go b/vxc.go index 11a0d40..dbbdf66 100644 --- a/vxc.go +++ b/vxc.go @@ -226,15 +226,24 @@ func (svc *VXCServiceOp) UpdateVXC(ctx context.Context, id string, req *UpdateVX url := svc.Client.BaseURL.JoinPath(path).String() update := &VXCUpdate{ - Name: req.Name, - RateLimit: req.RateLimit, - AEndVLAN: req.AEndVLAN, - BEndVLAN: req.BEndVLAN, - AEndProductUID: req.AEndProductUID, - BEndProductUID: req.BEndProductUID, - Term: req.Term, - CostCentre: req.CostCentre, - Shutdown: req.Shutdown, + RateLimit: req.RateLimit, + AEndVLAN: req.AEndVLAN, + BEndVLAN: req.BEndVLAN, + Term: req.Term, + Shutdown: req.Shutdown, + } + + if req.Name != nil { + update.Name = *req.Name + } + if req.AEndProductUID != nil { + update.AEndProductUID = *req.AEndProductUID + } + if req.BEndProductUID != nil { + update.BEndProductUID = *req.BEndProductUID + } + if req.CostCentre != nil { + update.CostCentre = *req.CostCentre } clientReq, err := svc.Client.NewRequest(ctx, http.MethodPut, url, update) diff --git a/vxc_test.go b/vxc_test.go index af0790d..ecebe92 100644 --- a/vxc_test.go +++ b/vxc_test.go @@ -994,12 +994,12 @@ func (suite *VXCClientTestSuite) TestUpdateVXC() { }, } update := &VXCUpdate{ - Name: updateReq.Name, + Name: *updateReq.Name, RateLimit: updateReq.RateLimit, AEndVLAN: updateReq.AEndVLAN, BEndVLAN: updateReq.BEndVLAN, Shutdown: updateReq.Shutdown, - CostCentre: updateReq.CostCentre, + CostCentre: *updateReq.CostCentre, Term: updateReq.Term, } path := fmt.Sprintf("/v3/product/%s/%s", PRODUCT_VXC, vxcUid) diff --git a/vxc_types.go b/vxc_types.go index dc6c43d..79ef739 100644 --- a/vxc_types.go +++ b/vxc_types.go @@ -137,15 +137,15 @@ type Peer struct { // VXCUpdate represents the fields that can be updated on a VXC. type VXCUpdate struct { - Name *string `json:"name,omitempty"` - RateLimit *int `json:"rateLimit,omitempty"` - CostCentre *string `json:"costCentre,omitempty"` - Shutdown *bool `json:"shutdown,omitempty"` - AEndVLAN *int `json:"aEndVlan,omitempty"` - BEndVLAN *int `json:"bEndVlan,omitempty"` - AEndProductUID *string `json:"aEndProductUid,omitempty"` - BEndProductUID *string `json:"bEndProductUid,omitempty"` - Term *int `json:"term,omitempty"` + Name string `json:"name,omitempty"` + RateLimit *int `json:"rateLimit,omitempty"` + CostCentre string `json:"costCentre,omitempty"` + Shutdown *bool `json:"shutdown,omitempty"` + AEndVLAN *int `json:"aEndVlan,omitempty"` + BEndVLAN *int `json:"bEndVlan,omitempty"` + AEndProductUID string `json:"aEndProductUid,omitempty"` + BEndProductUID string `json:"bEndProductUid,omitempty"` + Term *int `json:"term,omitempty"` } // VXCOrderResponse represents the response from the VXC Order API.