Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLOUDP-82836: Parse service version #122

Merged
merged 7 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/openlyinc/pointy v1.1.2
github.com/stretchr/testify v1.7.0
github.com/xdg-go/stringprep v1.0.2
go.mongodb.org/atlas v0.11.1-0.20210811161401-47f8a8c02572
go.mongodb.org/atlas v0.12.1-0.20210901163952-d05620be0f87
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/xdg-go/stringprep v1.0.2 h1:6iq84/ryjjeRmMJwxutI51F2GIPlP5BfTvXHeYjyhBc=
github.com/xdg-go/stringprep v1.0.2/go.mod h1:8F9zXuvzgwmyT5DUm4GUfZGDdT3W+LCvS6+da4O5kxM=
go.mongodb.org/atlas v0.11.1-0.20210811161401-47f8a8c02572 h1:V/9fqSuNtNOecclmodf3TSbAfYFSS4MOJOA8pO7iDP8=
go.mongodb.org/atlas v0.11.1-0.20210811161401-47f8a8c02572/go.mod h1:MMWDsc2akjTDSG4tVQrxv/82p3QbBnqeELbtTl45sbg=
go.mongodb.org/atlas v0.12.1-0.20210901163952-d05620be0f87 h1:pcPuHfABfq6w0ZjWZKTkmkT3b5fCaKAW0dgofmHdDUQ=
go.mongodb.org/atlas v0.12.1-0.20210901163952-d05620be0f87/go.mod h1:wVCnHcm/7/IfTjEB6K8K35PLG70yGz8BdkRwX0oK9/M=
golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ=
golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
3 changes: 3 additions & 0 deletions opsmngr/opsmngr.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const (
type (
Response = atlas.Response
RequestCompletionCallback = atlas.RequestCompletionCallback
ServiceVersion = atlas.ServiceVersion
)

// Client manages communication with Ops Manager API.
Expand Down Expand Up @@ -94,6 +95,7 @@ type Client struct {
ServerUsage ServerUsageService
ServerUsageReport ServerUsageReportService
LiveMigration LiveDataMigrationService
ServiceVersion ServiceVersionService
gssbzn marked this conversation as resolved.
Show resolved Hide resolved

onRequestCompleted RequestCompletionCallback
}
Expand Down Expand Up @@ -161,6 +163,7 @@ func NewClient(httpClient *http.Client) *Client {
c.ServerUsage = &ServerUsageServiceOp{Client: c}
c.ServerUsageReport = &ServerUsageReportServiceOp{Client: c}
c.LiveMigration = &LiveDataMigrationServiceOp{Client: c}
c.ServiceVersion = &ServiceVersionServiceOp{Client: c}

return c
}
Expand Down
46 changes: 46 additions & 0 deletions opsmngr/service_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package opsmngr

import (
"context"
"net/http"
)

const versionPath = "api/private/unauth/version"

// ServiceVersionService is an interface for interfacing with the version private endpoint of the MongoDB Atlas API.
type ServiceVersionService interface {
Get(context.Context) (*ServiceVersion, *Response, error)
}

type ServiceVersionServiceOp service

// Get gets a compressed (.gz) log file that contains a range of log messages for a particular host.
func (s *ServiceVersionServiceOp) Get(ctx context.Context) (*ServiceVersion, *Response, error) {
req, err := s.Client.NewRequest(ctx, http.MethodGet, versionPath, nil)
if err != nil {
return nil, nil, err
}

resp, err := s.Client.Do(ctx, req, nil)
if err != nil {
return nil, nil, err
}

version := resp.GetServiceVersion()

return version, resp, nil
}
37 changes: 37 additions & 0 deletions opsmngr/service_version_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2021 MongoDB Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package opsmngr

import (
"fmt"
"net/http"
"testing"
)

func TestServiceVersionService_Get(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

mux.HandleFunc("/api/private/unauth/version", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, http.MethodGet)
fmt.Fprint(w, "someGitHash")
})

_, _, err := client.ServiceVersion.Get(ctx)

if err != nil {
t.Fatalf("ServiceVersion.Get returned error: %v", err)
}
}