From e6576324bb0a85d56c8a651eeb13462eb3ca2d51 Mon Sep 17 00:00:00 2001 From: PacoDw <__pm@outlook.com> Date: Mon, 25 Nov 2019 12:30:04 -0600 Subject: [PATCH] chore: referenced to master branch of the MongoDB client chore: using errorstring chore: updating vendor --- go.mod | 3 +- go.sum | 2 + ...esource_mongodbatlas_maintenance_window.go | 2 +- vendor/github.com/go-test/deep/.gitignore | 2 + vendor/github.com/go-test/deep/.travis.yml | 13 + vendor/github.com/go-test/deep/CHANGES.md | 9 + vendor/github.com/go-test/deep/LICENSE | 21 ++ vendor/github.com/go-test/deep/README.md | 51 +++ vendor/github.com/go-test/deep/deep.go | 352 ++++++++++++++++++ .../mongodbatlas/clusters.go | 55 +++ .../mongodbatlas/maintenance.go | 136 +++++++ .../mongodbatlas/mongodbatlas.go | 2 + vendor/modules.txt | 4 +- 13 files changed, 649 insertions(+), 3 deletions(-) create mode 100644 vendor/github.com/go-test/deep/.gitignore create mode 100644 vendor/github.com/go-test/deep/.travis.yml create mode 100644 vendor/github.com/go-test/deep/CHANGES.md create mode 100644 vendor/github.com/go-test/deep/LICENSE create mode 100644 vendor/github.com/go-test/deep/README.md create mode 100644 vendor/github.com/go-test/deep/deep.go create mode 100644 vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/maintenance.go diff --git a/go.mod b/go.mod index c6b111169c..e004a28b13 100644 --- a/go.mod +++ b/go.mod @@ -4,9 +4,10 @@ go 1.12 require ( github.com/Sectorbob/mlab-ns2 v0.0.0-20171030222938-d3aa0c295a8a + github.com/go-test/deep v1.0.1 github.com/hashicorp/hcl v0.0.0-20180404174102-ef8a98b0bbce // indirect github.com/hashicorp/terraform v0.12.1 - github.com/mongodb/go-client-mongodb-atlas v0.1.1 + github.com/mongodb/go-client-mongodb-atlas v0.1.2-0.20191125173016-a644c761794e github.com/mwielbut/pointy v1.1.0 github.com/spf13/cast v1.3.0 ) diff --git a/go.sum b/go.sum index f203d67320..001840177a 100644 --- a/go.sum +++ b/go.sum @@ -233,6 +233,8 @@ github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/I github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/mongodb/go-client-mongodb-atlas v0.1.1 h1:L7eaGSvw1raCQF69N/tlYWAyyJRIJpdyqK6d90BtQ74= github.com/mongodb/go-client-mongodb-atlas v0.1.1/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= +github.com/mongodb/go-client-mongodb-atlas v0.1.2-0.20191125173016-a644c761794e h1:BZMjHAfy2ppKGSq+mJwJyYQSmKHyeiNgwradSVVa/zc= +github.com/mongodb/go-client-mongodb-atlas v0.1.2-0.20191125173016-a644c761794e/go.mod h1:LS8O0YLkA+sbtOb3fZLF10yY3tJM+1xATXMJ3oU35LU= github.com/mwielbut/pointy v1.1.0 h1:U5/YEfoIkaGCHv0St3CgjduqXID4FNRoyZgLM1kY9vg= github.com/mwielbut/pointy v1.1.0/go.mod h1:MvvO+uMFj9T5DMda33HlvogsFBX7pWWKAkFIn4teYwY= github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJEU3ofeGjhHklVoIGuVj85JJwZ6kWPaJwCIxgnFmo= diff --git a/mongodbatlas/resource_mongodbatlas_maintenance_window.go b/mongodbatlas/resource_mongodbatlas_maintenance_window.go index f7d32aa1f6..dea54be45a 100644 --- a/mongodbatlas/resource_mongodbatlas_maintenance_window.go +++ b/mongodbatlas/resource_mongodbatlas_maintenance_window.go @@ -166,7 +166,7 @@ func resourceMongoDBAtlasMaintenanceWindowUpdate(d *schema.ResourceData, meta in _, err := conn.MaintenanceWindows.Update(context.Background(), d.Id(), maintenanceWindowReq) if err != nil { - return fmt.Errorf(errorMaintenanceRead, d.Id(), err) + return fmt.Errorf(errorMaintenanceUpdate, d.Id(), err) } return nil diff --git a/vendor/github.com/go-test/deep/.gitignore b/vendor/github.com/go-test/deep/.gitignore new file mode 100644 index 0000000000..53f12f0f0e --- /dev/null +++ b/vendor/github.com/go-test/deep/.gitignore @@ -0,0 +1,2 @@ +*.swp +*.out diff --git a/vendor/github.com/go-test/deep/.travis.yml b/vendor/github.com/go-test/deep/.travis.yml new file mode 100644 index 0000000000..2279c61427 --- /dev/null +++ b/vendor/github.com/go-test/deep/.travis.yml @@ -0,0 +1,13 @@ +language: go + +go: + - 1.7 + - 1.8 + - 1.9 + +before_install: + - go get github.com/mattn/goveralls + - go get golang.org/x/tools/cover + +script: + - $HOME/gopath/bin/goveralls -service=travis-ci diff --git a/vendor/github.com/go-test/deep/CHANGES.md b/vendor/github.com/go-test/deep/CHANGES.md new file mode 100644 index 0000000000..4351819d68 --- /dev/null +++ b/vendor/github.com/go-test/deep/CHANGES.md @@ -0,0 +1,9 @@ +# go-test/deep Changelog + +## v1.0.1 released 2018-01-28 + +* Fixed #12: Arrays are not properly compared (samlitowitz) + +## v1.0.0 releaesd 2017-10-27 + +* First release diff --git a/vendor/github.com/go-test/deep/LICENSE b/vendor/github.com/go-test/deep/LICENSE new file mode 100644 index 0000000000..228ef16f74 --- /dev/null +++ b/vendor/github.com/go-test/deep/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright 2015-2017 Daniel Nichter + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/go-test/deep/README.md b/vendor/github.com/go-test/deep/README.md new file mode 100644 index 0000000000..3b78eac7c1 --- /dev/null +++ b/vendor/github.com/go-test/deep/README.md @@ -0,0 +1,51 @@ +# Deep Variable Equality for Humans + +[![Go Report Card](https://goreportcard.com/badge/github.com/go-test/deep)](https://goreportcard.com/report/github.com/go-test/deep) [![Build Status](https://travis-ci.org/go-test/deep.svg?branch=master)](https://travis-ci.org/go-test/deep) [![Coverage Status](https://coveralls.io/repos/github/go-test/deep/badge.svg?branch=master)](https://coveralls.io/github/go-test/deep?branch=master) [![GoDoc](https://godoc.org/github.com/go-test/deep?status.svg)](https://godoc.org/github.com/go-test/deep) + +This package provides a single function: `deep.Equal`. It's like [reflect.DeepEqual](http://golang.org/pkg/reflect/#DeepEqual) but much friendlier to humans (or any sentient being) for two reason: + +* `deep.Equal` returns a list of differences +* `deep.Equal` does not compare unexported fields (by default) + +`reflect.DeepEqual` is good (like all things Golang!), but it's a game of [Hunt the Wumpus](https://en.wikipedia.org/wiki/Hunt_the_Wumpus). For large maps, slices, and structs, finding the difference is difficult. + +`deep.Equal` doesn't play games with you, it lists the differences: + +```go +package main_test + +import ( + "testing" + "github.com/go-test/deep" +) + +type T struct { + Name string + Numbers []float64 +} + +func TestDeepEqual(t *testing.T) { + // Can you spot the difference? + t1 := T{ + Name: "Isabella", + Numbers: []float64{1.13459, 2.29343, 3.010100010}, + } + t2 := T{ + Name: "Isabella", + Numbers: []float64{1.13459, 2.29843, 3.010100010}, + } + + if diff := deep.Equal(t1, t2); diff != nil { + t.Error(diff) + } +} +``` + + +``` +$ go test +--- FAIL: TestDeepEqual (0.00s) + main_test.go:25: [Numbers.slice[1]: 2.29343 != 2.29843] +``` + +The difference is in `Numbers.slice[1]`: the two values aren't equal using Go `==`. diff --git a/vendor/github.com/go-test/deep/deep.go b/vendor/github.com/go-test/deep/deep.go new file mode 100644 index 0000000000..4ea14cb04e --- /dev/null +++ b/vendor/github.com/go-test/deep/deep.go @@ -0,0 +1,352 @@ +// Package deep provides function deep.Equal which is like reflect.DeepEqual but +// returns a list of differences. This is helpful when comparing complex types +// like structures and maps. +package deep + +import ( + "errors" + "fmt" + "log" + "reflect" + "strings" +) + +var ( + // FloatPrecision is the number of decimal places to round float values + // to when comparing. + FloatPrecision = 10 + + // MaxDiff specifies the maximum number of differences to return. + MaxDiff = 10 + + // MaxDepth specifies the maximum levels of a struct to recurse into. + MaxDepth = 10 + + // LogErrors causes errors to be logged to STDERR when true. + LogErrors = false + + // CompareUnexportedFields causes unexported struct fields, like s in + // T{s int}, to be comparsed when true. + CompareUnexportedFields = false +) + +var ( + // ErrMaxRecursion is logged when MaxDepth is reached. + ErrMaxRecursion = errors.New("recursed to MaxDepth") + + // ErrTypeMismatch is logged when Equal passed two different types of values. + ErrTypeMismatch = errors.New("variables are different reflect.Type") + + // ErrNotHandled is logged when a primitive Go kind is not handled. + ErrNotHandled = errors.New("cannot compare the reflect.Kind") +) + +type cmp struct { + diff []string + buff []string + floatFormat string +} + +var errorType = reflect.TypeOf((*error)(nil)).Elem() + +// Equal compares variables a and b, recursing into their structure up to +// MaxDepth levels deep, and returns a list of differences, or nil if there are +// none. Some differences may not be found if an error is also returned. +// +// If a type has an Equal method, like time.Equal, it is called to check for +// equality. +func Equal(a, b interface{}) []string { + aVal := reflect.ValueOf(a) + bVal := reflect.ValueOf(b) + c := &cmp{ + diff: []string{}, + buff: []string{}, + floatFormat: fmt.Sprintf("%%.%df", FloatPrecision), + } + if a == nil && b == nil { + return nil + } else if a == nil && b != nil { + c.saveDiff(b, "") + } else if a != nil && b == nil { + c.saveDiff(a, "") + } + if len(c.diff) > 0 { + return c.diff + } + + c.equals(aVal, bVal, 0) + if len(c.diff) > 0 { + return c.diff // diffs + } + return nil // no diffs +} + +func (c *cmp) equals(a, b reflect.Value, level int) { + if level > MaxDepth { + logError(ErrMaxRecursion) + return + } + + // Check if one value is nil, e.g. T{x: *X} and T.x is nil + if !a.IsValid() || !b.IsValid() { + if a.IsValid() && !b.IsValid() { + c.saveDiff(a.Type(), "") + } else if !a.IsValid() && b.IsValid() { + c.saveDiff("", b.Type()) + } + return + } + + // If differenet types, they can't be equal + aType := a.Type() + bType := b.Type() + if aType != bType { + c.saveDiff(aType, bType) + logError(ErrTypeMismatch) + return + } + + // Primitive https://golang.org/pkg/reflect/#Kind + aKind := a.Kind() + bKind := b.Kind() + + // If both types implement the error interface, compare the error strings. + // This must be done before dereferencing because the interface is on a + // pointer receiver. + if aType.Implements(errorType) && bType.Implements(errorType) { + if a.Elem().IsValid() && b.Elem().IsValid() { // both err != nil + aString := a.MethodByName("Error").Call(nil)[0].String() + bString := b.MethodByName("Error").Call(nil)[0].String() + if aString != bString { + c.saveDiff(aString, bString) + } + return + } + } + + // Dereference pointers and interface{} + if aElem, bElem := (aKind == reflect.Ptr || aKind == reflect.Interface), + (bKind == reflect.Ptr || bKind == reflect.Interface); aElem || bElem { + + if aElem { + a = a.Elem() + } + + if bElem { + b = b.Elem() + } + + c.equals(a, b, level+1) + return + } + + // Types with an Equal(), like time.Time. + eqFunc := a.MethodByName("Equal") + if eqFunc.IsValid() { + retVals := eqFunc.Call([]reflect.Value{b}) + if !retVals[0].Bool() { + c.saveDiff(a, b) + } + return + } + + switch aKind { + + ///////////////////////////////////////////////////////////////////// + // Iterable kinds + ///////////////////////////////////////////////////////////////////// + + case reflect.Struct: + /* + The variables are structs like: + type T struct { + FirstName string + LastName string + } + Type = .T, Kind = reflect.Struct + + Iterate through the fields (FirstName, LastName), recurse into their values. + */ + for i := 0; i < a.NumField(); i++ { + if aType.Field(i).PkgPath != "" && !CompareUnexportedFields { + continue // skip unexported field, e.g. s in type T struct {s string} + } + + c.push(aType.Field(i).Name) // push field name to buff + + // Get the Value for each field, e.g. FirstName has Type = string, + // Kind = reflect.String. + af := a.Field(i) + bf := b.Field(i) + + // Recurse to compare the field values + c.equals(af, bf, level+1) + + c.pop() // pop field name from buff + + if len(c.diff) >= MaxDiff { + break + } + } + case reflect.Map: + /* + The variables are maps like: + map[string]int{ + "foo": 1, + "bar": 2, + } + Type = map[string]int, Kind = reflect.Map + + Or: + type T map[string]int{} + Type = .T, Kind = reflect.Map + + Iterate through the map keys (foo, bar), recurse into their values. + */ + + if a.IsNil() || b.IsNil() { + if a.IsNil() && !b.IsNil() { + c.saveDiff("", b) + } else if !a.IsNil() && b.IsNil() { + c.saveDiff(a, "") + } + return + } + + if a.Pointer() == b.Pointer() { + return + } + + for _, key := range a.MapKeys() { + c.push(fmt.Sprintf("map[%s]", key)) + + aVal := a.MapIndex(key) + bVal := b.MapIndex(key) + if bVal.IsValid() { + c.equals(aVal, bVal, level+1) + } else { + c.saveDiff(aVal, "") + } + + c.pop() + + if len(c.diff) >= MaxDiff { + return + } + } + + for _, key := range b.MapKeys() { + if aVal := a.MapIndex(key); aVal.IsValid() { + continue + } + + c.push(fmt.Sprintf("map[%s]", key)) + c.saveDiff("", b.MapIndex(key)) + c.pop() + if len(c.diff) >= MaxDiff { + return + } + } + case reflect.Array: + n := a.Len() + for i := 0; i < n; i++ { + c.push(fmt.Sprintf("array[%d]", i)) + c.equals(a.Index(i), b.Index(i), level+1) + c.pop() + if len(c.diff) >= MaxDiff { + break + } + } + case reflect.Slice: + if a.IsNil() || b.IsNil() { + if a.IsNil() && !b.IsNil() { + c.saveDiff("", b) + } else if !a.IsNil() && b.IsNil() { + c.saveDiff(a, "") + } + return + } + + if a.Pointer() == b.Pointer() { + return + } + + aLen := a.Len() + bLen := b.Len() + n := aLen + if bLen > aLen { + n = bLen + } + for i := 0; i < n; i++ { + c.push(fmt.Sprintf("slice[%d]", i)) + if i < aLen && i < bLen { + c.equals(a.Index(i), b.Index(i), level+1) + } else if i < aLen { + c.saveDiff(a.Index(i), "") + } else { + c.saveDiff("", b.Index(i)) + } + c.pop() + if len(c.diff) >= MaxDiff { + break + } + } + + ///////////////////////////////////////////////////////////////////// + // Primitive kinds + ///////////////////////////////////////////////////////////////////// + + case reflect.Float32, reflect.Float64: + // Avoid 0.04147685731961082 != 0.041476857319611 + // 6 decimal places is close enough + aval := fmt.Sprintf(c.floatFormat, a.Float()) + bval := fmt.Sprintf(c.floatFormat, b.Float()) + if aval != bval { + c.saveDiff(a.Float(), b.Float()) + } + case reflect.Bool: + if a.Bool() != b.Bool() { + c.saveDiff(a.Bool(), b.Bool()) + } + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + if a.Int() != b.Int() { + c.saveDiff(a.Int(), b.Int()) + } + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: + if a.Uint() != b.Uint() { + c.saveDiff(a.Uint(), b.Uint()) + } + case reflect.String: + if a.String() != b.String() { + c.saveDiff(a.String(), b.String()) + } + + default: + logError(ErrNotHandled) + } +} + +func (c *cmp) push(name string) { + c.buff = append(c.buff, name) +} + +func (c *cmp) pop() { + if len(c.buff) > 0 { + c.buff = c.buff[0 : len(c.buff)-1] + } +} + +func (c *cmp) saveDiff(aval, bval interface{}) { + if len(c.buff) > 0 { + varName := strings.Join(c.buff, ".") + c.diff = append(c.diff, fmt.Sprintf("%s: %v != %v", varName, aval, bval)) + } else { + c.diff = append(c.diff, fmt.Sprintf("%v != %v", aval, bval)) + } +} + +func logError(err error) { + if LogErrors { + log.Println(err) + } +} diff --git a/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/clusters.go b/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/clusters.go index 00f9e727b7..c726cf6f90 100644 --- a/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/clusters.go +++ b/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/clusters.go @@ -114,6 +114,61 @@ type clustersResponse struct { TotalCount int `json:"totalCount,omitempty"` } +// DefaultDiskSizeGB represents the Tier and the default disk size for each one +// it can be use like: DefaultDiskSizeGB["AWS"]["M10"] +var DefaultDiskSizeGB map[string]map[string]float64 = map[string]map[string]float64{ + "TENANT": map[string]float64{ + "M2": 2, + "M5": 5, + }, + "AWS": map[string]float64{ + "M10": 10, + "M20": 20, + "M30": 40, + "M40": 80, + "R40": 80, + "M40_NVME": 380, + "M50": 160, + "R50": 160, + "M50_NVME": 760, + "M60": 320, + "R60": 320, + "M60_NVME": 1600, + "M80": 750, + "R80": 750, + "M80_NVME": 1600, + "M140": 1000, + "M200": 1500, + "R200": 1500, + "M200_NVME": 3100, + "M300": 2000, + "R300": 2000, + "R400": 3000, + "M400_NVME": 4000, + }, + "GCP": map[string]float64{ + "M10": 10, + "M20": 20, + "M30": 40, + "M40": 80, + "M50": 160, + "M60": 320, + "M80": 750, + "M200": 1500, + "M300": 2200, + }, + "AZURE": map[string]float64{ + "M10": 32, + "M20": 32, + "M30": 32, + "M40": 128, + "M50": 128, + "M60": 128, + "M80": 256, + "M200": 256, + }, +} + //List all clusters in the project associated to {GROUP-ID}. //See more: https://docs.atlas.mongodb.com/reference/api/clusters-get-all/ func (s *ClustersServiceOp) List(ctx context.Context, groupID string, listOptions *ListOptions) ([]Cluster, *Response, error) { diff --git a/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/maintenance.go b/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/maintenance.go new file mode 100644 index 0000000000..31076dd0d0 --- /dev/null +++ b/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/maintenance.go @@ -0,0 +1,136 @@ +package mongodbatlas + +import ( + "context" + "fmt" + "net/http" +) + +const ( + maintenanceWindowsPath = "groups/%s/maintenanceWindow" + // Sunday day of the week when you would like the maintenance window to start + Sunday = 1 + // Monday day of the week when you would like the maintenance window to start + Monday = 2 + // Tuesday day of the week when you would like the maintenance window to start + Tuesday = 3 + // Wednesday day of the week when you would like the maintenance window to start + Wednesday = 4 + // Thursday day of the week when you would like the maintenance window to start + Thursday = 5 + // Friday day of the week when you would like the maintenance window to start + Friday = 6 + // Saturday day of the week when you would like the maintenance window to start + Saturday = 7 +) + +// MaintenanceWindowsService is an interface for interfacing with the Maintenance Windows +// endpoints of the MongoDB Atlas API. +// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-windows/ +type MaintenanceWindowsService interface { + Get(context.Context, string) (*MaintenanceWindow, *Response, error) + Update(context.Context, string, *MaintenanceWindow) (*Response, error) + Defer(context.Context, string) (*Response, error) + Reset(context.Context, string) (*Response, error) +} + +// MaintenanceWindowsServiceOp handles communication with the MaintenanceWindows related methods +// of the MongoDB Atlas API +type MaintenanceWindowsServiceOp struct { + client *Client +} + +var _ MaintenanceWindowsService = &MaintenanceWindowsServiceOp{} + +// MaintenanceWindow represents MongoDB Maintenance Windows +type MaintenanceWindow struct { + DayOfWeek int `json:"dayOfWeek,omitempty"` // Day of the week when you would like the maintenance window to start as a 1-based integer.Sunday 1, Monday 2, Tuesday 3, Wednesday 4, Thursday 5, Friday 6, Saturday 7 + HourOfDay *int `json:"hourOfDay,omitempty"` // Hour of the day when you would like the maintenance window to start. This parameter uses the 24-hour clock, where midnight is 0, noon is 12. + StartASAP *bool `json:"startASAP,omitempty"` // Flag indicating whether project maintenance has been directed to start immediately. + NumberOfDeferrals int `json:"numberOfDeferrals,omitempty"` // Number of times the current maintenance event for this project has been deferred. +} + +// Get gets the current user-defined maintenance window for the given project. +// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-windows-view-in-one-project/ +func (s *MaintenanceWindowsServiceOp) Get(ctx context.Context, groupID string) (*MaintenanceWindow, *Response, error) { + if groupID == "" { + return nil, nil, NewArgError("groupID", "must be set") + } + + path := fmt.Sprintf(maintenanceWindowsPath, groupID) + req, err := s.client.NewRequest(ctx, http.MethodGet, path, nil) + if err != nil { + return nil, nil, err + } + + root := new(MaintenanceWindow) + resp, err := s.client.Do(ctx, req, root) + if err != nil { + return nil, resp, err + } + + return root, resp, err +} + +// Update the current maintenance window for the given project. +// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-window-update/ +func (s *MaintenanceWindowsServiceOp) Update(ctx context.Context, groupID string, updateRequest *MaintenanceWindow) (*Response, error) { + if updateRequest == nil { + return nil, NewArgError("updateRequest", "cannot be nil") + } + if groupID == "" { + return nil, NewArgError("groupID", "cannot be nil") + } + + path := fmt.Sprintf(maintenanceWindowsPath, groupID) + + req, err := s.client.NewRequest(ctx, http.MethodPatch, path, updateRequest) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, err +} + +// Defer maintenance for the given project for one week. +// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-window-defer/ +func (s *MaintenanceWindowsServiceOp) Defer(ctx context.Context, groupID string) (*Response, error) { + if groupID == "" { + return nil, NewArgError("groupID", "cannot be nil") + } + + path := fmt.Sprintf(maintenanceWindowsPath+"/defer", groupID) + + req, err := s.client.NewRequest(ctx, http.MethodPost, path, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + + return resp, err +} + +// Reset clears the current maintenance window for the given project. +// See more: https://docs.atlas.mongodb.com/reference/api/maintenance-window-clear/ +func (s *MaintenanceWindowsServiceOp) Reset(ctx context.Context, groupID string) (*Response, error) { + if groupID == "" { + return nil, NewArgError("groupID", "must be set") + } + + path := fmt.Sprintf(maintenanceWindowsPath, groupID) + + req, err := s.client.NewRequest(ctx, http.MethodDelete, path, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + + return resp, err +} diff --git a/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/mongodbatlas.go b/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/mongodbatlas.go index 00526393e1..7190f55a34 100644 --- a/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/mongodbatlas.go +++ b/vendor/github.com/mongodb/go-client-mongodb-atlas/mongodbatlas/mongodbatlas.go @@ -44,6 +44,7 @@ type Client struct { EncryptionsAtRest EncryptionsAtRestService WhitelistAPIKeys WhitelistAPIKeysService PrivateIPMode PrivateIpModeService + MaintenanceWindows MaintenanceWindowsService onRequestCompleted RequestCompletionCallback } @@ -147,6 +148,7 @@ func NewClient(httpClient *http.Client) *Client { c.ProjectIPWhitelist = &ProjectIPWhitelistServiceOp{client: c} c.WhitelistAPIKeys = &WhitelistAPIKeysServiceOp{client: c} c.PrivateIPMode = &PrivateIpModeServiceOp{client: c} + c.MaintenanceWindows = &MaintenanceWindowsServiceOp{client: c} return c } diff --git a/vendor/modules.txt b/vendor/modules.txt index 60f4b068b1..93e08165e0 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -61,6 +61,8 @@ github.com/blang/semver github.com/davecgh/go-spew/spew # github.com/fatih/color v1.7.0 github.com/fatih/color +# github.com/go-test/deep v1.0.1 +github.com/go-test/deep # github.com/golang/protobuf v1.3.0 github.com/golang/protobuf/proto github.com/golang/protobuf/protoc-gen-go/descriptor @@ -203,7 +205,7 @@ github.com/mitchellh/hashstructure github.com/mitchellh/mapstructure # github.com/mitchellh/reflectwalk v1.0.0 github.com/mitchellh/reflectwalk -# github.com/mongodb/go-client-mongodb-atlas v0.1.1 +# github.com/mongodb/go-client-mongodb-atlas v0.1.2-0.20191125173016-a644c761794e github.com/mongodb/go-client-mongodb-atlas/mongodbatlas # github.com/mwielbut/pointy v1.1.0 github.com/mwielbut/pointy