From efa0c7c992bda7930ba7b40abfd6f3e4718db4d5 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Fri, 24 Sep 2021 09:02:21 +0200 Subject: Update README --- README.md | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index c391971..6bb4d49 100644 --- a/README.md +++ b/README.md @@ -63,13 +63,15 @@ Start CouchDB, make sure to give it a username and password: Start the demo HTTP server. Here we should pass on a few environment variables to let it know which CouchDB to use: + cd demo export DB_NAME=test export DB_HOSTNAME=localhost export DB_USERNAME=couchdb export DB_PASSWORD=insecure - python3 src/wsgi.py + python3 ../src/wsgi.py -Submit some data. +Try adding some observations, basic auth user:pw from `wsgi_demo_users.yaml`, +including `{"domain": "sunet.se"}` in at least one of them: echo '[{ "ip": "192.0.2.10", @@ -90,12 +92,12 @@ Submit some data. "cve_2021_21974": "CVE-2021-21974 patched", "cve_2021_21985": "CVE-2021-21985 not applicable" } - }]' | curl -s -u admin:admin --data-binary @- http://localhost:8000/sc/v0/add + }]' | curl -s -u user3:pw3 --data-binary @- http://localhost:8000/sc/v0/add -Get the same data back. +Try retreiving all observations for a user with read access to 'sunet.se': - curl -s -u sunet.se: http://localhost:8000/sc/v0/get | json_pp -json_opt utf8,pretty + curl -s -u user1:pw1 http://localhost:8000/sc/v0/get | json_pp -json_opt utf8,pretty We might also filter the data: - curl -s -u sunet.se: http://localhost:8000/sc/v0/get?port=111 | json_pp -json_opt utf8,pretty + curl -s -u user1:pw1 http://localhost:8000/sc/v0/get?port=111 | json_pp -json_opt utf8,pretty -- cgit v1.1 From f6c1c22c832495d78be8ed2e1286701b760bf156 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Fri, 24 Sep 2021 09:04:02 +0200 Subject: Add .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..44bba42 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +demo/wsgi_demo.db -- cgit v1.1 From caef9eeb267fa19bf370274538f97efc6d4b8776 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Fri, 24 Sep 2021 09:08:28 +0200 Subject: Enable CORS --- src/wsgi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wsgi.py b/src/wsgi.py index 49c1c17..ef1e36f 100755 --- a/src/wsgi.py +++ b/src/wsgi.py @@ -104,7 +104,7 @@ class EPAdd(CollectorResource): def init(url_res_map, addr='', port=8000): - app = falcon.App() + app = falcon.App(cors_enable=True) for url, res in url_res_map: app.add_route(url, res) return make_server(addr, port, app) -- cgit v1.1 From f3204eecc33c60289ea0c2117ed3316beb59cde5 Mon Sep 17 00:00:00 2001 From: Ernst Widerberg Date: Tue, 28 Sep 2021 09:49:35 +0200 Subject: Fix: Add list of observations --- src/db.py | 8 ++++++-- src/wsgi.py | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/db.py b/src/db.py index 0c7e998..fa201aa 100755 --- a/src/db.py +++ b/src/db.py @@ -37,15 +37,19 @@ class DictDB(): pass def add(self, data, batch_write=False): - key = str(self.unique_key()) + keys = [] if type(data) is list: for item in data: + key = str(self.unique_key()) self.couchdb[key] = item + keys.append(key) else: + key = str(self.unique_key()) self.couchdb[key] = data + keys.append(key) - return key + return keys def get(self, key): return self.couchdb[key] diff --git a/src/wsgi.py b/src/wsgi.py index ef1e36f..e99ac74 100755 --- a/src/wsgi.py +++ b/src/wsgi.py @@ -99,8 +99,8 @@ class EPAdd(CollectorResource): resp.text = CollectorResource.parse_error(decodedin) return - key = self._db.add(json_data) - resp.text = repr(key) + '\n' + keys = self._db.add(json_data) + resp.text = repr(keys) + '\n' def init(url_res_map, addr='', port=8000): -- cgit v1.1