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-78654: Missing audit filter on convert #545

Merged
merged 2 commits into from
Dec 9, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 e2e/atlas/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func createProject(projectName string) (string, error) {
cmd.Env = os.Environ()
resp, err := cmd.CombinedOutput()
if err != nil {
return "", err
return "", fmt.Errorf("%s (%w)", string(resp), err)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

drive by debug, a tests was failing here and needed to see why

}

var project mongodbatlas.Project
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.3.1 // indirect
github.com/mongodb-forks/digest v1.0.1
github.com/openlyinc/pointy v1.1.2
github.com/pelletier/go-toml v1.8.1
github.com/spf13/afero v1.5.0
github.com/spf13/cast v1.3.1 // indirect
Expand Down
1 change: 1 addition & 0 deletions internal/convert/process_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ func (p *ProcessConfig) auditLog() *opsmngr.AuditLog {
Destination: p.auditLogDestination(),
Path: p.AuditLogPath,
Format: p.AuditLogFormat,
Filter: p.AuditLogFilter,
Copy link
Collaborator Author

@gssbzn gssbzn Dec 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I missed this, the rest is tests

}
}

Expand Down
186 changes: 173 additions & 13 deletions internal/convert/process_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ package convert
import (
"testing"

"github.com/openlyinc/pointy"
"github.com/stretchr/testify/assert"
"go.mongodb.org/ops-manager/opsmngr"
)

func TestNewReplicaSetProcessConfig(t *testing.T) {
trueValue := true
func Test_newReplicaSetProcessConfig(t *testing.T) {
omp := &opsmngr.Process{
Args26: opsmngr.Args26{
AuditLog: &opsmngr.AuditLog{
Expand All @@ -40,7 +40,7 @@ func TestNewReplicaSetProcessConfig(t *testing.T) {
},
Storage: &opsmngr.Storage{
DBPath: "/data/db",
DirectoryPerDB: &trueValue,
DirectoryPerDB: pointy.Bool(true),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
Expand Down Expand Up @@ -78,31 +78,28 @@ func TestNewReplicaSetProcessConfig(t *testing.T) {
Votes: 1,
}

one := 1.0
zero := 0.0
falseValue := false
expected := &ProcessConfig{
AuditLogPath: "/data/audit.log",
AuditLogDestination: "file",
AuditLogFormat: "JSON",
AuditLogFilter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
BuildIndexes: &trueValue,
BuildIndexes: pointy.Bool(true),
DBPath: "/data/db",
DirectoryPerDB: &trueValue,
DirectoryPerDB: pointy.Bool(true),
FCVersion: "4.4",
Hostname: "n1.omansible.int",
LogDestination: "file",
LogPath: "/data/log/mongodb.log",
Name: "myReplicaSet_1",
Port: 27017,
Priority: &one,
Priority: pointy.Float64(1),
ProcessType: "mongod",
SlaveDelay: &zero,
SlaveDelay: pointy.Float64(0),
Version: "4.4.1-ent",
Votes: &one,
ArbiterOnly: &falseValue,
Votes: pointy.Float64(1),
ArbiterOnly: pointy.Bool(false),
Disabled: false,
Hidden: &falseValue,
Hidden: pointy.Bool(false),
TLS: &TLS{Mode: "disabled"},
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
Expand All @@ -116,3 +113,166 @@ func TestNewReplicaSetProcessConfig(t *testing.T) {

assert.Equal(t, expected, result)
}

func Test_newConfigRSProcess(t *testing.T) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a test of ops manager -> mcli but not one mcli -> ops manager, so now we have both

p := &ProcessConfig{
AuditLogPath: "/data/audit.log",
AuditLogDestination: "file",
AuditLogFormat: "JSON",
AuditLogFilter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
BuildIndexes: pointy.Bool(true),
DBPath: "/data/db",
DirectoryPerDB: pointy.Bool(true),
FCVersion: "4.4",
Hostname: "n1.omansible.int",
LogDestination: "file",
LogPath: "/data/log/mongodb.log",
Name: "myReplicaSet_1",
Port: 27017,
Priority: pointy.Float64(1),
ProcessType: "mongod",
SlaveDelay: pointy.Float64(0),
Version: "4.4.1-ent",
Votes: pointy.Float64(1),
ArbiterOnly: pointy.Bool(false),
Disabled: false,
Hidden: pointy.Bool(false),
TLS: &TLS{Mode: "disabled"},
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
"cacheSizeGB": 1,
},
"indexConfig": map[string]interface{}{},
},
}

want := &opsmngr.Process{
Args26: opsmngr.Args26{
AuditLog: &opsmngr.AuditLog{
Destination: "file",
Path: "/data/audit.log",
Format: "JSON",
Filter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
},
NET: opsmngr.Net{
Port: 27017,
TLS: &opsmngr.TLS{Mode: "disabled"},
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
Storage: &opsmngr.Storage{
DBPath: "/data/db",
DirectoryPerDB: pointy.Bool(true),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
"cacheSizeGB": 1,
},
"indexConfig": map[string]interface{}{},
},
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/log/mongodb.log",
},
Sharding: &opsmngr.Sharding{ClusterRole: "configsvr"},
},
AuthSchemaVersion: 5,
Disabled: false,
FeatureCompatibilityVersion: "4.4",
Hostname: "n1.omansible.int",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000,
TimeThresholdHrs: 24,
},
ManualMode: false,
Name: "myReplicaSet_1",
ProcessType: "mongod",
Version: "4.4.1-ent",
}
got := newConfigRSProcess(p, "myReplicaSet")
assert.Equal(t, got, want)
}

func Test_newReplicaSetProcess(t *testing.T) {
p := &ProcessConfig{
AuditLogPath: "/data/audit.log",
AuditLogDestination: "file",
AuditLogFormat: "JSON",
AuditLogFilter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
BuildIndexes: pointy.Bool(true),
DBPath: "/data/db",
DirectoryPerDB: pointy.Bool(true),
FCVersion: "4.4",
Hostname: "n1.omansible.int",
LogDestination: "file",
LogPath: "/data/log/mongodb.log",
Name: "myReplicaSet_1",
Port: 27017,
Priority: pointy.Float64(1),
ProcessType: "mongod",
SlaveDelay: pointy.Float64(0),
Version: "4.4.1-ent",
Votes: pointy.Float64(1),
ArbiterOnly: pointy.Bool(false),
Disabled: false,
Hidden: pointy.Bool(false),
TLS: &TLS{Mode: "disabled"},
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
"cacheSizeGB": 1,
},
"indexConfig": map[string]interface{}{},
},
}

want := &opsmngr.Process{
Args26: opsmngr.Args26{
AuditLog: &opsmngr.AuditLog{
Destination: "file",
Path: "/data/audit.log",
Format: "JSON",
Filter: "{ atype: { $in: [ \"createCollection\", \"dropCollection\" ] } }",
},
NET: opsmngr.Net{
Port: 27017,
TLS: &opsmngr.TLS{Mode: "disabled"},
},
Replication: &opsmngr.Replication{
ReplSetName: "myReplicaSet",
},
Storage: &opsmngr.Storage{
DBPath: "/data/db",
DirectoryPerDB: pointy.Bool(true),
WiredTiger: &map[string]interface{}{
"collectionConfig": map[string]interface{}{},
"engineConfig": map[string]interface{}{
"cacheSizeGB": 1,
},
"indexConfig": map[string]interface{}{},
},
},
SystemLog: opsmngr.SystemLog{
Destination: "file",
Path: "/data/log/mongodb.log",
},
},
AuthSchemaVersion: 5,
Disabled: false,
FeatureCompatibilityVersion: "4.4",
Hostname: "n1.omansible.int",
LogRotate: &opsmngr.LogRotate{
SizeThresholdMB: 1000,
TimeThresholdHrs: 24,
},
ManualMode: false,
Name: "myReplicaSet_1",
ProcessType: "mongod",
Version: "4.4.1-ent",
}
got := newReplicaSetProcess(p, "myReplicaSet")
assert.Equal(t, got, want)
}