go-client-mongodb-ops-manager

module
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2020 License: Apache-2.0

README

MongoDB Ops Manager Go Client

Build Status

An HTTP client for Ops Manager and Cloud Manager Public API endpoints.

You can view the Official API docs at:

Installation

To get the latest version run this command:

go get github.com/mongodb/go-client-mongodb-ops-manager

Usage

import "github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"

Authentication

The Ops Manager API uses HTTP Digest Authentication. Provide your PUBLIC_KEY as the username and PRIVATE_KEY as the password as part of the HTTP request. See how to set up public API access for more information.

We use the following library to get HTTP Digest Auth:

Example Usage

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/Sectorbob/mlab-ns2/gae/ns/digest"
	"github.com/mongodb/go-client-mongodb-ops-manager/opsmngr"
)

func newClient(publicKey, privateKey string) (*mongodbatlas.Client, error) {

	// Setup a transport to handle digest
	transport := digest.NewTransport(publicKey, privateKey)

	// Initialize the client
	client, err := transport.Client()
	if err != nil {
		return nil, err
	}

	//Initialize the MongoDB API Client.
	return opsmngr.NewClient(client), nil
}

func main() {
	publicKey := os.Getenv("MONGODB_PUBLIC_KEY")
	privateKey := os.Getenv("MONGODB_PRIVATE_KEY")
	projectID := os.Getenv("MONGODB_PROJECT_ID")

	if publicKey == "" || privateKey == "" || projectID == "" {
		log.Fatalln("MONGODB_PUBLIC_KEY, MONGODB_PRIVATE_KEY and MONGODB_PROJECT_ID must be set to run this example")
	}

	client, err := newClient(publicKey, privateKey)
	if err != nil {
		log.Fatalf(err.Error())
	}

	atmStatus, _, err := client.AutomationStatus.Get(context.Background(), projectID)

	if err != nil {
		log.Fatalf(err.Error())
	}

	fmt.Printf("%+v \n", atmStatus)

}

Roadmap

This library is being initially developed for mongocli, so API methods will likely be implemented in the order that they are needed by that application.

Contributing

See our CONTRIBUTING.md Guide.

License

MongoDB Ops Manager Go Client is released under the Apache 2.0 license. See LICENSE

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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