-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Support MongoDB session-wide write concern #3646
Changes from 4 commits
c2e2897
b8c4366
8807a27
24f37a2
6934d5c
2415f81
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,16 @@ type mongoDBStatement struct { | |
Roles mongodbRoles `json:"roles"` | ||
} | ||
|
||
// writeConcern is the mgo.Safe struct with JSON tags | ||
// More info: https://godoc.org/gopkg.in/mgo.v2#Safe | ||
type writeConcern struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this struct or can we just use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, we might not need the JSON tags if there's no snake-casing on the fields so this could probably go away. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, in that case i'd say it's fine to leave this struct as is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We agreed offline that this is okay to remove since we are following mongoDB's naming convention (e.g. |
||
W int `json:"w"` // Min # of servers to ack before success | ||
WMode string `json:"w_mode"` // Write mode for MongoDB 2.0+ (e.g. "majority") | ||
WTimeout int `json:"wtimeout"` // Milliseconds to wait for W before timing out | ||
FSync bool `json:"fsync"` // Sync via the journal if present, or via data files sync otherwise | ||
J bool `json:"j"` // Sync via the journal if present | ||
} | ||
|
||
// Convert array of role documents like: | ||
// | ||
// [ { "role": "readWrite" }, { "role": "readWrite", "db": "test" } ] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,26 @@ has a number of parameters to further configure a connection. | |
|
||
| Method | Path | Produces | | ||
| :------- | :--------------------------- | :--------------------- | | ||
| `POST` | `/database/config/:name` | `204 (empty body)` | | ||
| `POST` | `/database/config/:name` | `204 (empty body)` | | ||
|
||
### Parameters | ||
- `connection_url` `(string: <required>)` – Specifies the MongoDB standard connection string (URI). | ||
|
||
- `connection_url` `(string: <required>)` – Specifies the MongoDB standard | ||
connection string (URI). | ||
- `write_concern` `(string: "")` - Specifies the MongoDB [write | ||
concern][mongodb-write-concern]. This is set for the entirety of the session, | ||
maintained for the lifecycle of the plugin process. Must be a serialized JSON | ||
object, or a base64-encoded serialized JSON object. The JSON payload values | ||
map to the values in the [Safe][mgo-safe] struct from the mgo driver. | ||
|
||
### Sample Payload | ||
|
||
```json | ||
{ | ||
"plugin_name": "mongodb-database-plugin", | ||
"allowed_roles": "readonly", | ||
"connection_url": "mongodb://admin:[email protected]:27017/admin?ssl=true" | ||
"connection_url": "mongodb://admin:[email protected]:27017/admin?ssl=true", | ||
"write_concern": "{ \"wmode\": \"majority\", \"wtimeout\": 5000 }" | ||
} | ||
``` | ||
|
||
|
@@ -68,7 +76,7 @@ list the plugin does not support that statement type. | |
[MongoDB's documentation](https://docs.mongodb.com/manual/reference/method/db.createUser/). | ||
|
||
- `revocation_statements` `(string: "")` – Specifies the database statements to | ||
be executed to revoke a user. Must be a serialized JSON object, or a base64-encoded | ||
be executed to revoke a user. Must be a serialized JSON object, or a base64-encoded | ||
serialized JSON object. The object can optionally contain a "db" string. If no | ||
"db" value is provided, it defaults to the "admin" database. | ||
|
||
|
@@ -84,4 +92,7 @@ list the plugin does not support that statement type. | |
} | ||
] | ||
} | ||
``` | ||
``` | ||
|
||
[mongodb-write-concern]: https://docs.mongodb.com/manual/reference/write-concern/ | ||
[mgo-safe]: https://godoc.org/gopkg.in/mgo.v2#Safe |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be better to do in the Initialize function and cache the
writeConcern
object in the struct. Will save on marshaling it on every call.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This only gets through if
Connection()
creates a new session, otherwise it will return pretty early up top. Since other session settings were set here, I thought callingSetSafe
here as well.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also probably better to return any unmarshaling errors during Init too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say decode and unmarshal in Init, store the
mgo.Safe
pointer in the struct and callSetSafe
inConnection()