Skip to content

Commit

Permalink
Merge pull request #87 from megaport/fix/serviceKeyId
Browse files Browse the repository at this point in the history
fix: add support in service key resource for both port uid and port id
  • Loading branch information
MegaportPhilipBrowne authored Dec 4, 2024
2 parents 2ac515a + eafd219 commit 361bf83
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions service_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package megaport
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log/slog"
Expand Down Expand Up @@ -60,8 +61,9 @@ type ServiceKey struct {

// CreateServiceKeyRequest represents a request to create a service key from the Megaport Service Key API.
type CreateServiceKeyRequest struct {
ProductUID string `json:"productUid"` // The Port for the service key.
SingleUse bool `json:"singleUse"` // Determines whether to create a single-use or multi-use service key. Valid values are true (single-use) and false (multi-use). With a multi-use key, the customer that you share the key with can request multiple connections using that key. For single-use keys only, specify a VLAN ID (vlan).
ProductUID string `json:"productUid,omitempty"` // The Port ID for the service key. API can take either UID or ID.
ProductID int `json:"productId,omitempty"` // The Port UID for the service key. API can take either UID or ID.
SingleUse bool `json:"singleUse"` // Determines whether to create a single-use or multi-use service key. Valid values are true (single-use) and false (multi-use). With a multi-use key, the customer that you share the key with can request multiple connections using that key. For single-use keys only, specify a VLAN ID (vlan).
MaxSpeed int `json:"maxSpeed"`
Active bool `json:"active,omitempty"` // Determines whether the service key is available for use. Valid values are true if you want the key to be available right away and false if you don’t want the key to be available right away.
PreApproved bool `json:"preApproved,omitempty"` // Whether the service key is pre-approved for use.
Expand Down Expand Up @@ -127,10 +129,11 @@ type ListServiceKeysResponse struct {
// UpdateServiceKeyRequest represents a request to update a service key in the Megaport Service Key API.
type UpdateServiceKeyRequest struct {
Key string `json:"key"`
ProductID int `json:"productId"` // The Port for the service key.
SingleUse bool `json:"singleUse"` // Determines whether the service key is single-use or multi-use. Valid values are true (single-use) and false (multi-use). With a multi-use key, the customer that you share the key with can request multiple connections using that key.
Active bool `json:"active"` // Determines whether the service key is available for use. Valid values are true if you want the key to be available right away and false if you don’t want the key to be available right away.
OrderValidFor *OrderValidFor `json:"validFor,omitempty"` // The range of dates for which the service key is valid.
ProductUID string `json:"productUid,omitempty"` // The Product UID for the service key. API can take either UID or ID.
ProductID int `json:"productId,omitempty"` // The Product ID for the service key. API can take either UID or ID.
SingleUse bool `json:"singleUse"` // Determines whether the service key is single-use or multi-use. Valid values are true (single-use) and false (multi-use). With a multi-use key, the customer that you share the key with can request multiple connections using that key.
Active bool `json:"active"` // Determines whether the service key is available for use. Valid values are true if you want the key to be available right away and false if you don’t want the key to be available right away.
OrderValidFor *OrderValidFor `json:"validFor,omitempty"` // The range of dates for which the service key is valid.
ValidFor *ValidFor
}

Expand All @@ -141,6 +144,9 @@ type UpdateServiceKeyResponse struct {

// CreateServiceKey creates a service key in the Megaport Service Key API.
func (svc *ServiceKeyServiceOp) CreateServiceKey(ctx context.Context, req *CreateServiceKeyRequest) (*CreateServiceKeyResponse, error) {
if req.ProductID != 0 && req.ProductUID != "" {
return nil, errors.New("ProductID and ProductUID cannot both be set")
}
if req.ValidFor != nil {
req.OrderValidFor = &OrderValidFor{
Start: req.ValidFor.StartTime.Unix() * 1000,
Expand Down Expand Up @@ -256,6 +262,9 @@ func (svc *ServiceKeyServiceOp) GetServiceKey(ctx context.Context, keyId string)
}

func (svc *ServiceKeyServiceOp) UpdateServiceKey(ctx context.Context, req *UpdateServiceKeyRequest) (*UpdateServiceKeyResponse, error) {
if req.ProductID != 0 && req.ProductUID != "" {
return nil, errors.New("ProductID and ProductUID cannot both be set")
}
path := "/v2/service/key"
url := svc.Client.BaseURL.JoinPath(path).String()
if req.ValidFor != nil {
Expand Down

0 comments on commit 361bf83

Please sign in to comment.