forked from DataBiosphere/data-store
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dss-api.yml
3299 lines (3132 loc) · 123 KB
/
dss-api.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
swagger: '2.0'
info:
title: DataBiosphere DSS API
description: >
DataBiosphere Data Storage System API
**HTTP Semantics:**
The DSS API requires clients to follow certain HTTP protocol semantics that may require extra configuration in your
HTTP client. The reference CLI and SDK (https://dbio.readthedocs.io/) is pre-configured to do this. If writing your own
client, please note the following:
**301 redirects**: Some DSS API routes may return one or more HTTP 301 redirects, including potentially redirects to
themselves (combined with the **Retry-After** delay described below). The client must follow these redirects to obtain
the resource requested.
**Retry-After header**: Some DSS API routes may use the **Retry-After** header in combination with HTTP 301 or 500
series response codes. The client must follow the HTTP specification and wait the designated time period before
continuing with the next request.
**General retry logic**: If you are building an application that will issue high numbers of API requests, you should be
prepared for the possibility that a small fraction of requests fails due to network or server errors. In these
situations, the HTTP client should follow best practice HTTP retry semantics. For example, clients may be configured
to retry 5 times while waiting for an exponential number of seconds (1, 2, 4, 8, 16 seconds) upon encountering any 500
series response code, connect or read timeout.
The following Python code demonstrates an example configuration of the popular Requests library per the above guidance:
```
import requests, requests.packages.urllib3.util.retry
class RetryPolicy(requests.packages.urllib3.util.retry.Retry):
def __init__(self, retry_after_status_codes={301}, **kwargs):
super(RetryPolicy, self).__init__(**kwargs)
self.RETRY_AFTER_STATUS_CODES = frozenset(retry_after_status_codes | retry.Retry.RETRY_AFTER_STATUS_CODES)
retry_policy = RetryPolicy(read=5, status=5, status_forcelist=frozenset({500, 502, 503, 504}))
s = requests.Session()
a = requests.adapters.HTTPAdapter(max_retries=retry_policy)
s.mount('https://', a)
print(s.get("https://dss.dev.ucsc-cgp-redwood.org").content)
```
**Subscriptions:**
DSS supports webhook subscriptions for data events like bundle creation and deletion. Webhooks are callbacks to a public
HTTPS endpoint provided by your application. When an event matching your subscription occurs, DSS will send a push
notification (via an HTTPS POST or PUT request), giving your application an up-to-date stream of system activity.
Subscriptions are delivered with the payload format
```
{
'transaction_id': {uuid},
'subscription_id': {uuid},
'event_type': "CREATE"|"TOMBSTONE"|"DELETE", # JMESPath subscriptions only
'match': {
'bundle_uuid': {uuid},
'bundle_version': {version},
}
'jmespath_query': {jmespath_query}, # JMESPath subscriptions only
'es_query': {es_query}, # Elasticsearch subscriptions only
'attachments': {
"attachment_name_1": {value},
"attachment_name_1": {value},
...
"_errors": [...]
}
}
```
**Special String Formats:**
**DSS_VERSION**: a timestamp that generally follows [RFC3339](https://tools.ietf.org/html/rfc3339#section-5.6)
format guide. However there are a few differences. DSS_VERSION must always be in UTC time, ':' are removed from
the time, and the fractional seconds extends to 6 decimal places. Using the first example found [here](https://tools.ietf.org/html/rfc3339#section-5.8),
the RFC3339 version would be `1985-04-12T23:20:50.52Z` while the DSS_VERSION would be `1985-04-12T232050.520000Z`
**Pagination:**
The DSS API supports pagination in a manner consistent with the
[GitHub API](https://developer.github.com/v3/guides/traversing-with-pagination/),
which is based on [RFC 5988](https://tools.ietf.org/html/rfc5988). When the results of an API call exceed the
page size specified, the HTTP response will contain a `Link` header of the following form:
`Link: <https://dss.dev.ucsc-cgp-redwood.org/v1/search?replica=aws&per_page=100&search_after=123>; rel="next"`.
The URL in the header refers to the next page of the results to be fetched; if no `Link rel="next"` URL is
included, then all results have been fetched. The client should recognize and parse the `Link` header
appropriately according to RFC 5988, and retrieve the next page if requested by the user, or if all results
are being retrieved.
version: "0.0.2"
host: {{API_DOMAIN_NAME}}
schemes:
- https
basePath: /v1
produces:
- application/json
securityDefinitions:
OauthSecurity:
description: >
The following claims must be present in the JWT:
- '{{OIDC_GROUP_CLAIM}}': the user group this user belongs.
- 'iss': must be {{OPENID_PROVIDER}} or a trusted google project.
- 'aud': audience must match {{API_DOMAIN_NAME}}.
- '{{OIDC_EMAIL_CLAIM}}': the email of the requester
type: oauth2
flow: implicit
authorizationUrl: {{AUTH_URL}}/authorize
scopes:
email: This scope value requests access to the email and email_verified Claims.
openid: see http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims
offline_access: see http://openid.net/specs/openid-connect-core-1_0.html#OfflineAccessPrivacy
x-audience: {{OIDC_AUDIENCE}}
x-email-claim: {{OIDC_EMAIL_CLAIM}}
x-group-claim: {{OIDC_GROUP_CLAIM}}
x-auth0-claim: {{OIDC_AUTH0_TOKEN_CLAIM}}
paths:
/search:
post:
description: >
Accepts Elasticsearch JSON query and returns matching bundle identifiers
**Index Design:**
The metadata seach index is implemented as a
[document-oriented database](https://en.wikipedia.org/wiki/Document-oriented_database)
using [Elasticsearch](https://www.elastic.co/). The index stores all information relevant to a bundle within
each bundle document, largely eliminating the need for
[object-relational mapping](https://en.wikipedia.org/wiki/Object-relational_mapping). This design is optimized
for queries that filter the data.
To illustrate this concept, say our index stored information on three entities, `foo`, `bar`, and `baz`. A foo
can have many bars and bars can have many bazes. If we were to index bazes in a document-oriented design, the
information on the foo a bar comes from and the bazes it contains are combined into a single document. A
example sketch of this is shown below in [JSON-schema](https://en.wikipedia.org/wiki/JSON#JSON_Schema).
```
{
"definitions": {
"bar": {
"type": "object",
"properties": {
"uuid": {
"type": "string",
"format": "uuid"
},
"foo": {
"type": "object",
"properties": {
"uuid": {
"type": "string",
"format": "uuid"
},
...
}
},
"bazes": {
"type": "array",
"items": {
"type": "string",
"format": "uuid"
}
},
...
}
}
}
}
```
This closely resembles the structure of DSS bundle documents: projects have many bundles and bundles have many
files. Each bundle document is a concatenation of the metadata on the project it belongs to and the files it
contains.
**Limitations to Index Design:**
There are limitations to the design of DSS's metadata search index. A few important ones are listed below.
* [Joins](https://en.wikipedia.org/wiki/Join_(SQL)) between bundle metadata must be conducted client-side
* Querying is schema-specific; fields or values changed between schema version will break queries that use
those fields and values
* A new search index must be built for each schema version
* A lot of metadata is duplicated between documents
summary: >
Find bundles by searching their metadata with an Elasticsearch query
parameters:
- name: json_request_body
in: body
required: true
schema:
type: object
properties:
es_query:
description: Elasticsearch query
type: object
required:
- es_query
- name: output_format
in: query
description: >
Specifies the output format. The default format, `summary`, is a list of UUIDs for bundles that match
the query. Set this parameter to `raw` to get the verbatim JSON metadata for bundles that match the query.
When using `output_format raw` the `per_page` size is limit to no more than 10 to avoid excessively large
response sizes.
required: false
type: string
enum: [summary, raw]
default: summary
- name: replica
in: query
description: Replica to search.
required: true
type: string
enum: [aws, gcp]
- name: per_page
in: query
description: Max number of results to return per page. When using `output_format raw` the `per_page` size is
limit to no more than 10 to avoid excessively large response sizes.
required: false
type: integer
format: int32
minimum: 10
maximum: 500
default: 100
- name: search_after
in: query
description: >
**Search-After-Context**.
An internal state pointer parameter for use with pagination. This parameter is referenced by the `Link`
header as described in the "Pagination" section. The API client should not need to set this parameter
directly; it should instead directly fetch the URL given in the `Link` header.
required: false
type: string
responses:
200:
description: All results retrieved.
schema:
$ref: '#/definitions/SearchResult'
headers:
X-OpenAPI-Pagination:
type: boolean
206:
description: A single page of results was retrieved.
schema:
$ref: '#/definitions/SearchResult'
headers:
Link:
type: string
description: URL to retrieve the next page of results.
X-OpenAPI-Pagination:
type: boolean
X-OpenAPI-Paginated-Content-Key:
type: string
description: The JSON response body key containing an array of results that are paginated.
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
/files/{uuid}:
head:
summary: Retrieve a file's metadata given an UUID and optionally a version.
description: >
Given a file UUID, return the metadata for the latest version of that file. If the version is provided, that
version's metadata is returned instead. The metadata is returned in the headers.
parameters:
- name: uuid
in: path
description: A RFC4122-compliant ID for the file.
required: true
type: string
- name: replica
in: query
description: Replica to fetch from.
required: true
type: string
enum: [aws, gcp]
- name: version
in: query
description: Timestamp of file creation in DSS_VERSION format. If this is not provided, the latest version is returned.
required: false
type: string
responses:
200:
description: Returns metadata
headers:
# edits to here should probably be reflected in the 302 section immediately below.
X-DSS-CREATOR-UID:
description: User ID who created this file.
type: integer
format: int64
X-DSS-VERSION:
description: Timestamp of file creation in DSS_VERSION format.
type: string
X-DSS-CONTENT-TYPE:
description: Content-type of the file.
type: string
X-DSS-SIZE:
description: File size (bytes).
type: integer
format: int64
X-DSS-CRC32C:
description: CRC-32C (in hex format) of the file contents in hex.
type: string
pattern: "^[a-z0-9]{8}$"
X-DSS-S3-ETAG:
description: S3 ETag (in hex format) of the file contents.
type: string
pattern: "^[a-z0-9]{32}(-([2-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|10000))?$"
X-DSS-SHA1:
description: SHA-1 (in hex format) of the file contents in hex.
type: string
pattern: "^[a-z0-9]{40}$"
X-DSS-SHA256:
description: SHA-256 (in hex format) of the file contents in hex.
type: string
pattern: "^[a-z0-9]{64}$"
500:
$ref: '#/responses/ServerError'
502:
$ref: '#/responses/BadGateway'
503:
$ref: '#/responses/ServiceUnavailable'
504:
$ref: '#/responses/GatewayTimeout'
get:
summary: Retrieve a file given a UUID and optionally a version.
description: >
Given a file UUID, return the latest version of that file. If the version is provided, that version of the file
is returned instead.
Headers will contain the data store metadata for the file.
This endpoint returns a HTTP redirect to another HTTP endpoint with the file contents.
NOTE When using the DataBiosphere DSS CLI, this will stream the file to stdout and may need to be piped. For example,
`dbio dss get-file --uuid UUID --replica aws > result.txt`
parameters:
- name: uuid
in: path
description: A RFC4122-compliant ID for the file.
required: true
type: string
pattern: "[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"
- name: replica
in: query
description: Replica to fetch from.
required: true
type: string
enum: [aws, gcp]
- name: version
in: query
description: Timestamp of file creation in DSS_VERSION format. If this is not provided, the latest version is returned.
required: false
type: string
- name: token
in: query
description: Token to manage retries. End users constructing queries should not set this parameter.
required: false
type: string
- name: directurl
in: query
required: false
description: |
When set to true, the response will contain API-specific URLs that are tied to the specified replica, for
example `gs://bucket/object` or `s3://bucket/object`
The use of presigned URLs is recommended for data access. Cloud native URLs are currently provided for a
limited set of use cases and may not be provided in the future. If cloud native URLs are required, please
contact the data store team regarding the credentials necessary to use them.
type: boolean
- name: content_disposition
in: query
description: |
Optional and does not work when directurl=true (only works with the default presigned url response).
If this parameter is provided, the response from fetching the returned presigned url will include the
specified Content-Disposition header.
This can be useful to indicate to a browser that a file should be downloaded rather than opened in a new
tab, and can also supply the original filename in the response. Example:
content_disposition="attachment; filename=data.json"
required: false
type: string
responses:
301:
description: >
The file is still being fetched. The request is being handled asynchronously. The client should follow the
redirect after the delay specified in the Retry-After header.
headers:
Retry-After:
description: Delay in seconds. The client should follow the redirect after waiting for this duration.
type: integer
format: int64
302:
description: Redirects to a signed URL with the data.
headers:
# edits to here should probably be reflected in the 200 section above.
X-DSS-CREATOR-UID:
description: User ID who created this file.
type: integer
format: int64
X-DSS-VERSION:
description: Timestamp of file creation in DSS_VERSION format.
type: string
format: DSS_VERSION
X-DSS-CONTENT-TYPE:
description: Content-type of the file.
type: string
X-DSS-SIZE:
description: File size (bytes).
type: integer
format: int64
X-DSS-CRC32C:
description: CRC-32C (in hex format) of the file contents in hex.
type: string
pattern: "^[a-z0-9]{8}$"
X-DSS-S3-ETAG:
description: S3 ETag (in hex format) of the file contents.
type: string
pattern: "^[a-z0-9]{32}(-([2-9]|[1-8][0-9]|9[0-9]|[1-8][0-9]{2}|9[0-8][0-9]|99[0-9]|[1-8][0-9]{3}|9[0-8][0-9]{2}|99[0-8][0-9]|999[0-9]|10000))?$"
X-DSS-SHA1:
description: SHA-1 (in hex format) of the file contents in hex.
type: string
pattern: "^[a-z0-9]{40}$"
X-DSS-SHA256:
description: SHA-256 (in hex format) of the file contents in hex.
type: string
pattern: "^[a-z0-9]{64}$"
400:
description: Bad request
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: >
Machine-readable error code. The types of return values should not be changed lightly.
The code `illegal_token` is returned when the token parameter cannot be understood.
enum: [illegal_token]
required:
- code
500:
$ref: '#/responses/ServerError'
502:
$ref: '#/responses/BadGateway'
503:
$ref: '#/responses/ServiceUnavailable'
504:
$ref: '#/responses/GatewayTimeout'
default:
description: Unexpected error
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
enum: [unhandled_exception, illegal_arguments, not_found]
required:
- code
put:
security:
- OauthSecurity: []
summary: Create a new version of a file
description: >
Create a new version of a file with a given UUID. The contents of the file are provided by the client by
reference using a cloud object storage URL. The file on the cloud object storage service must have metadata set
listing the file checksums and content-type.
The metadata fields required are:
- dss-sha256: SHA-256 checksum of the file
- dss-sha1: SHA-1 checksum of the file
- dss-s3_etag: S3 ETAG checksum of the file. See https://stackoverflow.com/q/12186993 for the
general algorithm for how checksum is calculated. For files smaller than 64MB, this is the MD5 checksum
of the file. For files larger than 64MB but smaller than 640,000MB, we use 64MB chunks. For files larger than
640,000MB, we use a chunk size equal to the total file size divided by 10000, rounded up to the nearest MB.
MB, in this section, refers to 1,048,576 bytes. Note that 640,000MB is not the same as 640GB!
- dss-crc32c: CRC-32C checksum of the file
parameters:
- name: uuid
in: path
description: A RFC4122-compliant ID for the file.
required: true
type: string
pattern: "[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"
- name: version
in: query
description: Timestamp of file creation in DSS_VERSION format. If this is not provided, the latest version is returned.
required: true
type: string
format: DSS_VERSION
- name: json_request_body
in: body
required: true
schema:
type: object
properties:
source_url:
description: Cloud bucket URL for source data. Example is "s3://bucket_name/serious_dna.fa" .
type: string
pattern: "^(gs|s3|wasb)://"
creator_uid:
description: User ID who is creating this file.
type: integer
format: int64
required:
- source_url
- creator_uid
responses:
200:
description: Returned when the file is already present and is identical to the file being uploaded.
schema:
type: object
properties:
version:
description: Timestamp of file creation in DSS_VERSION format.
type: string
format: DSS_VERSION
required:
- version
201:
description: Returned when the file is successfully copied.
schema:
type: object
properties:
version:
description: Timestamp of file creation in DSS_VERSION format.
type: string
format: DSS_VERSION
required:
- version
202:
description: Returned when the file has been queued up for copying.
schema:
type: object
properties:
version:
description: Timestamp of file creation in DSS_VERSION format.
type: string
format: DSS_VERSION
task_id:
description: ID for the task responsible for managing the copy.
type: string
pattern: "[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"
required:
- version
400:
description: Returned when the server could not process the request. Examine the code for more details.
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: >
Machine-readable error code. The types of return values should not be changed lightly.
The code `unknown_source_schema` is returned when the source_url of the file has an unsupported
schema.
The code `illegal_version` is returned when version is not a DSS_VERSION format-compliant timestamp.
enum: [unknown_source_schema, illegal_version]
required:
- code
409:
description: Returned when a file with the same UUID and version already exists
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
enum: [file_already_exists]
required:
- code
422:
description: Returned when a request cannot be processed due to invalid values in a supplied entity.
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
The code `missing_checksum` is returned when the file uploaded is missing a required checksum.
The code `invalid_checksum` is returned when a checksum is provided but badly-formed.
enum: [missing_checksum, invalid_checksum]
required:
- code
500:
$ref: '#/responses/ServerError'
502:
$ref: '#/responses/BadGateway'
503:
$ref: '#/responses/ServiceUnavailable'
504:
$ref: '#/responses/GatewayTimeout'
default:
description: Unexpected error
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
enum: [unhandled_exception, Forbidden, Unauthorized, illegal_arguments, read_only]
required:
- code
/subscriptions:
get:
security:
- OauthSecurity: []
summary: Retrieve a user\'s event subscriptions.
description: |
Return a list of associated subscriptions.
operationId: dss.api.subscriptions.find
parameters:
- name: replica
in: query
description: Replica to fetch from.
required: true
type: string
enum: [aws, gcp]
- name: subscription_type
in: query
description: Type of subscriptions to fetch (elasticsearch or jmespath).
required: false
default: jmespath
type: string
enum: [elasticsearch, jmespath]
responses:
200:
description: OK
schema:
type: object
properties:
subscriptions:
type: array
items:
$ref: "#/definitions/Subscription"
required:
- subscriptions
500:
$ref: '#/responses/ServerError'
502:
$ref: '#/responses/BadGateway'
503:
$ref: '#/responses/ServiceUnavailable'
504:
$ref: '#/responses/GatewayTimeout'
default:
description: Unexpected error
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
enum: [unhandled_exception, Forbidden, Unauthorized, OAuthResponseProblem]
required:
- code
put:
security:
- OauthSecurity: []
summary: Create an event subscription.
description: >
Register an HTTP endpoint that is to be notified when a given event occurs.
Each user is allowed 100 subscriptions, a limit that may be increased in the future. Concerns about
notification service limitations should be routed to the DSS development team.
parameters:
- name: replica
in: query
description: Replica to write to.
required: true
type: string
enum: [aws, gcp]
- name: json_request_body
in: body
required: true
schema:
type: object
properties:
es_query:
description: >
An Elasticsearch query for restricting the set of bundles for which the subscriber is notified. The
subscriber will only be notified for newly indexed bundles that match the given query. If this
parameter is present the subscription will be of type `elasticsearch`, otherwise it will be of
type `jmespath`.
type: object
jmespath_query:
description: >
An JMESPath query for restricting the set of bundles for which the subscriber is notified. The
subscriber will only be notified for new bundles that match the given query. If `es_query` is
specified, the subscription will be of type `elasticsearch`. If `es_query` is not present, the
subscription will be of type `jmespath`
type: string
callback_url:
description: >
The subscriber's URL. An HTTP request is made to the specified URL for every attempt to deliver
a notification to the subscriber. If the HTTP response code is 2XX, the delivery attempt is
considered successful. Otherwise, more attempts will be made with an exponentially increasing delay
between attempts, until an attempt is successful or the a maximum number of attempts is reached.
Occasionally, duplicate notifications may be sent. It is up to the receiver of the notification to
tolerate duplicate notifications.
type: string
pattern: 'https?://'
method:
description: The HTTP request method to use when delivering a notification to the subscriber.
enum: [POST, PUT]
default: POST
encoding:
description: >
The MIME type describing the encoding of the request body
* `application/json` - the HTTP request body is the notification payload as JSON
* `multipart/form-data` - the HTTP request body is a list of form fields, each consisting of a name
and a corresponding value. See https://tools.ietf.org/html/rfc7578 for details on this encoding.
The actual notification payload will be placed as JSON into a field of the name specified via
`payload_form_field`.
enum:
- application/json
- multipart/form-data
default: application/json
form_fields:
description: >
A collection of static form fields to be supplied in the request body, alongside the actual
notification payload. The value of each field must be a string. For example, if the subscriptions has
this property set to `{"foo" : "bar"}`, the corresponding notification HTTP request body will consist
of a multipart frame with two frames,
```
----------------2769baffc4f24cbc83ced26aa0c2f712
Content-Disposition: form-data; name="foo"
bar
----------------2769baffc4f24cbc83ced26aa0c2f712
Content-Disposition: form-data; name="payload"
{"transaction_id": "301c9079-3b20-4311-a131-bcda9b7f08ba", "subscription_id": ...
```
Since the type of this property is `object`, multi-valued fields are not supported. This property is
ignored unless `encoding` is `multipart/form-data`.
type: object
default: {}
additionalProperties:
type: string
payload_form_field:
description: >
The name of the form field that will hold the notification payload when the request is made. If the
default name of the payload field collides with that of a field in `form_fields`, this porperty can be
used to rename the payload and avoid the collision. This property is ignored unless `encoding` is
`multipart/form-data`.
type: string
default: payload
hmac_secret_key:
description: >
The key for signing requests to the subscriber's URL. The signature will be constructed according to
https://tools.ietf.org/html/draft-cavage-http-signatures and transmitted in the HTTP `Authorization`
header.
type: string
hmac_key_id:
description: >
An optional key ID to use with `hmac_secret_key`.
type: string
attachments:
description: >
The set of bundle metadata items to be included in the payload of a notification request to a
subscription endpoint. Each property in this object represents an attachment to the notification
payload. Each attachment will be a child property of the `attachments` property of the payload. The
name of such a child property can be chosen freely provided it does not start with an underscore.
For example, if the subscription is
```
{
"attachments": {
"taxon": {
"type": "jmespath",
"expression": "files.biomaterial_json.biomaterials[].content.biomaterial_core.ncbi_taxon_id[]"
}
}
}
```
the corresponding notification payload will contain the following entry
```
"attachments": {
"taxon": [9606, 9606]
}
```
If a general error occurs during the processing of attachments, the notification will be sent with
`attachments` containing only the reserved `_errors` attachment containing a string describing the
error. If an error occurs during the processing of a specific attachment, the notification will be
sent with all successfully processed attachments and additionally the `_errors` attachment containing
an object with one property for each failed attachment. For example,
```
"attachments": {
"taxon": [9606, 9606]
"_errors" {
"biomaterial": "Some error occurred"
}
}
```
The value of the `attachments` property must be less than or equal to 128 KiB in size when serialized
to JSON and encoded as UTF-8. If it is not, the notification will be sent with
"attachments": {
"_errors": "Attachments too large (131073 bytes)"
}
type: object
additionalProperties:
type: object
properties:
type:
description: The type of the attachment. Currently only the `jmespath` type is supported.
enum: [jmespath]
expression:
description: >
The JMESPath expression to evaluate against the bundle metadata JSON document. That document is
of the same structure as those returned by `POST /search` with `output_format: raw`.
type: string
required:
- type
- expression
required:
- callback_url
additionalProperties: false
responses:
201:
description: OK
schema:
type: object
properties:
uuid:
description: A RFC4122-compliant ID for the subscription.
type: string
pattern: "[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"
required:
- uuid
500:
$ref: '#/responses/ServerError'
502:
$ref: '#/responses/BadGateway'
503:
$ref: '#/responses/ServiceUnavailable'
504:
$ref: '#/responses/GatewayTimeout'
default:
description: Unexpected error
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
enum:
- unhandled_exception
- Forbidden
- Unauthorized
- OAuthResponseProblem
- elasticsearch_error
- invalid_attachment_expression
- invalid_attachment_name
- invalid_query_type
- invalid_jmespath
- unprocessable
- read_only
- not_acceptable
required:
- code
/subscriptions/{uuid}:
get:
security:
- OauthSecurity: []
summary: Retrieve an event subscription given a UUID.
description: >
Given a subscription UUID, return the associated subscription.
parameters:
- name: uuid
in: path
description: A RFC4122-compliant ID for the subscription.
required: true
type: string
pattern: "[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"
- name: replica
in: query
description: Replica to fetch from.
required: true
type: string
enum: [aws, gcp]
- name: subscription_type
in: query
description: type of subscriptions to fetch (elasticsearch or jmespath)
required: false
default: jmespath
type: string
enum: [elasticsearch, jmespath]
responses:
200:
description: OK
schema:
type: object
properties:
subscription:
$ref: "#/definitions/Subscription"
500:
$ref: '#/responses/ServerError'
502:
$ref: '#/responses/BadGateway'
503:
$ref: '#/responses/ServiceUnavailable'
504:
$ref: '#/responses/GatewayTimeout'
default:
description: Unexpected error
schema:
allOf:
- $ref: '#/definitions/Error'
- type: object
properties:
code:
type: string
description: Machine-readable error code. The types of return values should not be changed lightly.
enum: [unhandled_exception, Forbidden, Unauthorized, OAuthResponseProblem, not_found]
required:
- code
delete:
security:
- OauthSecurity: []
summary: Delete an event subscription.
description: >
Delete a registered event subscription. The associated query will no longer trigger a callback
if a matching document is added to the system.
parameters:
- name: uuid
in: path
description: A RFC4122-compliant ID for the subscription.
required: true
type: string
pattern: "[A-Za-z0-9]{8}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{4}-[A-Za-z0-9]{12}"
- name: replica