dservercore 0.20.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,857 @@
1
+ Metadata-Version: 2.1
2
+ Name: dservercore
3
+ Version: 0.20.0
4
+ Summary: Web API to register/lookup/search for dtool dataset metadata
5
+ Author-email: Tjelvar Olsson <tjelvar.olsson@gmail.com>
6
+ License: MIT License
7
+
8
+ Copyright (c) 2018 jic-dtool
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy
11
+ of this software and associated documentation files (the "Software"), to deal
12
+ in the Software without restriction, including without limitation the rights
13
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14
+ copies of the Software, and to permit persons to whom the Software is
15
+ furnished to do so, subject to the following conditions:
16
+
17
+ The above copyright notice and this permission notice shall be included in all
18
+ copies or substantial portions of the Software.
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26
+ SOFTWARE.
27
+
28
+ Project-URL: Documentation, https://dservercore.readthedocs.io
29
+ Project-URL: Repository, https://github.com/jic-dtool/dservercore
30
+ Project-URL: Changelog, https://github.com/jic-dtool/dservercore/blob/main/CHANGELOG.rst
31
+ Description-Content-Type: text/x-rst
32
+ License-File: LICENSE
33
+ Requires-Dist: setuptools
34
+ Requires-Dist: flask <3
35
+ Requires-Dist: pymongo
36
+ Requires-Dist: alembic
37
+ Requires-Dist: flask-sqlalchemy
38
+ Requires-Dist: flask-migrate
39
+ Requires-Dist: flask-pymongo
40
+ Requires-Dist: flask-marshmallow
41
+ Requires-Dist: flask-smorest
42
+ Requires-Dist: marshmallow-sqlalchemy
43
+ Requires-Dist: flask-cors
44
+ Requires-Dist: dtoolcore >=3.18.0
45
+ Requires-Dist: flask-jwt-extended[asymmetric_crypto] >=4.0
46
+ Requires-Dist: pyyaml
47
+ Provides-Extra: docs
48
+ Requires-Dist: sphinx ; extra == 'docs'
49
+ Requires-Dist: sphinx-rtd-theme ; extra == 'docs'
50
+ Requires-Dist: sphinxcontrib-spelling ; extra == 'docs'
51
+ Requires-Dist: myst-parser ==3.0.1 ; extra == 'docs'
52
+ Provides-Extra: test
53
+ Requires-Dist: pytest ; extra == 'test'
54
+ Requires-Dist: pytest-cov ; extra == 'test'
55
+
56
+ dservercore
57
+ ===========
58
+
59
+ .. |dtool| image:: https://github.com/livMatS/dservercore/blob/main/icons/22x22/dtool_logo.png?raw=True
60
+ :height: 20px
61
+ :target: https://github.com/livMatS/dservercore
62
+ .. |pypi| image:: https://img.shields.io/pypi/v/dservercore
63
+ :target: https://pypi.org/project/dservercore/
64
+ .. |tag| image:: https://img.shields.io/github/v/tag/livMatS/dservercore
65
+ :target: https://github.com/livMatS/dservercore/tags
66
+ .. |test| image:: https://img.shields.io/github/actions/workflow/status/livMatS/dservercore/test.yml?branch=main
67
+ :target: https://github.com/livMatS/dservercore/actions/workflows/test.yml
68
+
69
+ |dtool| |pypi| |tag| |test|
70
+
71
+ - GitHub: https://github.com/livMatS/dservercore
72
+ - PyPI: https://pypi.python.org/pypi/dservercore
73
+ - Free software: MIT License
74
+
75
+
76
+ Features
77
+ --------
78
+
79
+ - Use a dataset UUID to lookup one more URIs where the dataset is stored
80
+ - Search for datasets of interest using free text search
81
+ - Built in support to manage users
82
+ - Built in support to manage base URIs
83
+ - Build in support to manage a user permissions on base URIs
84
+ - Built in support for authentication using JSON web tokens
85
+
86
+
87
+ Introduction
88
+ ------------
89
+
90
+ `dtool <https://dtool.readthedocs.io>`_ is a command line tool for packaging
91
+ data and metadata into a dataset. A dtool dataset manages data and metadata
92
+ without the need for a central database.
93
+
94
+ However, if one has to manage more than a hundred datasets it can be helpful
95
+ to have the datasets' metadata stored in a central server to enable one to
96
+ quickly find datasets of interest.
97
+
98
+ ``dserver`` provides a web API for registering datasets' metadata
99
+ and provides functionality to lookup, list and search for datasets.
100
+
101
+ When managing many groups data it can be useful to ensure that users can only
102
+ access metadata associated with datasets stored in base URI's that they have
103
+ been given access to. ``dserver`` therefore provides means to
104
+ manage users, base URIs and users' permissions on those base URIs.
105
+
106
+ ``dserver`` is consumed by the `dtool-lookup-client
107
+ <https://github.com/jic-dtool/dtool-lookup-client>`_, and the
108
+ `dtool-lookup-webapp <https://github.com/jic-dtool/dtool-lookup-webapp>`_.
109
+ Third party applications making use of the dserver have also been
110
+ created, notably the `livMatS/dtool-lookup-gui
111
+ <https://github.com/livMatS/dtool-lookup-gui>`_.
112
+
113
+ ``dservercore`` provides the core Flask app central to dserver's
114
+ modular, pluggable framework.
115
+
116
+ Installation
117
+ ------------
118
+
119
+ Install ``dservercore``::
120
+
121
+ $ pip install dservercore
122
+
123
+ For a minimal setup, dserver requires search and retrieve plugins.
124
+ Pick search and retrieve plugins of your choice and install those. Here, the
125
+ ``dserver-search-plugin-mongo`` and ``dserver-retrieve-plugin-mongo``
126
+ serve as default for demonstration::
127
+
128
+ $ pip install dserver-search-plugin-mongo
129
+ $ pip install dserver-retrieve-plugin-mongo
130
+
131
+ Setup and configuration
132
+ -----------------------
133
+
134
+ Configure the Flask app
135
+ ^^^^^^^^^^^^^^^^^^^^^^^
136
+
137
+ ``dserver`` is a Flask app. Flask needs to know where to look for
138
+ the app. One therefore needs to define the ``FLASK_APP`` environment variable::
139
+
140
+ $ export FLASK_APP=dservercore
141
+
142
+ Configure search and retrieve plugins
143
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144
+
145
+ ``dserver`` is agnostic of how descriptive data is stored and
146
+ searched. The implementation is delegated to search and retrieve plugins.
147
+ Refer to their documentation for details on their configuration.
148
+
149
+ In the sample case of ``dserver-search-plugin-mongo`` and
150
+ ``dserver-retrieve-plugin-mongo``, the same Mongo database
151
+ can be used for both search and information retrieval.
152
+
153
+ Create a directory where the MongoDB data will be stored::
154
+
155
+ $ mkdir data
156
+
157
+ Start Mongo DB, for example using docker::
158
+
159
+ $ docker run -d -p 27017:27017 -v `pwd`/data:/data/db mongo
160
+
161
+ Configure the search plugin with::
162
+
163
+ export SEARCH_MONGO_URI="mongodb://localhost:27017/"
164
+ export SEARCH_MONGO_DB="dserver"
165
+ export SEARCH_MONGO_COLLECTION="datasets"
166
+
167
+ and the retrieve plugin with::
168
+
169
+ export RETRIEVE_MONGO_URI="mongodb://localhost:27017/"
170
+ export RETRIEVE_MONGO_DB="dserver"
171
+ export RETRIEVE_MONGO_COLLECTION="datasets"
172
+
173
+ This must happen before issuing any ``flask`` commands as below.
174
+
175
+ Configure the SQL database
176
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^
177
+
178
+ ``dserver`` stores administrative metadata in a SQL database.
179
+ By default it uses a SQLite database. However, this can be configured by
180
+ setting the ``SQLALCHEMY_DATABASE_URI``, i.e using something along the lines of::
181
+
182
+ export SQLALCHEMY_DATABASE_URI=mysql://username:password@server/db
183
+
184
+ Importantly, you will need an according Python connector for whatever SQL database
185
+ you decide to use, e.g. `psycopg2` for PostgreSQL or `mysqlclient` for MySQL.
186
+
187
+ For more information see `flask-SQLAlchemy
188
+ <http://flask-sqlalchemy.pocoo.org>`_.
189
+
190
+ Versioning of the relational database is handled using
191
+ `flask-Migrate <https://flask-migrate.readthedocs.io>`_
192
+
193
+ Populate the SQL database with tables using the commands below::
194
+
195
+ $ flask db init
196
+ $ flask db migrate
197
+ $ flask db upgrade
198
+
199
+ Configure a public and private key pair
200
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
201
+
202
+ ``dserver`` implements authentication using JSON Web Tokens.
203
+ Private and public key can for example be generated with::
204
+
205
+ openssl genrsa -out /path/to/private/jwt_key 2048
206
+ openssl rsa -in /path/to/private/jwt_key -pubout -outform PEM -out /path/to/public/jwt_key.pub
207
+
208
+ It is possible to delegate the generation of JSON Web Tokens to a different
209
+ service as long as one has access to the public key::
210
+
211
+ export JWT_PUBLIC_KEY_FILE=~/.ssh/id_rsa.pub
212
+
213
+ If one has access to the private key as well one can use the ``flask user
214
+ token`` command line utility to generate a token for the user. To enable this
215
+ one has to set the ``JWT_PRIVATE_KEY_FILE`` environment variable::
216
+
217
+ export JWT_PRIVATE_KEY_FILE=~/.ssh/id_rsa
218
+
219
+ Mac users be warned that the Mac's implementation ``ssh-keygen`` may result in
220
+ files that do not adhere to the RFC standard. As such you may get a warning
221
+ along the lines of::
222
+
223
+ ValueError: Could not deserialize key data.
224
+
225
+ In this case you need to find a version of ``ssh-keygen`` that generates files
226
+ that adhere to the RFC standard, the easiest is probably to generate them in Linux.
227
+
228
+ Making use of JSON Web Tokens from a different server
229
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
230
+
231
+ When making use of JSON Web Tokens from a different server it may be easier to
232
+ use configure the server using the pubic key directly rather than the public key
233
+ file::
234
+
235
+ export JWT_PUBLIC_KEY="ssh-rsa XXXXXX user@localhost"
236
+
237
+ Inspecting the flask app configuration
238
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
239
+
240
+ Inspect the Flask app configuration with::
241
+
242
+ $ flask config show
243
+ {
244
+ "DEBUG": false,
245
+ "TESTING": false,
246
+ "PROPAGATE_EXCEPTIONS": null,
247
+ "SECRET_KEY": "***",
248
+ ...
249
+ }
250
+
251
+
252
+ The output is JSON-formatted with lower-case keys and will include plugin
253
+ configuration parameters as well.
254
+
255
+ Inspect the installed ``dserver`` components with::
256
+
257
+ $ flask config versions
258
+ {
259
+ "dservercore": "0.17.2",
260
+ "dserver_retrieve_plugin_mongo": "0.1.0",
261
+ "dserver_search_plugin_mongo": "0.1.0"
262
+ }
263
+
264
+ Starting the flask app
265
+ ^^^^^^^^^^^^^^^^^^^^^^
266
+
267
+ The Flask web app can be started using the command below::
268
+
269
+ $ flask run
270
+
271
+
272
+ Populating dserver using the CLI
273
+ --------------------------------
274
+
275
+ Indexing a base URI
276
+ ^^^^^^^^^^^^^^^^^^^
277
+
278
+ Datasets can be stored on filesystem and in object storage such as AWS S3. In
279
+ an AWS S3 bucket datasets are stored in a flat structure and the bucket itself
280
+ is the base URI. To index all the datasets in the S3 bucket, the base URI, one
281
+ first needs to register it in ``dserver``::
282
+
283
+ flask base_uri add s3://dtool-demo
284
+
285
+ One can then index it using the command::
286
+
287
+ $ flask base_uri index s3://dtool-demo
288
+ Registered: s3://dtool-demo/8ecd8e05-558a-48e2-b563-0c9ea273e71e
289
+ Registered: s3://dtool-demo/907e1b52-d649-476a-b0bc-643ef769a7d9
290
+ Registered: s3://dtool-demo/af6727bf-29c7-43dd-b42f-a5d7ede28337
291
+ Registered: s3://dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db
292
+ Registered: s3://dtool-demo/c58038a4-3a54-425e-9087-144d0733387f
293
+ Registered: s3://dtool-demo/faa44606-cb86-4877-b9ea-643a3777e021
294
+
295
+ It is possible to list all the base URIs registered in ``dserver``::
296
+
297
+ $ flask base_uri list
298
+ [
299
+ {
300
+ "base_uri": "s3://dtool-demo",
301
+ "users_with_search_permissions": [],
302
+ "users_with_register_permissions": []
303
+ }
304
+ ]
305
+
306
+ In the output above it is worth noting that there are two types of permissions
307
+ associated with a base URI. "Search" permissions allow a user to search for
308
+ datasets in a base URI. "Register" permissions allow a user to register a
309
+ dataset in ``dserver`` if it is stored in the specific base URI.
310
+
311
+
312
+ Adding a user and managing permissions
313
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
314
+
315
+ The command below adds the user ``olssont`` to ``dserver``::
316
+
317
+ $ flask user add olssont
318
+
319
+ The command below gives the user ``olssont`` search permissions on the
320
+ ``s3://dtool-demo`` base URI::
321
+
322
+ $ flask user search_permission olssont s3://dtool-demo
323
+
324
+ The command below gives the user ``olssont`` register permissions on the
325
+ ``s3://dtool-demo`` base URI::
326
+
327
+ $ flask user register_permission olssont s3://dtool-demo
328
+
329
+
330
+ Creating an admin user
331
+ ^^^^^^^^^^^^^^^^^^^^^^
332
+
333
+ The command below adds the user ``overlord``, with admin privileges, to the
334
+ dtool lookup server::
335
+
336
+ $ flask user add --is_admin overlord
337
+
338
+
339
+ Generating a JSON Web Token for a registered user
340
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
341
+
342
+ The command below can be used to generate a token for a user to authenticate
343
+ with when using the web API::
344
+
345
+ $ flask user token olssont
346
+ eyJhbGciOiJSUzI1NiIsInR5... (truncated)
347
+
348
+
349
+ Listing the registered users
350
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
351
+
352
+ The command below lists the users registered in ``dserver``::
353
+
354
+ $ flask user list
355
+ [
356
+ {
357
+ "username": "olssont",
358
+ "is_admin": false,
359
+ "register_permissions_on_base_uris": [
360
+ "s3://dtool-demo"
361
+ ],
362
+ "search_permissions_on_base_uris": [
363
+ "s3://dtool-demo"
364
+ ]
365
+ },
366
+ {
367
+ "username": "overlord",
368
+ "is_admin": true,
369
+ "register_permissions_on_base_uris": [],
370
+ "search_permissions_on_base_uris": []
371
+ }
372
+ ]
373
+
374
+
375
+ Deleting a user
376
+ ^^^^^^^^^^^^^^^
377
+
378
+ The command below can be used to delete a user::
379
+
380
+ $ flask user delete overlord
381
+
382
+
383
+ Adding and removing admin privileges from an existing user
384
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
385
+
386
+ The command below can be used to give an existing user admin privileges::
387
+
388
+ $ flask user update --is_admin olssont
389
+
390
+ The command below can be used to remove admin privileges from an existing user::
391
+
392
+ $ flask user update olssont
393
+
394
+
395
+ dserver API
396
+ -----------
397
+
398
+ ``dserver`` makes use of the authorized header to pass through the
399
+ JSON web token for authorization. Below we create environment variables for the
400
+ token and the header used in the ``curl`` commands::
401
+
402
+ $ TOKEN=$(flask user token olssont)
403
+ $ HEADER="Authorization: Bearer $TOKEN"
404
+
405
+
406
+ Standard user usage
407
+ ^^^^^^^^^^^^^^^^^^^
408
+
409
+ Looking up URIs based on a dataset's UUID
410
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
411
+
412
+ A dataset can be uniquely identified by it's UUID (Universally Unique
413
+ Identifier). Below we create an environment variable with the UUID of a dataset
414
+ in the s3://dtool-demo bucket::
415
+
416
+ $ UUID=8ecd8e05-558a-48e2-b563-0c9ea273e71e
417
+
418
+ It is possible to list all the location a dataset is located in using the
419
+ command below::
420
+
421
+ $ curl -H $HEADER http://localhost:5000/uuids/$UUID
422
+
423
+ Response content::
424
+
425
+ [
426
+ {
427
+ "base_uri": "s3://dtool-demo",
428
+ "name": "Escherichia-coli-ref-genome",
429
+ "uri": "s3://dtool-demo/8ecd8e05-558a-48e2-b563-0c9ea273e71e",
430
+ "uuid": "8ecd8e05-558a-48e2-b563-0c9ea273e71e"
431
+ }
432
+ ]
433
+
434
+ Note that it is possible for a dataset to be registered in more than one base
435
+ URI. As such looking up a dataset by UUID can result in multiple hits.
436
+
437
+
438
+ Summary information about datasets
439
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
440
+
441
+ An overall summary of datasets accessible to a user can be accessed using the request below::
442
+
443
+ $ curl -H "$HEADER" http://localhost:5000/users/olssont/summary
444
+
445
+ The response will contain JSON content along the lines of::
446
+
447
+ {
448
+ "number_of_datasets": 3,
449
+ "creator_usernames": ["queen"],
450
+ "base_uris": ["s3://mr-men", "s3://snow-white"],
451
+ "datasets_per_creator": {"queen": 3},
452
+ "datasets_per_base_uri": {"s3://mr-men": 1, "s3://snow-white": 2},
453
+ "tags": ["fruit", "veg"],
454
+ "datasets_per_tag": {"fruit": 2, "veg": 1}
455
+ }
456
+
457
+
458
+ Listing all datasets
459
+ ~~~~~~~~~~~~~~~~~~~~
460
+
461
+ All the dataset's that a user has permissions to search for can be listed using
462
+ the request below::
463
+
464
+ $ curl -H "$HEADER" http://localhost:5000/uris
465
+
466
+ Some of the output of the command above is displayed below::
467
+
468
+ [
469
+ {
470
+ "base_uri": "s3://dtool-demo",
471
+ "created_at": 1604860720.736269,
472
+ "creator_username": "olssont",
473
+ "frozen_at": 1604864525.691079,
474
+ "name": "Escherichia-coli-ref-genome",
475
+ "uri": "s3://dtool-demo/8ecd8e05-558a-48e2-b563-0c9ea273e71e",
476
+ "uuid": "8ecd8e05-558a-48e2-b563-0c9ea273e71e"
477
+ },
478
+ ... (truncated)
479
+ {
480
+ "base_uri": "s3://dtool-demo",
481
+ "created_at": 1604860720.736269,
482
+ "creator_username": "olssont",
483
+ "frozen_at": 1604864525.691079,
484
+ "name": "Escherichia-coli-reads-ERR022075",
485
+ "uri": "s3://dtool-demo/faa44606-cb86-4877-b9ea-643a3777e021",
486
+ "uuid": "faa44606-cb86-4877-b9ea-643a3777e021"
487
+ }
488
+ ]
489
+
490
+
491
+
492
+ Searching for specific datasets
493
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
494
+
495
+ The command below does a full text search for the word "microscopy" in the descriptive metadata::
496
+
497
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
498
+ -X POST -d '{"free_text": "microscopy"}' \
499
+ http://localhost:5000/uris
500
+
501
+ Below is the result of this search::
502
+
503
+ [
504
+ {
505
+ "base_uri": "s3://dtool-demo",
506
+ "created_at": "1530803916.74",
507
+ "creator_username": "olssont",
508
+ "frozen_at": "1536749825.85",
509
+ "name": "hypocotyl3",
510
+ "uri": "s3://dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db",
511
+ "uuid": "ba92a5fa-d3b4-4f10-bcb9-947f62e652db"
512
+ }
513
+ ]
514
+
515
+ Below is a JSON string specifying a more complex query that will search for
516
+ datasets with "apples" in the "s3://snow-white" bucket created by either
517
+ "grumpy" or "dopey", and has both of the tags "fruit" and "veg"::
518
+
519
+ {
520
+ "base_uris": ["s3://snow-white"],
521
+ "creator_usernames": ["grumpy", "dopey"],
522
+ "free_text": "apples",
523
+ "tags": ["fruit", "veg"]
524
+ }
525
+
526
+ .. note:: The search engine make use of "OR" logic for the items in
527
+ ``base_uris`` and ``creator_usernames`` lists, but uses
528
+ "AND" logic for filtering the search based on the items
529
+ in the ``tags`` list.
530
+
531
+
532
+ Accessing a dataset's readme, annotations and manifest
533
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
534
+
535
+ The command below retrieves the readme for the dataset with the
536
+ URI ``s3://dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db``::
537
+
538
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
539
+ http://localhost:5000/readmes/s3/dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db
540
+
541
+ The command below retrieves the annotations for the dataset with the
542
+ URI ``s3://dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db``::
543
+
544
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
545
+ http://localhost:5000/annotations/s3/dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db
546
+
547
+ The command below retrieves the tags for the dataset with the
548
+ URI ``s3://dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db``::
549
+
550
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
551
+ http://localhost:5000/tags/s3/dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db
552
+
553
+ The command below retrieves the manifest for the dataset with the
554
+ URI ``s3://dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db``::
555
+
556
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
557
+ http://localhost:5000/manifests/s3/dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db
558
+
559
+
560
+ Getting information about one's own permissions
561
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
562
+
563
+ A user can find out about his/her own permissions using the command below::
564
+
565
+ $ curl -H "$HEADER" http://localhost:5000/users/olssont
566
+
567
+ Response content::
568
+
569
+ {
570
+ "is_admin": false,
571
+ "register_permissions_on_base_uris": [
572
+ "s3://dtool-demo"
573
+ ],
574
+ "search_permissions_on_base_uris": [
575
+ "s3://dtool-demo"
576
+ ],
577
+ "username": "olssont"
578
+ }
579
+
580
+ Data champion user usage
581
+ ^^^^^^^^^^^^^^^^^^^^^^^^
582
+
583
+ A data champion is different from a regular user in that he/she has
584
+ "register" permissions on a base URI. This means that a data champion
585
+ can register metadata about a data to ``dserver``.
586
+
587
+ Registering a dataset
588
+ ~~~~~~~~~~~~~~~~~~~~~
589
+
590
+ Below is an example of how to register a dataset::
591
+
592
+ $ DATASET_INFO='
593
+ {
594
+ "uuid": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
595
+ "base_uri": "s3://dtool-demo",
596
+ "uri": "s3://dtool-demo/8ecd8e05-558a-48e2-b563-0c9ea273e71e",
597
+ "name": "Escherichia-coli-ref-genome",
598
+ "type": "dataset",
599
+ "readme": "{\"accession_id\":\"U00096.3\",\"description\":\"U00096.3genomewithBowtie2indices\",\"index_build_cmd\":\"bowtie2-buildU00096.3.fastareference\",\"index_builder\":\"bowtie2-buildversion2.3.3\",\"link\":\"https://www.ebi.ac.uk/ena/data/view/U00096.3\",\"organism\":\"Escherichiacolistr.K-12substr.MG1655\"},",
600
+ "manifest": {
601
+ "dtoolcore_version": "3.18.2",
602
+ "hash_function": "md5sum_hexdigest",
603
+ "items": {
604
+ "26f0d76fb3c3e34f0c7c8b7c3461b7495761835c": {
605
+ "hash": "06d80eb0c50b49a509b49f2424e8c805",
606
+ "relpath": "dog.txt",
607
+ "size_in_bytes": 3,
608
+ "utc_timestamp": 1716979579.898408
609
+ },
610
+ "d25102a700e072b528db79a0f22b3a5ffe5e8f5d": {
611
+ "hash": "68238cd792d215bdfdddc7bbb6d10db4",
612
+ "relpath": "parrot.txt",
613
+ "size_in_bytes": 6,
614
+ "utc_timestamp": 1716979579.902415
615
+ }
616
+ }
617
+ },
618
+ "creator_username": "olssont",
619
+ "frozen_at": "1537916653.7",
620
+ "created_at": "1537802877.62",
621
+ "annotations": {},
622
+ "tags": [],
623
+ "number_of_items": 2,
624
+ "size_in_bytes": 9
625
+ }'
626
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
627
+ -X PUT -d "$DATASET_INFO" \
628
+ http://localhost:5000/uris/s3/dtool-demo/ba92a5fa-d3b4-4f10-bcb9-947f62e652db
629
+
630
+ The required keys are defined in the variable
631
+ ``dservercore.utils.DATASET_INFO_REQUIRED_KEYS``.
632
+
633
+ Admin user usage
634
+ ^^^^^^^^^^^^^^^^
635
+
636
+ The administrative user can register new users, base URIs and manage who has
637
+ permissions to search for and register datasets. Below we update the header
638
+ to use the token from the ``overlord`` admin user::
639
+
640
+ $ TOKEN=$(flask user token overlord)
641
+ $ HEADER="Authorization: Bearer $TOKEN"
642
+
643
+
644
+ Listing registered users
645
+ ~~~~~~~~~~~~~~~~~~~~~~~~
646
+
647
+ To list all the registered users an admin user can use the below::
648
+
649
+ $ curl -H "$HEADER" http://localhost:5000/users
650
+
651
+ Response content::
652
+
653
+ [
654
+ {
655
+ "is_admin": false,
656
+ "username": "olssont"
657
+ },
658
+ {
659
+ "is_admin": true,
660
+ "username": "overlord"
661
+ }
662
+ ]
663
+
664
+
665
+ Registering users
666
+ ~~~~~~~~~~~~~~~~~
667
+
668
+ An admin user can register other users::
669
+
670
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
671
+ -X PUT -d '{"username": "joe", "is_admin": true}' \
672
+ http://localhost:5000/users/joe
673
+
674
+
675
+
676
+
677
+ Registering a base URI
678
+ ~~~~~~~~~~~~~~~~~~~~~~
679
+
680
+ An admin user can register a new base URI ``s3://another-bucket``::
681
+
682
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
683
+ -X PUT -d '{
684
+ "base_uri": "s3://another-bucket",
685
+ "users_with_search_permissions": ["joe"],
686
+ "users_with_register_permissions": ["olssont"]
687
+ }' http://localhost:5000/base-uris/s3/another-bucket
688
+
689
+
690
+ Listing registered base URIs
691
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
692
+
693
+ An admin user can list all registered base URIs::
694
+
695
+ $ curl -H "$HEADER" http://localhost:5000/base-uris
696
+
697
+ Response content::
698
+
699
+ [
700
+ {
701
+ "base_uri": "s3://dtool-demo",
702
+ },
703
+ {
704
+ "base_uri": "s3://another-bucket",
705
+ }
706
+ ]
707
+
708
+
709
+ Updating the permissions on a base URI
710
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
711
+
712
+ An admin user can update the permissions on a base URI
713
+ simply by another `PUT` request::
714
+
715
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
716
+ -X PUT -d '{
717
+ "base_uri": "s3://another-bucket",
718
+ "users_with_search_permissions": ["joe", "olssont"],
719
+ "users_with_register_permissions": ["olssont"]
720
+ }' http://localhost:5000/base-uris/s3/another-bucket
721
+
722
+ Note that the request below can be used to clear all existing permissions::
723
+
724
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
725
+ -X PUT -d '{
726
+ "base_uri": "s3://another-bucket",
727
+ "users_with_register_permissions": [],
728
+ "users_with_search_permissions": []}' \
729
+ http://localhost:5000/base-uris/s3/another-bucket
730
+
731
+
732
+ Getting information about the permissions on a base URI
733
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
734
+
735
+ An admin user can get information about the permissions on a base URI::
736
+
737
+ $ curl -H "$HEADER" -H "Content-Type: application/json" \
738
+ http://localhost:5000/base-uris/s3/another-bucket
739
+
740
+ Response content::
741
+
742
+ {
743
+ "base_uri": "s3://another-bucket",
744
+ "users_with_register_permissions": [],
745
+ "users_with_search_permissions": []
746
+ }
747
+
748
+ Querying server configuration
749
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
750
+
751
+ The request::
752
+
753
+ $ curl -H "$HEADER" http://localhost:5000/config/info
754
+
755
+ will return the current server configuration with all keys in lowercase, i.e.::
756
+
757
+ {
758
+ "config": {
759
+ "allow_access_from": "0.0.0.0/0",
760
+ "allow_direct_aggregation": true,
761
+ "allow_direct_query": true,
762
+ ...
763
+ }
764
+ }
765
+
766
+ The request::
767
+
768
+ $ curl http://localhost:5000/config/versions
769
+
770
+ will return all components, i.e. server core, search, retrieve
771
+ and extension plugins with their versions, i.e.::
772
+
773
+ {
774
+ "versions": {
775
+ "dservercore": "0.17.2",
776
+ "dserver_retrieve_plugin_mongo": "0.1.0",
777
+ "dserver_search_plugin_mongo": "0.1.0"
778
+ }
779
+ }
780
+
781
+ This request does not require any authorization.
782
+
783
+ Creating a plugin
784
+ -----------------
785
+
786
+ It is possible to create add plugins to this system. This is achieved by
787
+ creating a separate Python package containing a `Flask blueprint
788
+ <https://flask.palletsprojects.com/en/1.1.x/blueprints/>`_.
789
+
790
+ A basic plugin could consist of a single ``__init__`` and a ``setup.py``
791
+ or ``pyproject.toml`` file in the directory structure below::
792
+
793
+ .
794
+ |-- my_plugin
795
+ | `-- __init__.py
796
+ `-- setup.py
797
+
798
+
799
+ The ``__init__.py`` file could contain the code below. Importantly, the
800
+ plugin has to implement a derivative of ``dtoolcore.ExtensionABC``.
801
+
802
+ .. code-block:: python
803
+
804
+ from flask_smorest import Blueprint
805
+ from dtoolcore import ExtensionABC
806
+
807
+ my_plugin_bp = Blueprint('my_plugin', __name__, url_prefix="/my_plugin")
808
+
809
+ @my_plugin_bp.route('/', methods=["GET"])
810
+ @my_plugin_bp.response(200)
811
+ def show(page):
812
+ return "My plugin content"
813
+
814
+ class NotificationExtension(ExtensionABC):
815
+
816
+ def register_dataset(self, dataset_info):
817
+ """Register or update a dataset entry by replacing a possibly existing entry."""
818
+ pass
819
+
820
+ def get_blueprint(self):
821
+ """Return the Flask blueprint to be used for the extension."""
822
+ return my_plugin_bp
823
+
824
+ Classes adhering to the interface of the ``dservercore.ExtensionABC`` abstract base class
825
+ need to be associated with the ``dservercore.extension`` entrypoint in the Python package
826
+ ``setup.py`` file or ``pyproject.toml``. The ``setup.py`` file would need to look something along the
827
+ lines of the below.
828
+
829
+ .. code-block:: python
830
+
831
+ from setuptools import setup
832
+
833
+ setup(
834
+ name="my-plugin",
835
+ packages=["my_plugin"],
836
+ install_requires=[
837
+ "dservercore",
838
+ ],
839
+ entry_points={
840
+ "dservercore.extension": [
841
+ "my_plugin=my_plugin:my_plugin_bp",
842
+ ],
843
+ }
844
+ )
845
+
846
+ A respective entry in a ``pyproject.toml`` would look as follows.
847
+
848
+ .. code-block:: toml
849
+
850
+ [project.entry-points."dservercore.extension"]
851
+ "MyExtension" = "dserver_extension_module:MyExtension"
852
+
853
+ Examples of actual plugins include:
854
+
855
+ - `dserver-direct-mongo-plugin <https://github.com/livMatS/dserver-direct-mongo-plugin>`_
856
+ - `dserver-dependency-graph-plugin <https://github.com/livMatS/dserver-dependency-graph-plugin>`_
857
+ - `dserver-notification-plugin <https://github.com/livMatS/dserver-notification-plugin>`_