README.md
1# go-client-mongodb-atlas [![Build Status](https://travis-ci.org/mongodb/go-client-mongodb-atlas.svg?branch=master)](https://travis-ci.org/mongodb/go-client-mongodb-atlas)
2
3A Go HTTP client for the [MongoDB Atlas API](https://docs.atlas.mongodb.com/api/).
4
5You can view the Official API docs here: https://docs.atlas.mongodb.com/api/
6
7## Installation
8
9To get the latest version run this command:
10
11```sh
12go get github.com/mongodb/go-client-mongodb-atlas
13```
14
15## Usage
16
17```go
18import "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
19```
20
21## Authentication
22
23The Atlas API uses [HTTP Digest Authentication](https://docs.atlas.mongodb.com/api/#api-authentication). Provide your Atlas PUBLIC_KEY as the username and PRIVATE_KEY as the password as part of the HTTP request. See Programmatic API Keys docs for more detailed information: https://docs.atlas.mongodb.com/configure-api-access/#atlas-prog-api-key.
24
25We use the following library to get HTTP Digest Auth:
26
27https://github.com/Sectorbob/mlab-ns2/gae/ns/digest
28
29## Example Usage
30
31```go
32package main
33
34import (
35 "context"
36 "fmt"
37 "log"
38 "os"
39
40 "github.com/Sectorbob/mlab-ns2/gae/ns/digest"
41 "github.com/mongodb/go-client-mongodb-atlas/mongodbatlas"
42)
43
44func newClient(publicKey, privateKey string) (*mongodbatlas.Client, error) {
45
46 //Setup a transport to handle digest
47 transport := digest.NewTransport(publicKey, privateKey)
48
49 //Initialize the client
50 client, err := transport.Client()
51 if err != nil {
52 return nil, err
53 }
54
55 //Initialize the MongoDB Atlas API Client.
56 return mongodbatlas.NewClient(client), nil
57}
58
59func main() {
60 publicKey := os.Getenv("MONGODB_ATLAS_PUBLIC_KEY")
61 privateKey := os.Getenv("MONGODB_ATLAS_PRIVATE_KEY")
62 projectID := os.Getenv("MONGODB_ATLAS_PROJECT_ID")
63
64 if publicKey == "" || privateKey == "" || projectID == "" {
65 log.Fatalln("MONGODB_ATLAS_PROJECT_ID, MONGODB_ATLAS_PUBLIC_KEY and MONGODB_ATLAS_PRIVATE_KEY must be set to run this example")
66 }
67
68 client, err := newClient(publicKey, privateKey)
69 if err != nil {
70 log.Fatalf(err.Error())
71 }
72
73 clusters, _, err := client.Clusters.List(context.Background(), projectID, nil)
74
75 if err != nil {
76 log.Fatalf(err.Error())
77 }
78
79 fmt.Printf("%+v \n", clusters)
80
81}
82```
83
84## Versioning
85Each version of the client is tagged and the version is updated accordingly.
86
87To see the list of past versions, run `git tag`.
88
89
90## Development and contribution
91
92Feel free to open an Issue or PR! Our contribution guidelines are a WIP but generally follow the official [Terraform Guidelines](https://www.terraform.io/docs/extend/community/contributing.html).
93
94```
95git clone git@github.com:mongodb/go-client-mongodb-atlas.git
96make tools
97make check
98```
99