Skip to content

Commit

Permalink
fix: support cost centre in buying MCR and Port, fix Marketplace Visi…
Browse files Browse the repository at this point in the history
…bility 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
  • Loading branch information
MegaportPhilipBrowne authored May 21, 2024
1 parent f5b697c commit e36b3aa
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 44 deletions.
7 changes: 6 additions & 1 deletion mcr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion mcr_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion mcr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions mcr_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand Down
7 changes: 4 additions & 3 deletions mve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion mve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
30 changes: 17 additions & 13 deletions port.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion port_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion port_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions port_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
2 changes: 1 addition & 1 deletion product.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion product_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
27 changes: 18 additions & 9 deletions vxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions vxc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 9 additions & 9 deletions vxc_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit e36b3aa

Please sign in to comment.