Skip to content

Commit

Permalink
Merge pull request #27 from diggyk/master
Browse files Browse the repository at this point in the history
Added simple query passthrough
  • Loading branch information
gmjosack committed Jul 27, 2015
2 parents 3447067 + 71d6a46 commit 2c3d451
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 2 deletions.
57 changes: 56 additions & 1 deletion hermes/handlers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2196,4 +2196,59 @@ def delete(self, id):
*Not supported*
"""
self.not_supported()
self.not_supported()


class ExtQueryHandler(ApiHandler):
def get(self):
"""**Get results from the external query services**
The frontend will need to run queries against the external query server
so that users can validate the results before working with a particular
query. This handler acts as a passthrough so users can do exactly that.
**Example Request:**
.. sourcecode:: http
GET /api/v1/query?hostQuery=server HTTP/1.1
Host: localhost
**Example response:**
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: application/json
{
"status": "ok",
"results": [
{
"id": 1,
"href": "/api/v1/hosts/server1",
"hostname": "server1",
},
...
]
}
:query string hostQuery: the query to send to the plugin to come up with the list of hostnames
:statuscode 200: The request was successful.
:statuscode 401: The request was made without being logged in.
"""
host_query = self.get_argument("hostQuery", None)

response = PluginHelper.request_get(params={"query": host_query})
if (
response.status_code == 200
and response.json()["status"] == "ok"
):
json = {
"results": response.json()["results"],
}
else:
raise exc.BadRequest("Bad host query: {}".format(host_query))

self.success(json)
3 changes: 3 additions & 0 deletions hermes/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
(r"/api/v1/quests\/?", api.QuestsHandler),
(r"/api/v1/quests/(?P<id>\d+)\/?", api.QuestHandler),

# Queries to 3rd party tools
(r"/api/v1/extquery\/?", api.ExtQueryHandler),

# Frontend Handlers
(r"/.*", frontends.AppHandler),
]
2 changes: 1 addition & 1 deletion hermes/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.2.3"
__version__ = "0.2.4"

0 comments on commit 2c3d451

Please sign in to comment.