Skip to content

Commit

Permalink
fixing the createUser/updateUser cmd invokation in a3s to correct use…
Browse files Browse the repository at this point in the history
… bson document (#107)
  • Loading branch information
knainwal authored Aug 27, 2024
1 parent 42ab85d commit f91edd8
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions cmd/a3s/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,20 @@ func createMongoDBAccount(cfg conf.MongoConf, username string) error {

db := manipmongo.GetDatabase(m)

role := map[string][]string{
"a3s": {"readWrite", "dbAdmin"},
roles := bson.A{
bson.D{
{Key: "role", Value: "readWrite"},
{Key: "db", Value: "a3s"},
},
bson.D{
{Key: "role", Value: "dbAdmin"},
{Key: "db", Value: "a3s"},
},
}

createCommand := bson.D{
{Key: "createUser", Value: username},
{Key: "roles", Value: bson.A{
bson.D{
{Key: "role", Value: role},
{Key: "db", Value: db.Name},
},
}},
{Key: "roles", Value: roles},
}

err := db.RunCommand(context.Background(), createCommand).Err()
Expand All @@ -408,12 +411,7 @@ func createMongoDBAccount(cfg conf.MongoConf, username string) error {
// User already exists, update user instead
updateCommand := bson.D{
{Key: "updateUser", Value: username},
{Key: "roles", Value: bson.A{
bson.D{
{Key: "role", Value: role},
{Key: "db", Value: db.Name},
},
}},
{Key: "roles", Value: roles},
}
if err := db.RunCommand(context.Background(), updateCommand).Err(); err != nil {
return fmt.Errorf("unable to upsert the user: %w", err)
Expand Down

0 comments on commit f91edd8

Please sign in to comment.