Skip to content

Commit

Permalink
Merge pull request #72 from megaport/fix/mve-vendorConfig-cleanup
Browse files Browse the repository at this point in the history
cleanup: remove unnecessary switch case in createMVEOrder
  • Loading branch information
MegaportPhilipBrowne authored Sep 16, 2024
2 parents e88686a + d8e1261 commit 154af0b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 104 deletions.
90 changes: 7 additions & 83 deletions mve.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,93 +158,17 @@ func (svc *MVEServiceOp) ValidateMVEOrder(ctx context.Context, req *BuyMVEReques

func createMVEOrder(req *BuyMVERequest) []*MVEOrderConfig {
order := &MVEOrderConfig{
LocationID: req.LocationID,
Name: req.Name,
Term: req.Term,
PromoCode: req.PromoCode,
CostCentre: req.CostCentre,
ProductType: strings.ToUpper(PRODUCT_MVE),
LocationID: req.LocationID,
Name: req.Name,
Term: req.Term,
PromoCode: req.PromoCode,
CostCentre: req.CostCentre,
VendorConfig: req.VendorConfig,
ProductType: strings.ToUpper(PRODUCT_MVE),
Config: MVEConfig{
DiversityZone: req.DiversityZone,
},
}
switch c := req.VendorConfig.(type) {
case *ArubaConfig:
order.VendorConfig = &ArubaConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
AccountName: c.AccountName,
AccountKey: c.AccountKey,
}
case *CiscoConfig:
order.VendorConfig = &CiscoConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
AdminSSHPublicKey: c.AdminSSHPublicKey,
SSHPublicKey: c.SSHPublicKey,
ManageLocally: c.ManageLocally,
CloudInit: c.CloudInit,
FMCIPAddress: c.FMCIPAddress,
FMCRegistrationKey: c.FMCRegistrationKey,
FMCNatID: c.FMCNatID,
}
case *FortinetConfig:
order.VendorConfig = &FortinetConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
AdminSSHPublicKey: c.AdminSSHPublicKey,
SSHPublicKey: c.SSHPublicKey,
LicenseData: c.LicenseData,
}
case *PaloAltoConfig:
order.VendorConfig = &PaloAltoConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
AdminSSHPublicKey: c.AdminSSHPublicKey,
SSHPublicKey: c.SSHPublicKey,
AdminPasswordHash: c.AdminPasswordHash,
LicenseData: c.LicenseData,
}
case *VersaConfig:
order.VendorConfig = &VersaConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
DirectorAddress: c.DirectorAddress,
ControllerAddress: c.ControllerAddress,
LocalAuth: c.LocalAuth,
RemoteAuth: c.RemoteAuth,
SerialNumber: c.SerialNumber,
}
case *VmwareConfig:
order.VendorConfig = &VmwareConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
AdminSSHPublicKey: c.AdminSSHPublicKey,
SSHPublicKey: c.SSHPublicKey,
VcoAddress: c.VcoAddress,
VcoActivationCode: c.VcoActivationCode,
}
case *MerakiConfig:
order.VendorConfig = &MerakiConfig{
Vendor: c.Vendor,
ImageID: c.ImageID,
ProductSize: c.ProductSize,
MVELabel: c.MVELabel,
Token: c.Token,
}
}

if len(req.Vnics) == 0 {
order.NetworkInterfaces = []MVENetworkInterface{{Description: "Data Plane", VLAN: 0}}
Expand Down
28 changes: 7 additions & 21 deletions mve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,9 @@ func (suite *MVEClientTestSuite) TestBuyMVE() {
mveSvc := suite.client.MVEService
productUid := "36b3f68e-2f54-4331-bf94-f8984449365f"
req := &BuyMVERequest{
Name: "test-mve",
Term: 12,
LocationID: 1,
VendorConfig: PaloAltoConfig{
ImageID: 32,
ProductSize: "SMALL",
Vendor: "palo alto",
AdminSSHPublicKey: "test-key",
AdminPasswordHash: "test-hash",
},
Name: "test-mve",
Term: 12,
LocationID: 1,
DiversityZone: "blue",
}
jblob := `{
Expand Down Expand Up @@ -132,17 +125,10 @@ func (suite *MVEClientTestSuite) TestBuyMVE() {
]
}`
mveOrder := []MVEOrderConfig{{
LocationID: req.LocationID,
Name: req.Name,
Term: req.Term,
ProductType: strings.ToUpper(PRODUCT_MVE),
VendorConfig: &PaloAltoConfig{
ImageID: 32,
ProductSize: "SMALL",
Vendor: "palo alto",
AdminSSHPublicKey: "test-key",
AdminPasswordHash: "test-hash",
},
LocationID: req.LocationID,
Name: req.Name,
Term: req.Term,
ProductType: strings.ToUpper(PRODUCT_MVE),
NetworkInterfaces: []MVENetworkInterface{{Description: "Data Plane", VLAN: 0}},
Config: MVEConfig{
DiversityZone: req.DiversityZone,
Expand Down

0 comments on commit 154af0b

Please sign in to comment.