Coder Social home page Coder Social logo

mongodb / go-client-mongodb-ops-manager Goto Github PK

View Code? Open in Web Editor NEW
14.0 21.0 14.0 754 KB

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

Home Page: https://pkg.go.dev/go.mongodb.org/ops-manager

License: Apache License 2.0

Makefile 0.20% Go 99.80%
mongodb mongodb-ops-manager mongodb-cloud-manager golang hacktoberfest

go-client-mongodb-ops-manager's Introduction

MongoDB Ops Manager Go Client

Go Reference CI Go Report Card

A go client for Ops Manager and Cloud Manager API.

Note that ops-manager only supports the two most recent major versions of Go.

Usage

import "go.mongodb.org/ops-manager/opsmngr"

Construct a new Ops Manager client, then use the various services on the client to access different parts of the Ops Manager API. For example:

client := opsmngr.NewClient(nil)

The services of a client divide the API into logical chunks and correspond to the structure of the Ops Manager API documentation.

NOTE: Using the context package, one can easily pass cancellation signals and deadlines to various services of the client for handling a request. In case there is no context available, then context.Background() can be used as a starting point.

Authentication

The ops-manager library does not directly handle authentication. Instead, when creating a new client, pass an http.Client that can handle Digest Access authentication for you. The easiest way to do this is using the digest library, but you can always use any other library that provides an http.Client. If you have a private and public API token pair, you can use it with the digest library using:

import (
	"context"
	"log"

	"github.com/mongodb-forks/digest"
	"go.mongodb.org/ops-manager/opsmngr"
)

func main() {
	t := digest.NewTransport("your public key", "your private key")
	tc, err := t.Client()
	if err != nil {
		log.Fatalf(err.Error())
	}

	// Note: If no Base URL is set the client is set to work with Cloud Manager by default
	clientops := opsmngr.SetBaseURL("https://opsmanagerurl/" + opsmngr.APIPublicV1Path)
	client, err := opsmngr.New(tc, clientops)
	if err != nil {
		log.Fatalf(err.Error())
	}

	orgs, _, err := client.Organizations.List(context.Background(), nil)
}

Note that when using an authenticated Client, all calls made by the client will include the specified tokens. Therefore, authenticated clients should almost never be shared between different users.

To get your API Keys please refer to our docs for, Ops Manager, or Cloud Manager.

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

go-client-mongodb-ops-manager's People

Contributors

0xmh avatar andreaangiolillo avatar colm-quinn avatar dependabot[bot] avatar fc-c avatar fmenezes avatar gssbzn avatar mihaibojin avatar mpilar avatar robcarlan-mlab avatar ruhickey avatar sunny-b avatar svagner avatar threebee avatar tibulca avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-client-mongodb-ops-manager's Issues

Unable to connect Ops Manager using Public API

Hi Team,

I am unable to access ops manager using public API.I am getting below error.

curl --user '{XXX}:{XXX}' --digest --header 'Accept: application/json' --include --request GET ":/api/public/v1.0/groups?pretty=true"

Content-Type: application/json
Content-Length: 106

{
"reason" : "Unauthorized",
"error" : 401,
"detail" : "You are not authorized for this resource."
}

Thanks!!

Invalid JSON Attribut

Hi,

I've got the error "INVALID_JSON_ATTRIBUT" on my API PUT call can someone support me?

`t := digest.NewTransport("", "private-key")
tc, err := t.Client()
if err != nil {
log.Fatalf(err.Error())
}
clientops := opsmngr.SetBaseURL("<OpsManager_URL>")
client, err := opsmngr.New(tc, clientops)
if err != nil {
log.Fatalf(err.Error())
} else {
fmt.Println("running")
}

var projectId string
fmt.Println("Please enter the projectID")
fmt.Scanln(&projectId)

a, _, err := client.Automation.GetConfig(context.Background(), projectId)
if err != nil {
	log.Fatal(err)
}

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

roles := make([]*opsmngr.Role, 2)

var r1 opsmngr.Role
r1.Role = "clusterMonitor"
r1.Database = "admin"

var r2 opsmngr.Role
r2.Role = "readAnyDatabase"
r2.Database = "admin"

roles = append(roles, &r1, &r2)

var u opsmngr.MongoDBUser
u.Database = "admin"
u.Password = RandStringRunes(20)
u.Roles = roles
u.Username = "mongomirror"

a.Auth.UsersWanted = append(a.Auth.UsersWanted, &u)

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

_, err = client.Automation.UpdateConfig(context.Background(), projectId, a)
if err != nil {
	log.Fatal(err)
}`

Thanks,
Pascal

Use interface instead of http.client

Describe the bug
I would like to mock the raw requests I do via the http.client but the opsmngr.client only takes the direct struct.
Is it possible to create an interface and add that as parameter. i.e.

type HttpClient interface {
	Do(req *http.Request) (*http.Response, error)
}

Missing Force property from opsmngr.AutomationConfig.ReplicaSets

Describe the bug

Missing replicaSets[n].force property in the replicaset automation config for opsmngr.

Expected behavior
opsmngr.AutomationConfig.ReplicaSets[*].Force to exist.

Screenshots
N/A

Desktop (please complete the following information):
Irrelevant but

  • OS: macOS
  • Lib Version: master
  • Product: OpsManager

Getting 500 error attempting to update the automation config

Describe the bug
I have created a project/group and am now trying to update the automation config to create the processes/replicaset and I am getting an error. I have even tried to use the jsonBlob (https://github.com/mongodb/go-client-mongodb-ops-manager/blob/master/opsmngr/automation_config_test.go#L26) from your test case and that also reports a 500. Weirdly, I can also get it into a state where it tells me that members in my replicaset "must have priority 0 when not eligible to become primary" so maybe that is a clue to what is going on.

Basic reproduction:
Create a project
Unmarshal the jsonBlob into an AutomationConfig object
Attempt to apply the AutomationConfig to the project

Note: I did confirm that I am passing the correct project id.

Expected behavior
I would expect either a validation error if something was wrong, or for it to work.

Desktop (please complete the following information):

  • OS: macOS

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.