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

To include projectId attribute(optional)in CVD,Create DLG, Create ACL template, Create SSH Public Key APIs #28

Merged
merged 5 commits into from
Feb 5, 2024
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
24 changes: 14 additions & 10 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ type Device struct {
ASN *int
ZoneCode *string
ClusterDetails *ClusterDetails
ProjectID *string
}

// DeviceInterface describes Network Edge device interface
Expand Down Expand Up @@ -358,10 +359,11 @@ type BGPConfiguration struct {

// SSHPublicKey describes Network Edge SSH user public key
type SSHPublicKey struct {
UUID *string
Name *string
Value *string
Type *string
UUID *string
Name *string
Value *string
Type *string
ProjectID *string
}

// ACLTemplate describes Network Edge device ACL template
Expand All @@ -374,6 +376,7 @@ type ACLTemplate struct {
DeviceACLStatus *string
InboundRules []ACLTemplateInboundRule
DeviceDetails []ACLTemplateDeviceDetails
ProjectID *string
}

// ACLTemplateInboundRule describes inbound ACL rule that is part of
Expand Down Expand Up @@ -412,12 +415,13 @@ type DeviceACLDetails struct {

// DeviceLinkGroup describes details of a device link group
type DeviceLinkGroup struct {
UUID *string
Name *string
Subnet *string
Status *string
Devices []DeviceLinkGroupDevice
Links []DeviceLinkGroupLink
UUID *string
Name *string
Subnet *string
ProjectID *string
Status *string
Devices []DeviceLinkGroupDevice
Links []DeviceLinkGroupLink
}

// DeviceLinkGroupDevice describes details of a device within device
Expand Down
9 changes: 5 additions & 4 deletions internal/api/acltemplate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package api

//ACLTemplate describes Network Edge device ACL template
// ACLTemplate describes Network Edge device ACL template
type ACLTemplate struct {
UUID *string `json:"uuid,omitempty"`
Name *string `json:"name,omitempty"`
Expand All @@ -10,10 +10,11 @@ type ACLTemplate struct {
DeviceACLStatus *string `json:"deviceAclstatus,omitempty"`
InboundRules []ACLTemplateInboundRule `json:"inboundRules,omitempty"`
DeviceDetails []ACLTemplateDeviceDetails `json:"virtualDeviceDetails,omitempty"`
ProjectID *string `json:"projectId,omitempty"`
}

//ACLTemplateInboundRule describes inbound ACL rule that is part of
//Network Edge device ACL template
// ACLTemplateInboundRule describes inbound ACL rule that is part of
// Network Edge device ACL template
type ACLTemplateInboundRule struct {
SrcType *string `json:"srcType,omitempty"`
Protocol *string `json:"protocol,omitempty"`
Expand All @@ -31,7 +32,7 @@ type ACLTemplateDeviceDetails struct {
ACLStatus *string `json:"aclStatus,omitempty"`
}

//ACLTemplatesResponse describes response for a get ACL template collection request
// ACLTemplatesResponse describes response for a get ACL template collection request
type ACLTemplatesResponse struct {
Pagination Pagination `json:"pagination,omitempty"`
Data []ACLTemplate `json:"data,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions internal/api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Device struct {
ZoneCode *string `json:"zoneCode,omitempty"`
ClusterDetails *ClusterDetails `json:"clusterDetails,omitempty"`
Connectivity *string `json:"connectivity,omitempty"`
ProjectID *string `json:"projectId,omitempty"`
}

// DeviceRequest describes network edge device creation request
Expand Down Expand Up @@ -75,6 +76,7 @@ type DeviceRequest struct {
Secondary *SecondaryDeviceRequest `json:"secondary,omitempty"`
ClusterDetails *ClusterDetailsRequest `json:"clusterDetails,omitempty"`
Connectivity *string `json:"connectivity,omitempty"`
ProjectID *string `json:"projectId,omitempty"`
}

// SecondaryDeviceRequest describes secondary device part of device creation request
Expand Down
1 change: 1 addition & 0 deletions internal/api/device_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type DeviceLinkGroup struct {
Status *string `json:"status,omitempty"`
Devices []DeviceLinkGroupDevice `json:"linkDevices,omitempty"`
Links []DeviceLinkGroupLink `json:"links"`
ProjectID *string `json:"projectId,omitempty"`
}

type DeviceLinkGroupUpdateRequest struct {
Expand Down
11 changes: 6 additions & 5 deletions internal/api/sshkey.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package api

//SSHPublicKey describes SSH public key
// SSHPublicKey describes SSH public key
type SSHPublicKey struct {
UUID *string `json:"uuid,omitempty"`
KeyName *string `json:"keyName,omitempty"`
KeyValue *string `json:"keyValue,omitempty"`
KeyType *string `json:"keyType,omitempty"`
UUID *string `json:"uuid,omitempty"`
KeyName *string `json:"keyName,omitempty"`
KeyValue *string `json:"keyValue,omitempty"`
KeyType *string `json:"keyType,omitempty"`
ProjectID *string `json:"projectId,omitempty"`
}
16 changes: 9 additions & 7 deletions rest_acltemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/equinix/rest-go"
)

//CreateACLTemplate creates new ACL template with a given model
//On successful creation, template's UUID is returned
// CreateACLTemplate creates new ACL template with a given model
// On successful creation, template's UUID is returned
func (c RestClient) CreateACLTemplate(template ACLTemplate) (*string, error) {
path := "/ne/v1/aclTemplates"
reqBody := mapACLTemplateDomainToAPI(template)
Expand All @@ -25,7 +25,7 @@ func (c RestClient) CreateACLTemplate(template ACLTemplate) (*string, error) {
return uuid, nil
}

//GetACLTemplates retrieves list of all ACL templates along with their details
// GetACLTemplates retrieves list of all ACL templates along with their details
func (c RestClient) GetACLTemplates() ([]ACLTemplate, error) {
path := "/ne/v1/aclTemplates"
content, err := c.GetOffsetPaginated(path, &api.ACLTemplatesResponse{},
Expand All @@ -40,7 +40,7 @@ func (c RestClient) GetACLTemplates() ([]ACLTemplate, error) {
return transformed, nil
}

//GetACLTemplate retrieves ACL template with a given UUID
// GetACLTemplate retrieves ACL template with a given UUID
func (c RestClient) GetACLTemplate(uuid string) (*ACLTemplate, error) {
path := "/ne/v1/aclTemplates/" + url.PathEscape(uuid)
respBody := api.ACLTemplate{}
Expand All @@ -52,8 +52,8 @@ func (c RestClient) GetACLTemplate(uuid string) (*ACLTemplate, error) {
return &template, nil
}

//ReplaceACLTemplate replaces ACL template under given UUID with
//a new one with a given model
// ReplaceACLTemplate replaces ACL template under given UUID with
// a new one with a given model
func (c RestClient) ReplaceACLTemplate(uuid string, template ACLTemplate) error {
path := "/ne/v1/aclTemplates/" + url.PathEscape(uuid)
updateTemplate := ACLTemplate{
Expand All @@ -70,7 +70,7 @@ func (c RestClient) ReplaceACLTemplate(uuid string, template ACLTemplate) error
return nil
}

//DeleteACLTemplate removes ACL template with a given UUID
// DeleteACLTemplate removes ACL template with a given UUID
func (c RestClient) DeleteACLTemplate(uuid string) error {
path := "/ne/v1/aclTemplates/" + url.PathEscape(uuid)
if err := c.Execute(c.R(), http.MethodDelete, path); err != nil {
Expand All @@ -87,6 +87,7 @@ func mapACLTemplateDomainToAPI(template ACLTemplate) api.ACLTemplate {
MetroCode: template.MetroCode,
DeviceACLStatus: template.DeviceACLStatus,
InboundRules: mapACLTemplateInboundRulesDomainToAPI(template.InboundRules),
ProjectID: template.ProjectID,
}
}

Expand Down Expand Up @@ -120,6 +121,7 @@ func mapACLTemplateAPIToDomain(apiTemplate api.ACLTemplate) ACLTemplate {
DeviceACLStatus: apiTemplate.DeviceACLStatus,
InboundRules: mapACLTemplateInboundRulesAPIToDomain(apiTemplate.InboundRules),
DeviceDetails: mapACLTemplateDeviceDetailsAPIToDomain(apiTemplate.DeviceDetails),
ProjectID: apiTemplate.ProjectID,
}
}

Expand Down
10 changes: 9 additions & 1 deletion rest_acltemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ var testACLTemplate = ACLTemplate{
Name: String("test"),
Description: String("Test ACL"),
MetroCode: String("SV"),
ProjectID: String("68ccfd49-39b1-478e-957a-67c72f719d7a"),
InboundRules: []ACLTemplateInboundRule{
{
SrcType: String("SUBNET"),
Expand Down Expand Up @@ -122,7 +123,7 @@ func TestGetACLTemplate(t *testing.T) {
func TestReplaceACLTemplate(t *testing.T) {
//given
templateID := "db66bf49-b2d8-4e64-8719-d46406b54039"
template := testACLTemplate
template := updateACLRequestPayload()
reqBody := api.ACLTemplate{}
testHc := &http.Client{}
httpmock.ActivateNonDefault(testHc)
Expand Down Expand Up @@ -163,6 +164,7 @@ func TestDeleteACLTemplate(t *testing.T) {
}

func verifyACLTemplate(t *testing.T, template ACLTemplate, apiTemplate api.ACLTemplate) {
assert.Equal(t, template.ProjectID, apiTemplate.ProjectID, "ProjectID matches")
assert.Equal(t, template.UUID, apiTemplate.UUID, "UUID matches")
assert.Equal(t, template.Name, apiTemplate.Name, "Name matches")
assert.Equal(t, template.Description, apiTemplate.Description, "Description matches")
Expand Down Expand Up @@ -192,3 +194,9 @@ func verifyACLTemplateDeviceDetails(t *testing.T, template ACLTemplate, apiTempl
assert.Equal(t, template.DeviceDetails[i].ACLStatus, apiTemplate.DeviceDetails[i].ACLStatus, "ACL Status matches")
}
}

func updateACLRequestPayload() ACLTemplate {
updateRequestPayload := testACLTemplate
updateRequestPayload.ProjectID = nil
return updateRequestPayload
}
2 changes: 2 additions & 0 deletions rest_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ func mapDeviceAPIToDomain(apiDevice api.Device) *Device {
device.RedundancyType = apiDevice.RedundancyType
device.RedundantUUID = apiDevice.RedundantUUID
device.TermLength = apiDevice.TermLength
device.ProjectID = apiDevice.ProjectID
device.AdditionalBandwidth = apiDevice.AdditionalBandwidth
device.WanInterfaceId = apiDevice.SshInterfaceID
device.OrderReference = apiDevice.OrderReference
Expand Down Expand Up @@ -395,6 +396,7 @@ func createDeviceRequest(device Device) api.DeviceRequest {
}
}
req.Connectivity = device.Connectivity
req.ProjectID = device.ProjectID
req.Core = device.CoreCount
req.AdditionalBandwidth = device.AdditionalBandwidth
req.SshInterfaceId = device.WanInterfaceId
Expand Down
20 changes: 11 additions & 9 deletions rest_device_link.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ type restDeviceLinkUpdateRequest struct {
c RestClient
}

//GetDeviceLinkGroups retrieves list of existing device link groups
//(along with their details)
// GetDeviceLinkGroups retrieves list of existing device link groups
// (along with their details)
func (c RestClient) GetDeviceLinkGroups() ([]DeviceLinkGroup, error) {
path := "/ne/v1/links"
content, err := c.GetOffsetPaginated(path, &api.DeviceLinkGroupsGetResponse{},
Expand All @@ -34,8 +34,8 @@ func (c RestClient) GetDeviceLinkGroups() ([]DeviceLinkGroup, error) {
return transformed, nil
}

//GetDeviceLinkGroups retrieves details of a device link group
//with a given identifier
// GetDeviceLinkGroups retrieves details of a device link group
// with a given identifier
func (c RestClient) GetDeviceLinkGroup(uuid string) (*DeviceLinkGroup, error) {
path := "/ne/v1/links/" + url.PathEscape(uuid)
result := api.DeviceLinkGroup{}
Expand All @@ -46,8 +46,8 @@ func (c RestClient) GetDeviceLinkGroup(uuid string) (*DeviceLinkGroup, error) {
return mapDeviceLinkGroupAPIToDomain(result), nil
}

//CreateDeviceLinkGroup creates given device link group and returns
//its identifier upon successful creation
// CreateDeviceLinkGroup creates given device link group and returns
// its identifier upon successful creation
func (c RestClient) CreateDeviceLinkGroup(linkGroup DeviceLinkGroup) (*string, error) {
path := "/ne/v1/links"
reqBody := mapDeviceLinkGroupDomainToAPI(linkGroup)
Expand All @@ -59,13 +59,13 @@ func (c RestClient) CreateDeviceLinkGroup(linkGroup DeviceLinkGroup) (*string, e
return respBody.UUID, nil
}

//NewDeviceLinkGroupUpdateRequest creates new update request for a device link
//group with a given identifier
// NewDeviceLinkGroupUpdateRequest creates new update request for a device link
// group with a given identifier
func (c RestClient) NewDeviceLinkGroupUpdateRequest(uuid string) DeviceLinkUpdateRequest {
return &restDeviceLinkUpdateRequest{uuid: uuid, c: c}
}

//DeleteDeviceLinkGroup removes device link group with a given identifier
// DeleteDeviceLinkGroup removes device link group with a given identifier
func (c RestClient) DeleteDeviceLinkGroup(uuid string) error {
path := "/ne/v1/links/" + url.PathEscape(uuid)
if err := c.Execute(c.R(), http.MethodDelete, path); err != nil {
Expand Down Expand Up @@ -128,6 +128,7 @@ func mapDeviceLinkGroupAPIToDomain(apiLinkGroup api.DeviceLinkGroup) *DeviceLink
linkGroup.Name = apiLinkGroup.GroupName
linkGroup.Subnet = apiLinkGroup.Subnet
linkGroup.Status = apiLinkGroup.Status
linkGroup.ProjectID = apiLinkGroup.ProjectID
linkGroup.Devices = make([]DeviceLinkGroupDevice, len(apiLinkGroup.Devices))
for i := range apiLinkGroup.Devices {
linkGroup.Devices[i] = mapDeviceLinkGroupDeviceAPIToDomain(apiLinkGroup.Devices[i])
Expand Down Expand Up @@ -165,6 +166,7 @@ func mapDeviceLinkGroupDomainToAPI(linkGroup DeviceLinkGroup) api.DeviceLinkGrou
apiLinkGroup := api.DeviceLinkGroup{}
apiLinkGroup.GroupName = linkGroup.Name
apiLinkGroup.Subnet = linkGroup.Subnet
apiLinkGroup.ProjectID = linkGroup.ProjectID
apiLinkGroup.Devices = make([]api.DeviceLinkGroupDevice, len(linkGroup.Devices))
for i := range linkGroup.Devices {
apiLinkGroup.Devices[i] = mapDeviceLinkGroupDeviceDomainToAPI(linkGroup.Devices[i])
Expand Down
1 change: 1 addition & 0 deletions rest_device_link_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ func verifyDeviceLinkGroup(t *testing.T, linkGroup DeviceLinkGroup, apiLinkGroup
assert.Equal(t, apiLinkGroup.GroupName, linkGroup.Name, "GroupName matches")
assert.Equal(t, apiLinkGroup.Subnet, linkGroup.Subnet, "Subnet matches")
assert.Equal(t, len(apiLinkGroup.Devices), len(linkGroup.Devices), "Length of []Devices matches")
assert.Equal(t, apiLinkGroup.ProjectID, linkGroup.ProjectID, "Project ID matches")
for i := range apiLinkGroup.Devices {
verifyDeviceLinkGroupDevice(t, linkGroup.Devices[i], apiLinkGroup.Devices[i])
}
Expand Down
2 changes: 2 additions & 0 deletions rest_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var testDevice = Device{
Notifications: []string{"[email protected]", "[email protected]"},
PackageCode: String("VM100"),
TermLength: Int(24),
ProjectID: String("68ccfd49-39b1-478e-957a-67c72f719d7a"),
Throughput: Int(1),
ThroughputUnit: String("Gbps"),
Name: String("PaloAltoSRmy"),
Expand Down Expand Up @@ -501,6 +502,7 @@ func verifyDeviceRequest(t *testing.T, device Device, req api.DeviceRequest) {
assert.Equal(t, device.TypeCode, req.DeviceTypeCode, "TypeCode matches")
termLengthStr := strconv.Itoa(*device.TermLength)
assert.Equal(t, &termLengthStr, req.TermLength, "TermLength matches")
assert.Equal(t, device.ProjectID, req.ProjectID, "Project Id matches")
if *device.IsBYOL {
assert.Equal(t, DeviceLicenseModeBYOL, StringValue(req.LicenseMode), "LicenseMode matches")
} else {
Expand Down
26 changes: 14 additions & 12 deletions rest_sshkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/equinix/ne-go/internal/api"
)

//GetSSHPublicKeys retrieves list of available SSH public keys
// GetSSHPublicKeys retrieves list of available SSH public keys
func (c RestClient) GetSSHPublicKeys() ([]SSHPublicKey, error) {
path := "/ne/v1/publicKeys"
respBody := make([]api.SSHPublicKey, 0)
Expand All @@ -18,7 +18,7 @@ func (c RestClient) GetSSHPublicKeys() ([]SSHPublicKey, error) {
return mapSSHPublicKeysAPIToDomain(respBody), nil
}

//GetSSHPublicKey retrieves SSH public key with a given identifier
// GetSSHPublicKey retrieves SSH public key with a given identifier
func (c RestClient) GetSSHPublicKey(uuid string) (*SSHPublicKey, error) {
path := "/ne/v1/publicKeys/" + url.PathEscape(uuid)
respBody := api.SSHPublicKey{}
Expand All @@ -30,7 +30,7 @@ func (c RestClient) GetSSHPublicKey(uuid string) (*SSHPublicKey, error) {
return &mapped, nil
}

//CreateSSHPublicKey creates new SSH public key with a given details
// CreateSSHPublicKey creates new SSH public key with a given details
func (c RestClient) CreateSSHPublicKey(key SSHPublicKey) (*string, error) {
path := "/ne/v1/publicKeys"
reqBody := mapSSHPublicKeyDomainToAPI(key)
Expand All @@ -46,7 +46,7 @@ func (c RestClient) CreateSSHPublicKey(key SSHPublicKey) (*string, error) {
return uuid, nil
}

//DeleteSSHPublicKey removes SSH Public key with given identifier
// DeleteSSHPublicKey removes SSH Public key with given identifier
func (c RestClient) DeleteSSHPublicKey(uuid string) error {
path := "/ne/v1/publicKeys/" + url.PathEscape(uuid)
if err := c.Execute(c.R(), http.MethodDelete, path); err != nil {
Expand All @@ -65,18 +65,20 @@ func mapSSHPublicKeysAPIToDomain(apiKeys []api.SSHPublicKey) []SSHPublicKey {

func mapSSHPublicKeyAPIToDomain(apiKey api.SSHPublicKey) SSHPublicKey {
return SSHPublicKey{
UUID: apiKey.UUID,
Name: apiKey.KeyName,
Value: apiKey.KeyValue,
Type: apiKey.KeyType,
UUID: apiKey.UUID,
Name: apiKey.KeyName,
Value: apiKey.KeyValue,
Type: apiKey.KeyType,
ProjectID: apiKey.ProjectID,
}
}

func mapSSHPublicKeyDomainToAPI(key SSHPublicKey) api.SSHPublicKey {
return api.SSHPublicKey{
UUID: key.UUID,
KeyName: key.Name,
KeyValue: key.Value,
KeyType: key.Type,
UUID: key.UUID,
KeyName: key.Name,
KeyValue: key.Value,
KeyType: key.Type,
ProjectID: key.ProjectID,
}
}
Loading
Loading