new: [api] namespace API access added

You can do queries like:

- http://127.0.0.1:5000/namespace/finduuid/mitre-attack-id/T1589.003

and also list the known namespaces of the CyCAT instance.

curl -X 'GET' \
  'http://127.0.0.1:5000/namespace/getall' \
    -H 'accept: application/json'

and get

[
  "capec",
  "mitre-attack-id"
]
main
Alexandre Dulaunoy 2021-05-29 16:24:30 +02:00
parent db0c41a2a0
commit 513ad99b93
No known key found for this signature in database
GPG Key ID: 09E2CD4944E6CBCD
2 changed files with 28 additions and 0 deletions

View File

@ -33,6 +33,7 @@ class info(Resource):
info['publishers'] = r.zcard('t:1')
info['projects'] = r.zcard('t:2')
info['items'] = r.zcard('t:3')
info['namespaces'] = r.scard('idnamespace')
info['version'] = version
return info
@ -139,6 +140,32 @@ class relationshipsexpanded(Resource):
else:
return {'message': 'UUID is incorrect'}, 400
@api.route('/namespace/getall')
@api.doc(description="List all known namespaces.")
class namespacegetall(Resource):
def get(self):
s = r.smembers("idnamespace")
return(list(s))
@api.route('/namespace/getid/<string:namespace>')
@api.doc(description="Get all ID from a given namespace.")
class namespacegetid(Resource):
def get(self, namespace=None):
if namespace is None:
return None
k = "idk:{}".format(namespace)
s = r.smembers(k)
return(list(s))
@api.route('/namespace/finduuid/<string:namespace>/<string:namespaceid>')
@api.doc(description="Get all known UUID for a given namespace id.")
class namespacefinduuid(Resource):
def get(self, namespace=None, namespaceid=None):
if namespaceid is None or namespace is None:
return None
k = "id:{}:{}".format(namespace, namespaceid)
s = r.smembers(k)
return(list(s))
if __name__ == '__main__':
app.run()

View File

@ -48,6 +48,7 @@ def addexternalid(uuidsource=None, namespace=None, namespaceid=None):
rdb.sadd(k, uuidsource)
k = "idk:{}".format(namespace)
rdb.sadd(k, namespaceid)
rdb.sadd("idnamespace", namespace)
models = ['enterprise-attack', 'mobile-attack', 'ics-attack', 'pre-attack']