From 15383b87e45b3239c2525a4b46a573da22c4c1ac Mon Sep 17 00:00:00 2001 From: Filipe C Menezes Date: Thu, 7 Nov 2024 12:18:07 +0000 Subject: [PATCH] CLOUDP-283284 Remove unused code from 'internal/mongodbclient' --- internal/mocks/mock_mongodb_client.go | 57 --------------------------- internal/mongodbclient/database.go | 25 ------------ internal/mongodbclient/user.go | 52 ------------------------ 3 files changed, 134 deletions(-) delete mode 100644 internal/mongodbclient/user.go diff --git a/internal/mocks/mock_mongodb_client.go b/internal/mocks/mock_mongodb_client.go index 1680374c77..cc59c585cc 100644 --- a/internal/mocks/mock_mongodb_client.go +++ b/internal/mocks/mock_mongodb_client.go @@ -157,63 +157,6 @@ func (mr *MockDatabaseMockRecorder) CreateSearchIndex(arg0, arg1, arg2 interface return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateSearchIndex", reflect.TypeOf((*MockDatabase)(nil).CreateSearchIndex), arg0, arg1, arg2) } -// CreateUser mocks base method. -func (m *MockDatabase) CreateUser(arg0 context.Context, arg1, arg2 string, arg3 []string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "CreateUser", arg0, arg1, arg2, arg3) - ret0, _ := ret[0].(error) - return ret0 -} - -// CreateUser indicates an expected call of CreateUser. -func (mr *MockDatabaseMockRecorder) CreateUser(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CreateUser", reflect.TypeOf((*MockDatabase)(nil).CreateUser), arg0, arg1, arg2, arg3) -} - -// DropUser mocks base method. -func (m *MockDatabase) DropUser(arg0 context.Context, arg1 string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "DropUser", arg0, arg1) - ret0, _ := ret[0].(error) - return ret0 -} - -// DropUser indicates an expected call of DropUser. -func (mr *MockDatabaseMockRecorder) DropUser(arg0, arg1 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "DropUser", reflect.TypeOf((*MockDatabase)(nil).DropUser), arg0, arg1) -} - -// InitiateReplicaSet mocks base method. -func (m *MockDatabase) InitiateReplicaSet(arg0 context.Context, arg1, arg2 string, arg3, arg4 int) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InitiateReplicaSet", arg0, arg1, arg2, arg3, arg4) - ret0, _ := ret[0].(error) - return ret0 -} - -// InitiateReplicaSet indicates an expected call of InitiateReplicaSet. -func (mr *MockDatabaseMockRecorder) InitiateReplicaSet(arg0, arg1, arg2, arg3, arg4 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InitiateReplicaSet", reflect.TypeOf((*MockDatabase)(nil).InitiateReplicaSet), arg0, arg1, arg2, arg3, arg4) -} - -// InsertOne mocks base method. -func (m *MockDatabase) InsertOne(arg0 context.Context, arg1 string, arg2 interface{}) (interface{}, error) { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "InsertOne", arg0, arg1, arg2) - ret0, _ := ret[0].(interface{}) - ret1, _ := ret[1].(error) - return ret0, ret1 -} - -// InsertOne indicates an expected call of InsertOne. -func (mr *MockDatabaseMockRecorder) InsertOne(arg0, arg1, arg2 interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "InsertOne", reflect.TypeOf((*MockDatabase)(nil).InsertOne), arg0, arg1, arg2) -} - // RunCommand mocks base method. func (m *MockDatabase) RunCommand(arg0 context.Context, arg1 interface{}) (interface{}, error) { m.ctrl.T.Helper() diff --git a/internal/mongodbclient/database.go b/internal/mongodbclient/database.go index e8b61e7ba2..1fe70bb837 100644 --- a/internal/mongodbclient/database.go +++ b/internal/mongodbclient/database.go @@ -16,7 +16,6 @@ package mongodbclient import ( "context" - "fmt" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -24,10 +23,7 @@ import ( type Database interface { RunCommand(ctx context.Context, runCommand any) (any, error) - InsertOne(ctx context.Context, collection string, doc any) (any, error) - InitiateReplicaSet(ctx context.Context, rsName string, hostname string, internalPort int, externalPort int) error SearchIndex - User Collection(string) Collection } @@ -53,24 +49,3 @@ func (d *database) RunCommand(ctx context.Context, runCmd any) (any, error) { } return cmdResult, nil } - -func (d *database) InsertOne(ctx context.Context, col string, doc any) (any, error) { - return d.db.Collection(col).InsertOne(ctx, doc) -} - -func (d *database) InitiateReplicaSet(ctx context.Context, rsName string, hostname string, internalPort int, externalPort int) error { - return d.db.RunCommand(ctx, bson.D{{Key: "replSetInitiate", Value: bson.M{ - "_id": rsName, - "version": 1, - "configsvr": false, - "members": []bson.M{ - { - "_id": 0, - "host": fmt.Sprintf("%s:%d", hostname, internalPort), - "horizons": bson.M{ - "external": fmt.Sprintf("localhost:%d", externalPort), - }, - }, - }, - }}}).Err() -} diff --git a/internal/mongodbclient/user.go b/internal/mongodbclient/user.go deleted file mode 100644 index eb1b58db12..0000000000 --- a/internal/mongodbclient/user.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright 2023 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 mongodbclient - -import ( - "context" - - "go.mongodb.org/mongo-driver/bson" -) - -type User interface { - CreateUser(ctx context.Context, username, password string, roles []string) error - DropUser(ctx context.Context, username string) error -} - -func (d *database) CreateUser(ctx context.Context, username, password string, roles []string) error { - rolesDoc := bson.A{} - for _, r := range roles { - rolesDoc = append(rolesDoc, bson.D{ - {Key: "role", Value: r}, - {Key: "db", Value: d.db.Name()}, - }) - } - - return d.db.Client(). - Database("admin"). - RunCommand(ctx, bson.D{ - {Key: "createUser", Value: username}, - {Key: "pwd", Value: password}, - {Key: "roles", Value: rolesDoc}, - }).Err() -} - -func (d *database) DropUser(ctx context.Context, username string) error { - return d.db.Client(). - Database("admin"). - RunCommand(ctx, bson.D{ - {Key: "dropUser", Value: username}, - }).Err() -}