Code Monkey home page Code Monkey logo

megaportgo's Introduction

Megaport Go

Go Reference

Overview

This is the Megaport Go Library. It allows users to orchestrate the creation of Megaport Services.

Before using this library, please ensure you read Megaport's Terms and Conditions.

The Megaport API Documentation is also available online.

Getting started

package main

import (
	"context"
	"fmt"

	megaport "github.com/megaport/megaportgo"
)

// Create a new client using your credentials and interact with the Megaport API
func main() {
	// Creates a new client using the default HTTP cleint with the specified credentials against the staging environment
	client, err := megaport.New(nil,
		megaport.WithCredentials("ACCESS_KEY", "SECRET_KEY"),
		megaport.WithEnvironment(megaport.EnvironmentStaging),
	)
	if err != nil {
		// ...
	}

	// Authorize the client using the client's credentials
	authInfo, err := client.Authorize(context.TODO())
	if err != nil {
		// ...
	}
	fmt.Println(authInfo.AccessToken)
	fmt.Println(authInfo.Expiration) // You can use the expiration here to reauthorize the client when your access token expires

	// After you have authorized you can interact with the API
	locations, err := client.LocationService.ListLocations(context.TODO())
	if err != nil {
		// ...
	}

	for _, location := range locations {
		fmt.Println(location.Name)
	}
}

Testing

For mock tests go test ./...

To run integration tests against the Megaport API you will need to generate an API key

export MEGAPORT_ACCESS_KEY=YOUR_KEY
export MEGAPORT_SECRET_KEY=YOUR_KEY

go test -timeout 20m -integration ./... 

Contributing

Contributions via pull request are welcome. Familiarize yourself with these guidelines to increase the likelihood of your pull request being accepted.

All contributions are subject to the Megaport Contributor Licence Agreement. The CLA clarifies the terms of the Mozilla Public Licence 2.0 used to Open Source this respository and ensures that contributors are explictly informed of the conditions. Megaport requires all contributors to accept these terms to ensure that the Megaport Terraform Provider remains available and licensed for the community.

The main themes of the Megaport Contributor Licence Agreement cover the following conditions:

  • Clarifying the Terms of the Mozilla Public Licence 2.0, used to Open Source this project.
  • As a contributor, you have permission to agree to the License terms.
  • As a contributor, you are not obligated to provide support or warranty for your contributions.
  • Copyright is assigned to Megaport to use as Megaport determines, including within commercial products.
  • Grant of Patent Licence to Megaport for any contributions containing patented or future patented works.

The Megaport Contributor Licence Agreement is the authoritative document over these conditions and any other communications unless explicitly stated otherwise.

When you open a Pull Request, all authors of the contributions are required to comment on the Pull Request confirming acceptance of the CLA terms. Pull Requests can not be mMegaport_Contributor_Licence_Agreementerged until this is complete.

The Megaport Contributor Licence Agreement applies to contributions. All users are free to use the megaportgo project under the MPL-2.0 Open Source Licence.

Megaport users are also bound by the Acceptable Use Policy.

Getting Started

Prior to working on new code, review the Open Issues. Check whether your issue has already been raised, and consider working on an issue with votes or clear demand.

If you don't see an open issue for your need, open one and let others know what you are working on. Avoid lengthy or complex changes that rewrite the repository or introduce breaking changes. Straightforward pull requests based on discussion or ideas and Megaport feedback are the most likely to be accepted.

Megaport is under no obligation to accept any pull requests or to accept them in full. You are free to fork and modify the code for your own use as long is it is published under the MPL-2.0 License.

Notes

What's new in V1

The new V1 release of the megaportgo project has several changes users should be aware of:

  • All API methods now take context
  • More configurable
    • Custom HTTP client support
    • Structured logging is configurable and is handled using the slog package
  • Documentation is improved
  • Errors are easier to work with and are defined at the package level
  • All APIs are now available in the megaport package rather than multiple packages in the service directory
  • General code cleanup and linting rule enforcement
  • Missing types have been implemented

megaportgo's People

Contributors

aszynkow avatar cpuid avatar dannybarnes avatar ianb-mp avatar kdw174 avatar mega-alex avatar mega-nick avatar megaportphilipbrowne avatar mp1-nathan-grey avatar ngarratt avatar steve-exley avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

megaportgo's Issues

X-Auth Token End of Support

It looks like X-Auth token support, used by the current megaportgo (and terraform provider), will be disabled on September 30 2023.

Is there a plan to implement oauth2 before then?

No `GetPorts` function

It would be nice to be able to get the list of ports with a simple function call.

Will submit a pair of PRs here shortly to add this functionality.

Remove dependency on terraform

vxc.go depends on github.com/hashicorp/terraform-plugin-sdk/helper/schema for reasons which are not clear to me.

I propose moving the MarshallMcrAEndConfig function to the downstream project terraform-provider-megaport.

I have written a couple of fairly trivial patches to both projects to make this happen.

Will submit PRs shortly. If this is undesirable for some reason please let me know.

Removing the dependency on terraform was not simply an aesthetic issue for me. I am in the process of generating a pulumi module from the megaport terraform module. Conflicting versions of terraform were causing difficulty for me and correcting them was made more difficult by the fact that this project also depends on terraform.

VXC service provisioning times out - make configurable by callers

When provisioning a VXC circuit for Azure we regularly encounter timeouts requiring us to re-run our automation before it is completely provisioned. We would like the ability to specify a longer timeout than the hard-coded 15 minutes.

I'd propose adding a second function that accepts a context.Context that can be configured by the caller for an arbitrary timeout based on the caller's needs. I've also added a pollFrequency to specify how frequently it queries for the VxcDetails, currently hard-coded to 30 seconds.

func (v *VXC) WaitForVXCProvisioningCtx(ctx context.Context, pollFrequency time.Duration, vxcId string) (bool, error) { ...}

and

func (v *VXC) WaitForVXCUpdatedCtx(
	ctx context.Context, pollFrequency time.Duration, id string, name string, rateLimit int, aEndVLAN int, bEndVLAN int,
) (bool, error) { ... }

The existing functions can be modified to simply create a context with a 15 minute timeout and call the new functions, preserving the API and current behavior for existing users.

// WaitForVXCProvisioning waits up to 15 minutes for the VXC to reach the "LIVE" status.
// See WaitForVXCProvisioningCtx
func (v *VXC) WaitForVXCProvisioning(vxcId string) (bool, error) {
	ctx, cancelFunc := context.WithTimeout(context.Background(), 15*time.Minute)
	defer cancelFunc()
	return v.WaitForVXCProvisioningCtx(ctx, 30*time.Second, vxcId)
}

PR to follow.

A corresponding change will be proposed for the terraform-provider-megaport project to call the new APIs.

[req] Support for the telemetry API

Will this library be extended to include support for other non-terraform related APIs such as telemetry or log data?

I was interested in finding (or writing) a megaport exporter for Prometheus and was hoping that the library exposed those API methods.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.