Skip to content

Commit

Permalink
CLOUDP-252326: Remove Atlas Dependency Phase 4 (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
husniMDB authored Jun 26, 2024
1 parent b0a1437 commit e32fddf
Show file tree
Hide file tree
Showing 55 changed files with 1,211 additions and 530 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require (
github.com/google/go-querystring v1.1.0
github.com/stretchr/testify v1.9.0
github.com/xdg-go/stringprep v1.0.4
go.mongodb.org/atlas v0.36.0
)

require (
Expand Down
46 changes: 36 additions & 10 deletions opsmngr/accesslist_api_keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,48 @@ import (
"context"
"fmt"
"net/http"

atlas "go.mongodb.org/atlas/mongodbatlas"
)

type (
AccessListAPIKey = atlas.AccessListAPIKey
AccessListAPIKeys = atlas.AccessListAPIKeys
AccessListAPIKeysReq = atlas.AccessListAPIKeysReq
)

const accessListAPIKeysPath = "api/public/v1.0/orgs/%s/apiKeys/%s/accessList" //nolint:gosec // This is a path

// AccessListAPIKeysServiceOp handles communication with the AccessList API keys related methods of the MongoDB Ops Manager API.
// AccessListAPIKeysService is an interface for interfacing with the AccessList API Keys
// endpoints of the MongoDB Ops Manager API.
type AccessListAPIKeysService interface {
List(context.Context, string, string, *ListOptions) (*AccessListAPIKeys, *Response, error)
Get(context.Context, string, string, string) (*AccessListAPIKey, *Response, error)
Create(context.Context, string, string, []*AccessListAPIKeysReq) (*AccessListAPIKeys, *Response, error)
Delete(context.Context, string, string, string) (*Response, error)
}

// AccessListAPIKeysServiceOp handles communication with the AccessList API keys related methods of the
// MongoDB Ops Manager API.
type AccessListAPIKeysServiceOp service

var _ atlas.AccessListAPIKeysService = &AccessListAPIKeysServiceOp{}
var _ AccessListAPIKeysService = &AccessListAPIKeysServiceOp{}

// AccessListAPIKey represents a AccessList API key.
type AccessListAPIKey struct {
CidrBlock string `json:"cidrBlock,omitempty"` // CIDR-notated range of permitted IP addresses.
Count int `json:"count,omitempty"` // Total number of requests that have originated from this IP address.
Created string `json:"created,omitempty"` // Date this IP address was added to the access list.
IPAddress string `json:"ipAddress,omitempty"` // IP address in the API access list.
LastUsed string `json:"lastUsed,omitempty"` // Timestamp in ISO 8601 date and time format in UTC when the most recent request that originated from this IP address. This parameter only appears if at least one request has originated from this IP address, and is only updated when a permitted resource is accessed.
LastUsedAddress string `json:"lastUsedAddress,omitempty"` // IP address from which the last call to the API was issued. This field only appears if at least one request has originated from this IP address.
Links []*Link `json:"links,omitempty"` // An array of documents, representing a link to one or more sub-resources and/or related resources such as list pagination. See Linking for more information.}
}

// AccessListAPIKeys represents all AccessList API keys.
type AccessListAPIKeys struct {
Results []*AccessListAPIKey `json:"results,omitempty"` // Includes one AccessListAPIKey object for each item detailed in the results array section.
Links []*Link `json:"links,omitempty"` // One or more links to sub-resources and/or related resources.
TotalCount int `json:"totalCount,omitempty"` // Count of the total number of items in the result set. It may be greater than the number of objects in the results array if the entire result set is paginated.
}

// AccessListAPIKeysReq represents the request to the method create.
type AccessListAPIKeysReq struct {
IPAddress string `json:"ipAddress,omitempty"` // IP address to be added to the access list for the API key.
CidrBlock string `json:"cidrBlock,omitempty"` // CIDR-notation block of IP addresses to be added to the access list for the API key.
}

// List gets all AccessList API keys.
func (s *AccessListAPIKeysServiceOp) List(ctx context.Context, orgID, apiKeyID string, listOptions *ListOptions) (*AccessListAPIKeys, *Response, error) {
Expand Down
27 changes: 13 additions & 14 deletions opsmngr/accesslist_api_keys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"testing"

"github.com/go-test/deep"
atlas "go.mongodb.org/atlas/mongodbatlas"
)

const (
Expand Down Expand Up @@ -81,22 +80,22 @@ func TestAccessListAPIKeys_List(t *testing.T) {
t.Fatalf("AccessListAPIKeys.List returned error: %v", err)
}

expected := &atlas.AccessListAPIKeys{
Links: []*atlas.Link{
expected := &AccessListAPIKeys{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/599c510c80eef518f3b63fe1/apiKeys/5c49e72980eef544a218f8f8/accessList/?pretty=true&pageNum=1&itemsPerPage=100",
Rel: "self",
},
},
Results: []*atlas.AccessListAPIKey{
Results: []*AccessListAPIKey{
{
CidrBlock: "147.58.184.16/32",
Count: 0,
Created: "2019-01-24T16:34:57Z",
IPAddress: "147.58.184.16",
LastUsed: "2019-01-24T20:18:25Z",
LastUsedAddress: "147.58.184.16",
Links: []*atlas.Link{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/{ORG-ID}/apiKeys/{API-KEY-ID}/accessList/147.58.184.16",
Rel: "self",
Expand All @@ -110,7 +109,7 @@ func TestAccessListAPIKeys_List(t *testing.T) {
IPAddress: "84.255.48.125",
LastUsed: "2019-01-24T20:18:25Z",
LastUsedAddress: "84.255.48.125",
Links: []*atlas.Link{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/{ORG-ID}/apiKeys/{API-KEY-ID}/accessList/206.252.195.126",
Rel: "self",
Expand Down Expand Up @@ -151,12 +150,12 @@ func TestAccessListAPIKeys_Get(t *testing.T) {
t.Fatalf("AccessListAPIKeys.Get returned error: %v", err)
}

expected := &atlas.AccessListAPIKey{
expected := &AccessListAPIKey{
CidrBlock: "147.58.184.16/32",
Count: 0,
Created: "2019-01-24T16:34:57Z",
IPAddress: "147.58.184.16",
Links: []*atlas.Link{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/{ORG-ID}/apiKeys/{API-KEY-ID}/accessList/147.58.184.16",
Rel: "self",
Expand All @@ -173,7 +172,7 @@ func TestAccessListAPIKeys_Create(t *testing.T) {
client, mux, teardown := setup()
defer teardown()

createRequest := []*atlas.AccessListAPIKeysReq{
createRequest := []*AccessListAPIKeysReq{
{
IPAddress: "77.54.32.11",
CidrBlock: "77.54.32.11/32",
Expand Down Expand Up @@ -244,22 +243,22 @@ func TestAccessListAPIKeys_Create(t *testing.T) {
t.Fatalf("AccessListAPIKeys.Create returned error: %v", err)
}

expected := &atlas.AccessListAPIKeys{
Links: []*atlas.Link{
expected := &AccessListAPIKeys{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/599c510c80eef518f3b63fe1/apiKeys/5c49e72980eef544a218f8f8/accessList/?pretty=true&pageNum=1&itemsPerPage=100",
Rel: "self",
},
},
Results: []*atlas.AccessListAPIKey{
Results: []*AccessListAPIKey{
{
CidrBlock: "147.58.184.16/32",
Count: 0,
Created: "2019-01-24T16:34:57Z",
IPAddress: "147.58.184.16",
LastUsed: "2019-01-24T20:18:25Z",
LastUsedAddress: "147.58.184.16",
Links: []*atlas.Link{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/{ORG-ID}/apiKeys/{API-KEY-ID}/accessList/147.58.184.16",
Rel: "self",
Expand All @@ -273,7 +272,7 @@ func TestAccessListAPIKeys_Create(t *testing.T) {
IPAddress: "77.54.32.11",
LastUsed: "2019-01-24T20:18:25Z",
LastUsedAddress: "77.54.32.11",
Links: []*atlas.Link{
Links: []*Link{
{
Href: "https://cloud.mongodb.com/api/atlas/v1.0/orgs/{ORG-ID}/apiKeys/{API-KEY-ID}/accessList/77.54.32.11",
Rel: "self",
Expand Down
Loading

0 comments on commit e32fddf

Please sign in to comment.