-
Notifications
You must be signed in to change notification settings - Fork 25
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
feat: adds a MongoDB connector (closes smallstep/certificates#141) #52
base: master
Are you sure you want to change the base?
feat: adds a MongoDB connector (closes smallstep/certificates#141) #52
Conversation
This commit adds a MongoDB connector. A couple of things to note: - To enable transactions the database must a replica set, I made the connection fail if the condition was not met. MongoDB is a document database, thus concepts translate as: bucket/table = collection key = document value = document value Note: mongo will automatically create a collection if a operation is attempted on one that does not exist. For example: if you delete a table, then call list to check for the contents of the table it will be recreated. closes smallstep/certificates#141
Thank you, @elasticspoon! We've done a first pass of review. |
7652cc6
to
ae85109
Compare
removes use of github/errors package, uses fmt.Errorf instead changes syntax of error messages changes order of context as a parameter makes sure session is passed down where possible renames bucket to collection other minor fixes for review
ae85109
to
6fdea12
Compare
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.
Thank you for the improvements, @elasticspoon! 🙂
I've done another pass. It may seem like much, but it's mostly many cases of the same thing. Most things are just textual too.
We're currently working on a new version of nosql
that changes some things in terms of the exposed interface. It should be available fairly soon. We aim for no / minimal breaking changes, but at this time I can't say for sure what it'll look like. I don't expect big changes to happen to the core of your implementation. It's probably good to await its release and adapt this PR, so that it starts of in a nice way.
f2fb331
to
b850638
Compare
Co-authored-by: Herman Slatman <hslatman@users.noreply.github.com>
b850638
to
00983ad
Compare
mongo/mongo.go
Outdated
if err = session.StartTransaction(txnOptions); err != nil { | ||
return fmt.Errorf("failed to pending transaction: %w", err) | ||
} |
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.
"failed to 'what' pending ..."
b36b3e2
to
515e0c6
Compare
if err := db.CreateTable(op.Bucket); err != nil { | ||
return abort(ctx, session, fmt.Errorf("failed creating table %s: %w", op.Bucket, err)) | ||
} | ||
case database.DeleteTable: | ||
if err := db.DeleteTable(op.Bucket); err != nil { | ||
return abort(ctx, session, fmt.Errorf("failed deleting table %s: %w", op.Bucket, err)) | ||
} | ||
case database.Get: | ||
if op.Result, err = db.get(ctx, op.Bucket, op.Key); err != nil { | ||
return abort(ctx, session, fmt.Errorf("failed getting %s/%s: %w", op.Bucket, op.Key, err)) | ||
} | ||
case database.Set: | ||
if err := db.set(ctx, op.Bucket, op.Key, op.Value); err != nil { | ||
return abort(ctx, session, fmt.Errorf("failed setting %s/%s: %w", op.Bucket, op.Key, err)) | ||
} | ||
case database.Delete: | ||
if err := db.del(ctx, op.Bucket, op.Key); err != nil { | ||
return abort(ctx, session, fmt.Errorf("failed deleting %s/%s: %w", op.Bucket, op.Key, err)) | ||
} | ||
case database.CmpAndSwap: | ||
op.Result, op.Swapped, err = db.cmpAndSwap(ctx, op.Bucket, op.Key, op.CmpValue, op.Value) | ||
if err != nil { | ||
return abort(ctx, session, fmt.Errorf("failed load-or-store on %s/%s: %w", op.Bucket, op.Key, err)) |
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 think this is better in terms of error message clarity. Errors will now say what operation an Update failed to followed by the reason that operation failed.
515e0c6
to
74bf56f
Compare
Changes to error syntax
74bf56f
to
41c3aba
Compare
This commit adds a MongoDB connector and closes smallstep/certificates#141
Note: To enable transactions the database must a replica set, I made the connection fail if the condition was not met.
I am not sure if this is the best way to go about it. But I am also not sure how often the basic CRUD operations are used outside of transactions.
MongoDB is a document database, thus concepts translate as:
bucket/table = collection
key = document
value = document value
Name of feature:
MongoDB connector
Pain or issue this feature alleviates:
Closes smallstep/certificates#141
Why is this important to the project (if not answered above):
Closes smallstep/certificates#141
Is there documentation on how to use this feature? If so, where?
Implements the database interface
In what environments or workflows is this feature supported?
Same as all the rest of the connectors. Transactions require Mongo to be configured as a replica set.
In what environments or workflows is this feature explicitly NOT supported (if any)?
Not supported in CI tests.
Supporting links/other PRs/issues: