Skip to content

Commit

Permalink
remove some interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
gssbzn committed Mar 6, 2024
1 parent ce2c96a commit 4bee848
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 51 deletions.
1 change: 0 additions & 1 deletion build/ci/library_owners.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"go.mongodb.org/atlas": "mongocli",
"go.mongodb.org/atlas-sdk/v20231115007": "mongocli",
"go.mongodb.org/mongo-driver": "mongocli",
"go.mongodb.org/ops-manager": "mongocli",
"golang.org/x/crypto": "mongocli",
"golang.org/x/tools": "mongocli",
"google.golang.org/api": "mongocli",
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ require (
go.mongodb.org/atlas v0.36.0
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.1.0
go.mongodb.org/mongo-driver v1.14.0
go.mongodb.org/ops-manager v0.55.3
golang.org/x/crypto v0.21.0
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/mod v0.16.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,6 @@ go.mongodb.org/atlas-sdk/v20231115007 v20231115007.1.0 h1:RAnP53qeTT32iySa4sjfl1
go.mongodb.org/atlas-sdk/v20231115007 v20231115007.1.0/go.mod h1:JU7JOUGcv7pfDzbRTwIr8hGy2R1lehdrdfGj9fDjSVY=
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
go.mongodb.org/ops-manager v0.55.3 h1:ZckNLra9XfvUxWgRfdCVOr7QkeCPi7S4VNbcK5di/2A=
go.mongodb.org/ops-manager v0.55.3/go.mod h1:3KAtjSrHt4KB0mWLDRDlQpiyZypB+4EX9XXjx3gN5PA=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg=
Expand Down
9 changes: 5 additions & 4 deletions internal/cli/atlas/projects/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,20 @@ import (

"github.com/golang/mock/gomock"
mocks "github.com/mongodb/mongodb-atlas-cli/internal/mocks/atlas"
"go.mongodb.org/ops-manager/opsmngr"
"github.com/mongodb/mongodb-atlas-cli/internal/pointer"
"go.mongodb.org/atlas-sdk/v20231115007/admin"
)

func TestDescribe_Run(t *testing.T) {
ctrl := gomock.NewController(t)
mockStore := mocks.NewMockProjectDescriber(ctrl)
expected := opsmngr.Project{
expected := admin.Group{
Name: "test",
ID: "5a0a1e7e0f2912c554080adc",
Id: pointer.Get("5a0a1e7e0f2912c554080adc"),
}
mockStore.
EXPECT().
Project(gomock.Eq("5a0a1e7e0f2912c554080adc")).
Project("5a0a1e7e0f2912c554080adc").
Return(&expected, nil).
Times(1)

Expand Down
20 changes: 4 additions & 16 deletions internal/kubernetes/operator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ import (
)

const (
roleOrgGroupCreator = "ORG_GROUP_CREATOR"
roleProjectOwner = "GROUP_OWNER"
atlasErrorProjectNotFound = "GROUP_NAME_NOT_FOUND"
atlasErrorNotInGroup = "NOT_IN_GROUP"
roleOrgGroupCreator = "ORG_GROUP_CREATOR"
roleProjectOwner = "GROUP_OWNER"
)

type Install struct {
Expand Down Expand Up @@ -143,21 +141,16 @@ func (i *Install) Run(ctx context.Context, orgID string) error {
}

func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error) {
data, err := i.atlasStore.ProjectByName(projectName)
project, err := i.atlasStore.ProjectByName(projectName)
if err == nil {
project, ok := data.(*admin.Group)
if !ok {
return nil, fmt.Errorf("failed to decode project: %w", err)
}

return project, nil
}

if err != nil {
return nil, fmt.Errorf("failed to retrieve project: %w", err)
}

data, err = i.atlasStore.CreateProject(&admin.CreateProjectApiParams{
project, err = i.atlasStore.CreateProject(&admin.CreateProjectApiParams{
Group: &admin.Group{
Name: projectName,
OrgId: orgID,
Expand All @@ -169,11 +162,6 @@ func (i *Install) ensureProject(orgID, projectName string) (*admin.Group, error)
return nil, fmt.Errorf("failed to create project: %w", err)
}

project, ok := data.(*admin.Group)
if !ok {
return nil, fmt.Errorf("failed to decode created project: %w", err)
}

return project, nil
}

Expand Down
12 changes: 1 addition & 11 deletions internal/kubernetes/operator/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package project

import (
"errors"
"fmt"
"strings"

Expand Down Expand Up @@ -63,27 +62,18 @@ const (
prometheusIntegrationType = "PROMETHEUS"
)

var (
ErrAtlasProject = errors.New("can not get 'atlas project' resource")
)

type AtlasProjectResult struct {
Project *akov2.AtlasProject
Secrets []*corev1.Secret
Teams []*akov2.AtlasTeam
}

func BuildAtlasProject(projectStore atlas.OperatorProjectStore, validator features.FeatureValidator, orgID, projectID, targetNamespace string, includeSecret bool, dictionary map[string]string, version string) (*AtlasProjectResult, error) { //nolint:gocyclo
data, err := projectStore.Project(projectID)
project, err := projectStore.Project(projectID)
if err != nil {
return nil, err
}

project, ok := data.(*atlasv2.Group)
if !ok {
return nil, ErrAtlasProject
}

projectResult := newAtlasProject(project, dictionary, targetNamespace, version)

result := &AtlasProjectResult{
Expand Down
8 changes: 4 additions & 4 deletions internal/mocks/atlas/mock_atlas_generic_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/mocks/atlas/mock_atlas_operator_project_store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/mocks/atlas/mock_projects.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/store/atlas/projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ type ProjectDeleter interface {
}

type ProjectDescriber interface {
Project(string) (interface{}, error)
ProjectByName(string) (interface{}, error)
Project(string) (*atlasv2.Group, error)
ProjectByName(string) (*atlasv2.Group, error)
}

type ProjectUsersLister interface {
Expand Down Expand Up @@ -83,12 +83,12 @@ func (s *Store) GetOrgProjects(orgID string, opts *ListOptions) (*atlasv2.Pagina
}

// Project encapsulates the logic to manage different cloud providers.
func (s *Store) Project(id string) (interface{}, error) {
func (s *Store) Project(id string) (*atlasv2.Group, error) {
result, _, err := s.clientv2.ProjectsApi.GetProject(s.ctx, id).Execute()
return result, err
}

func (s *Store) ProjectByName(name string) (interface{}, error) {
func (s *Store) ProjectByName(name string) (*atlasv2.Group, error) {
result, _, err := s.clientv2.ProjectsApi.GetProjectByName(s.ctx, name).Execute()
return result, err
}
Expand Down

0 comments on commit 4bee848

Please sign in to comment.