shared

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

The `shared` package is houses functions that are used throughout the entire Megaport Go Library. They are not meant for general use outside of the Library.

The `shared` package is houses functions that are used throughout the entire Megaport Go Library. They are not meant for general use outside of the Library.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DumpObject

func DumpObject(debugObject interface{})

DumpObject uses the spew library to output variable contents

func GenerateOneTimePassword

func GenerateOneTimePassword(credentials *credential.Credential) (string, error)

Generates a OTP using a Google Authenticator-compatible OTP Key. The field `one_time_password_key` must be set in your Megaport credentials file.

func GenerateRandomNumber

func GenerateRandomNumber(lowerBound int, upperBound int) int

GenerateRandomNumber generates a random number between an upper and lower bound.

func GenerateRandomVLAN

func GenerateRandomVLAN() int

func GetCurrentTimestamp

func GetCurrentTimestamp() int64

func GetSessionToken

func GetSessionToken(credentials *credential.Credential) error

GetSessionToken connects to the Megaport API, passes the saved username, password, and a generated OTP (if otp key is set). The Megaport API returns a session token which is then saved in the session token file. The Session Token is also stored in the environment variable `MEGAPORT_SESSION_TOKEN`.

func IsEmail

func IsEmail(emailAddress string) bool

func IsErrorResponse

func IsErrorResponse(response *http.Response, responseErr *error, expectedReturnCode int) (bool, error)

IsErrorResponse returns an error report if an error response is detected from the API.

func IsGuid

func IsGuid(guid string) bool

func MakeAPICall

func MakeAPICall(verb string, url string, body []byte) (*http.Response, error)

MakeAPICall is a wrapper for HTTP calls against the Megaport API. It simply requires HTTP Verb, a URL, and the body of the request encoded as a byte array. It also sets generic headers such as content types, user agent. It also ensures the authentication tokesns are in the request headers.

func PurchaseError

func PurchaseError(productID string, err error)

PurchaseError prints out details about a failed purchase.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL