emicklei / mora Goto Github PK
View Code? Open in Web Editor NEWMongoDB generic REST server in Go
MongoDB generic REST server in Go
Each time I used another ip for http.server.host
setting throws a binding exeception, here is the full log:
2016/10/24 18:24:55 [mora][info] loading configuration from [mora.properties]
[restful] 2016/10/24 18:24:55 log.go:30: [restful/swagger] listing is available at http://192.168.56.103:8181/apidocs.json
[restful] 2016/10/24 18:24:55 log.go:30: [restful/swagger] http://192.168.56.103:8181/apidocs/ is mapped to folder ./swagger-ui/dist
2016/10/24 18:24:55 [mora][info] ready to serve on http://192.168.56.103:8181
2016/10/24 18:24:55 listen tcp 192.168.56.103:8181: bind: cannot assign requested address
it works with localhost or empty string, whatever else fails.
Hey, I'd like to have some authentication options for mora API usage.
I think it should be some out-of mongo, distributable authentication service, maybe Keystone (api docs) which is common choice in public and private clouds today as it's part of popular and strong OpenStack.
I would like to hear other options and opinions about them, and maybe some voices against my word because Keystone was just a shot.
Is it by design or how can I reuse the TCP connection.
Looking at netstat this appears to be resulting in a new connection for every post resulting in a large number of concurrent connections being open.
What is the correct way to reuse connections in this case?
I'm trying to build mora in a new environment, but it's failing because it looks like the emicklei/goproperties repository has been deleted from github: https://github.com/emicklei/goproperties Was this intentional? I think I was building successfully last month when I thinks this repo still existed.
$ go get
# cd .; git clone https://github.com/emicklei/goproperties /tmp/gocode/src/github.com/emicklei/goproperties
Cloning into '/tmp/gocode/src/github.com/emicklei/goproperties'...
ERROR: Repository not found.
fatal: Could not read from remote repository.
I found the original upstream repo at dmotylev/goproperties, so I'm not sure if mora could be switched over to use that directly, or if there was relevant changes in your forked repo that are needed.
Thanks!
I am trying to bring up an API for my mongoDB instance.
I currently have a user with read only rules that I can connect with so my mora.properties file looks like this:
#listener info is required
http.server.host=0.0.0.0
http.server.port=9123
mongo.db.uri=mongodb://user:pass@localhost:27017/mydb
I have also tried the following
#listener info is required
http.server.host=0.0.0.0
http.server.port=9123
#Auth
mongod.mydb.databse=mydb
mongod.mydb.username=user
mongod.mydb.password=pass
mondod.mydb.host=localhost
mondod.mydb.port=27017
But when I try to do the following
$ curl http://localhost:9123/docs/mydb
{
"success": false,
"error": {
"code": 401,
"name": "unauthorized"
}
}
And the Mora instance logs:
2015/06/20 05:32:00 [mora] connecting to [db=mongodb://user:pass@localhost:27014/mydb] with timeout [0 seconds]
2015/06/20 05:32:00 [mora][error] unauthorized
Needless to say - I have checked my user authentication info several times - it is correct.
The thing is - I have tried the exact same URI for mongoDB in another app (node.js mongodb-rest api) and it works, but for some reason Mora fails to authenticate.
Any ideas how to go around that?
Hey!
Today I was writing a small HTTP API using MongoDB as a storage and I just thought, what if I could reuse mora? Tell me what do You think about it and check code which is my first attempt, I have decoupled and a little bit documented the code. It makes mora a little bit more reusable but we can go further.
I wrote a json like {"a":10} into mongodb with mora, but the integer 10 becomes a double number 10.00 after writing. How to wrote a integer?
When I'm creating a request to mora using Google Chrome I'm getting error:
xml: unsupported type: bson.M
Request:
GET /docs/lab/appg_test_env1/clients/5334dce9b734f91194000001 HTTP/1.1
Host: 127.0.0.1:4000
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
I don't know how to build golang project.
If your MongoDB documents contain a certain type of UUID for an _id, Mora returns the ID as an object like this:
"_id": {
"Kind": 3,
"Data": "ABnJswg/6EKEoibo1A6/yQ=="
}
It does not appear possible to interact with the document level of the API (GET,PUT,DELETE) using this format with Swagger.
It looks like Mora supports some form of Hex object id. Not sure why this type shows up like this or what "Kind" refers to. These were documents which had a .NET GUID as an ID and were added to MongoDB using the official C-Sharp driver.
In MongoClient the id looks like: BinData(3,"ABnJswg/6EKEoibo1A6/yQ==")
In Robomongo the id looks like: LUUID("c1fad936-f455-d543-be73-07970d6eac1e")
or with .NET id encoding like: NUUID("36d9fac1-55f4-43d5-be73-07970d6eac1e")
I know this is just a demo project and I am rather new to GoLang but, if you have some general advice about how to solve this, I would be willing to try a fix and submit a pull request.
Is there an easy way to add auth mechanism in mora.
Just like this link https://github.com/mongodb-labs/sleepy.mongoose/wiki/Database-Commands
When I tried to insert integer to mongodb, I found that mongodb shell is needed for this situation. Finding documents api of mora seems like support query operation only.
I was attempting to perform a PUT operation from Angular and kept getting rejected by CORS in Chrome. I checked the GET request I did prior to the PUT and noticed it went through fine (though no OPTIONS request was done for the GET). Upon attempting a PUT, the OPTIONS request goes through and returns a 200 as you'd expect with the Allow response header, but not the Access-Control-Allow-Origin or Access-Control-Expose-Headers headers. This caused Chrome to deny the request.
I've done some digging in mora and go-restful and it looks like the CrossOriginResourceSharing Filter method isn't being called on the OPTIONS request, though I'm not sure if that's by design and the OPTIONSFilter container func should be handling this instead. The CrossOriginResourceSharing filter method does get called successfully for the GET. I haven't checked to see if it gets called for DELETE or POST yet.
Also, for completeness sake, I haven't touched the cors setting in mora.properties. It was left in its default state of true.
Thanks for the great project!
Been playing around with this and realized it almost meets the needs I have except for I want to be able to do some GPG application-level field encryption on the server side before any PUT or POST would make it actually into the DB. Of course this would be over HTTPs as well and hadn't read of support for that as well.
But my main question is really related to being able to do 99% CRUD with mora and then 1% application specific data transformations, log triggers and the like with some sort of hook. I suppose I could just customize mora to my needs, but was wondering if any thought had already been given into providing such hooks into the pipeline.
curl 'http://****?skip=1&limit=1'
response :
{
"success": true,
"data": []
}
change limit =2 , the resoponse is ok .
looks like : limit=1, skip >= 1 , empty
limit = 1, skip = 0 , ok
limit > 1, ok
I find len(iter.docData)=0 and iter.err = "not found"
resp.WriteHeader(status)
in WriteStatus (response.go)
is not required anymore as WriteEntity
in go-restful support WriteHeaderAndEntity
. So, we can use only resp.WriteHeaderAndEntity(status, r)
That creates "multiple response.WriteHeader calls" in logs.
I think its a good idea to validate the documents before we insert into the database, Using some kind of configuration includes a schema definition for every resource managed by the API.
There is an error which occurs when we want to update a document using putDocument.
Example request:
Request URL: http://127.0.0.1:8080/docs/local/use1/services/531c584fb734f914a8000001
Request Method: PUT
Status Code: 500 Internal Server Error
Request payload:
{
"_id": "531c584fb734f914a8000001",
"domain": "",
"icon": "",
"name": "test",
"state": "Ok",
"type": "Big Platform"
}
Response:
cannot change _id of a document old:{ _id: ObjectId('531c584fb734f914a8000001'), domain: "", icon: "", name: "test", state: "Ok", type: "Computing Service" } new:{ _id: "531c584fb734f914a8000001", domain: "", icon: "", name: "test", state: "Ok", type: "Big Platform" }
As u can see _id
value is a string. Mora doesn't treat it like a string from _id
path parameter (it should transform it into a ObjectIdHex) that's why error occurs.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.