forked from stevvooe/distribution
-
Notifications
You must be signed in to change notification settings - Fork 0
/
descriptors.go
1459 lines (1393 loc) · 47.4 KB
/
descriptors.go
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
package v2
import (
"net/http"
"regexp"
"github.com/docker/distribution/digest"
)
var (
nameParameterDescriptor = ParameterDescriptor{
Name: "name",
Type: "string",
Format: RepositoryNameRegexp.String(),
Required: true,
Description: `Name of the target repository.`,
}
tagParameterDescriptor = ParameterDescriptor{
Name: "tag",
Type: "string",
Format: TagNameRegexp.String(),
Required: true,
Description: `Tag of the target manifiest.`,
}
uuidParameterDescriptor = ParameterDescriptor{
Name: "uuid",
Type: "opaque",
Required: true,
Description: `A uuid identifying the upload. This field can accept almost anything.`,
}
digestPathParameter = ParameterDescriptor{
Name: "digest",
Type: "path",
Required: true,
Format: digest.DigestRegexp.String(),
Description: `Digest of desired blob.`,
}
hostHeader = ParameterDescriptor{
Name: "Host",
Type: "string",
Description: "Standard HTTP Host Header. Should be set to the registry host.",
Format: "<registry host>",
Examples: []string{"registry-1.docker.io"},
}
authHeader = ParameterDescriptor{
Name: "Authorization",
Type: "string",
Description: "An RFC7235 compliant authorization header.",
Format: "<scheme> <token>",
Examples: []string{"Bearer dGhpcyBpcyBhIGZha2UgYmVhcmVyIHRva2VuIQ=="},
}
authChallengeHeader = ParameterDescriptor{
Name: "WWW-Authenticate",
Type: "string",
Description: "An RFC7235 compliant authentication challenge header.",
Format: `<scheme> realm="<realm>", ..."`,
Examples: []string{
`Bearer realm="https://auth.docker.com/", service="registry.docker.com", scopes="repository:library/ubuntu:pull"`,
},
}
contentLengthZeroHeader = ParameterDescriptor{
Name: "Content-Length",
Description: "The `Content-Length` header must be zero and the body must be empty.",
Type: "integer",
Format: "0",
}
dockerUploadUUIDHeader = ParameterDescriptor{
Name: "Docker-Upload-UUID",
Description: "Identifies the docker upload uuid for the current request.",
Type: "uuid",
Format: "<uuid>",
}
digestHeader = ParameterDescriptor{
Name: "Docker-Content-Digest",
Description: "Digest of the targeted content for the request.",
Type: "digest",
Format: "<digest>",
}
unauthorizedResponse = ResponseDescriptor{
Description: "The client does not have access to the repository.",
StatusCode: http.StatusUnauthorized,
Headers: []ParameterDescriptor{
authChallengeHeader,
{
Name: "Content-Length",
Type: "integer",
Description: "Length of the JSON error response body.",
Format: "<length>",
},
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: unauthorizedErrorsBody,
},
}
unauthorizedResponsePush = ResponseDescriptor{
Description: "The client does not have access to push to the repository.",
StatusCode: http.StatusUnauthorized,
Headers: []ParameterDescriptor{
authChallengeHeader,
{
Name: "Content-Length",
Type: "integer",
Description: "Length of the JSON error response body.",
Format: "<length>",
},
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: unauthorizedErrorsBody,
},
}
)
const (
manifestBody = `{
"name": <name>,
"tag": <tag>,
"fsLayers": [
{
"blobSum": <tarsum>
},
...
]
],
"history": <v1 images>,
"signature": <JWS>
}`
errorsBody = `{
"errors:" [
{
"code": <error code>,
"message": "<error message>",
"detail": ...
},
...
]
}`
unauthorizedErrorsBody = `{
"errors:" [
{
"code": "UNAUTHORIZED",
"message": "access to the requested resource is not authorized",
"detail": ...
},
...
]
}`
)
// APIDescriptor exports descriptions of the layout of the v2 registry API.
var APIDescriptor = struct {
// RouteDescriptors provides a list of the routes available in the API.
RouteDescriptors []RouteDescriptor
// ErrorDescriptors provides a list of the error codes and their
// associated documentation and metadata.
ErrorDescriptors []ErrorDescriptor
}{
RouteDescriptors: routeDescriptors,
ErrorDescriptors: errorDescriptors,
}
// RouteDescriptor describes a route specified by name.
type RouteDescriptor struct {
// Name is the name of the route, as specified in RouteNameXXX exports.
// These names a should be considered a unique reference for a route. If
// the route is registered with gorilla, this is the name that will be
// used.
Name string
// Path is a gorilla/mux-compatible regexp that can be used to match the
// route. For any incoming method and path, only one route descriptor
// should match.
Path string
// Entity should be a short, human-readalbe description of the object
// targeted by the endpoint.
Entity string
// Description should provide an accurate overview of the functionality
// provided by the route.
Description string
// Methods should describe the various HTTP methods that may be used on
// this route, including request and response formats.
Methods []MethodDescriptor
}
// MethodDescriptor provides a description of the requests that may be
// conducted with the target method.
type MethodDescriptor struct {
// Method is an HTTP method, such as GET, PUT or POST.
Method string
// Description should provide an overview of the functionality provided by
// the covered method, suitable for use in documentation. Use of markdown
// here is encouraged.
Description string
// Requests is a slice of request descriptors enumerating how this
// endpoint may be used.
Requests []RequestDescriptor
}
// RequestDescriptor covers a particular set of headers and parameters that
// can be carried out with the parent method. Its most helpful to have one
// RequestDescriptor per API use case.
type RequestDescriptor struct {
// Name provides a short identifier for the request, usable as a title or
// to provide quick context for the particalar request.
Name string
// Description should cover the requests purpose, covering any details for
// this particular use case.
Description string
// Headers describes headers that must be used with the HTTP request.
Headers []ParameterDescriptor
// PathParameters enumerate the parameterized path components for the
// given request, as defined in the route's regular expression.
PathParameters []ParameterDescriptor
// QueryParameters provides a list of query parameters for the given
// request.
QueryParameters []ParameterDescriptor
// Body describes the format of the request body.
Body BodyDescriptor
// Successes enumerates the possible responses that are considered to be
// the result of a successful request.
Successes []ResponseDescriptor
// Failures covers the possible failures from this particular request.
Failures []ResponseDescriptor
}
// ResponseDescriptor describes the components of an API response.
type ResponseDescriptor struct {
// Name provides a short identifier for the response, usable as a title or
// to provide quick context for the particalar response.
Name string
// Description should provide a brief overview of the role of the
// response.
Description string
// StatusCode specifies the status recieved by this particular response.
StatusCode int
// Headers covers any headers that may be returned from the response.
Headers []ParameterDescriptor
// ErrorCodes enumerates the error codes that may be returned along with
// the response.
ErrorCodes []ErrorCode
// Body describes the body of the response, if any.
Body BodyDescriptor
}
// BodyDescriptor describes a request body and its expected content type. For
// the most part, it should be example json or some placeholder for body
// data in documentation.
type BodyDescriptor struct {
ContentType string
Format string
}
// ParameterDescriptor describes the format of a request parameter, which may
// be a header, path parameter or query parameter.
type ParameterDescriptor struct {
// Name is the name of the parameter, either of the path component or
// query parameter.
Name string
// Type specifies the type of the parameter, such as string, integer, etc.
Type string
// Description provides a human-readable description of the parameter.
Description string
// Required means the field is required when set.
Required bool
// Format is a specifying the string format accepted by this parameter.
Format string
// Regexp is a compiled regular expression that can be used to validate
// the contents of the parameter.
Regexp *regexp.Regexp
// Examples provides multiple examples for the values that might be valid
// for this parameter.
Examples []string
}
// ErrorDescriptor provides relevant information about a given error code.
type ErrorDescriptor struct {
// Code is the error code that this descriptor describes.
Code ErrorCode
// Value provides a unique, string key, often captilized with
// underscores, to identify the error code. This value is used as the
// keyed value when serializing api errors.
Value string
// Message is a short, human readable decription of the error condition
// included in API responses.
Message string
// Description provides a complete account of the errors purpose, suitable
// for use in documentation.
Description string
// HTTPStatusCodes provides a list of status under which this error
// condition may arise. If it is empty, the error condition may be seen
// for any status code.
HTTPStatusCodes []int
}
var routeDescriptors = []RouteDescriptor{
{
Name: RouteNameBase,
Path: "/v2/",
Entity: "Base",
Description: `Base V2 API route. Typically, this can be used for lightweight version checks and to validate registry authorization.`,
Methods: []MethodDescriptor{
{
Method: "GET",
Description: "Check that the endpoint implements Docker Registry API V2.",
Requests: []RequestDescriptor{
{
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
},
Successes: []ResponseDescriptor{
{
Description: "The API implements V2 protocol and is accessible.",
StatusCode: http.StatusOK,
},
},
Failures: []ResponseDescriptor{
{
Description: "The client is not authorized to access the registry.",
StatusCode: http.StatusUnauthorized,
Headers: []ParameterDescriptor{
authChallengeHeader,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
},
{
Description: "The registry does not implement the V2 API.",
StatusCode: http.StatusNotFound,
},
},
},
},
},
},
},
{
Name: RouteNameTags,
Path: "/v2/{name:" + RepositoryNameRegexp.String() + "}/tags/list",
Entity: "Tags",
Description: "Retrieve information about tags.",
Methods: []MethodDescriptor{
{
Method: "GET",
Description: "Fetch the tags under the repository identified by `name`.",
Requests: []RequestDescriptor{
{
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
},
Successes: []ResponseDescriptor{
{
StatusCode: http.StatusOK,
Description: "A list of tags for the named repository.",
Headers: []ParameterDescriptor{
{
Name: "Content-Length",
Type: "integer",
Description: "Length of the JSON response body.",
Format: "<length>",
},
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: `{
"name": <name>,
"tags": [
<tag>,
...
]
}`,
},
},
},
Failures: []ResponseDescriptor{
{
StatusCode: http.StatusNotFound,
Description: "The repository is not known to the registry.",
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeNameUnknown,
},
},
{
StatusCode: http.StatusUnauthorized,
Description: "The client does not have access to the repository.",
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
},
},
},
},
},
},
},
{
Name: RouteNameManifest,
Path: "/v2/{name:" + RepositoryNameRegexp.String() + "}/manifests/{reference:" + TagNameRegexp.String() + "|" + digest.DigestRegexp.String() + "}",
Entity: "Manifest",
Description: "Create, update and retrieve manifests.",
Methods: []MethodDescriptor{
{
Method: "GET",
Description: "Fetch the manifest identified by `name` and `reference` where `reference` can be a tag or digest.",
Requests: []RequestDescriptor{
{
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
tagParameterDescriptor,
},
Successes: []ResponseDescriptor{
{
Description: "The manifest idenfied by `name` and `reference`. The contents can be used to identify and resolve resources required to run the specified image.",
StatusCode: http.StatusOK,
Headers: []ParameterDescriptor{
digestHeader,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: manifestBody,
},
},
},
Failures: []ResponseDescriptor{
{
Description: "The name or reference was invalid.",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeNameInvalid,
ErrorCodeTagInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
{
StatusCode: http.StatusUnauthorized,
Description: "The client does not have access to the repository.",
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
},
{
Description: "The named manifest is not known to the registry.",
StatusCode: http.StatusNotFound,
ErrorCodes: []ErrorCode{
ErrorCodeNameUnknown,
ErrorCodeManifestUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
},
},
},
},
{
Method: "PUT",
Description: "Put the manifest identified by `name` and `reference` where `reference` can be a tag or digest.",
Requests: []RequestDescriptor{
{
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
tagParameterDescriptor,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: manifestBody,
},
Successes: []ResponseDescriptor{
{
Description: "The manifest has been accepted by the registry and is stored under the specified `name` and `tag`.",
StatusCode: http.StatusAccepted,
Headers: []ParameterDescriptor{
{
Name: "Location",
Type: "url",
Description: "The canonical location url of the uploaded manifest.",
Format: "<url>",
},
contentLengthZeroHeader,
digestHeader,
},
},
},
Failures: []ResponseDescriptor{
{
Name: "Invalid Manifest",
Description: "The received manifest was invalid in some way, as described by the error codes. The client should resolve the issue and retry the request.",
StatusCode: http.StatusBadRequest,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeNameInvalid,
ErrorCodeTagInvalid,
ErrorCodeManifestInvalid,
ErrorCodeManifestUnverified,
ErrorCodeBlobUnknown,
},
},
{
StatusCode: http.StatusUnauthorized,
Description: "The client does not have permission to push to the repository.",
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
},
{
Name: "Missing Layer(s)",
Description: "One or more layers may be missing during a manifest upload. If so, the missing layers will be enumerated in the error response.",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeBlobUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: `{
"errors:" [{
"code": "BLOB_UNKNOWN",
"message": "blob unknown to registry",
"detail": {
"digest": <tarsum>
}
},
...
]
}`,
},
},
{
StatusCode: http.StatusUnauthorized,
Headers: []ParameterDescriptor{
authChallengeHeader,
{
Name: "Content-Length",
Type: "integer",
Description: "Length of the JSON error response body.",
Format: "<length>",
},
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
},
},
},
},
{
Method: "DELETE",
Description: "Delete the manifest identified by `name` and `reference` where `reference` can be a tag or digest.",
Requests: []RequestDescriptor{
{
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
tagParameterDescriptor,
},
Successes: []ResponseDescriptor{
{
StatusCode: http.StatusAccepted,
},
},
Failures: []ResponseDescriptor{
{
Name: "Invalid Name or Tag",
Description: "The specified `name` or `tag` were invalid and the delete was unable to proceed.",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeNameInvalid,
ErrorCodeTagInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
{
StatusCode: http.StatusUnauthorized,
Headers: []ParameterDescriptor{
authChallengeHeader,
{
Name: "Content-Length",
Type: "integer",
Description: "Length of the JSON error response body.",
Format: "<length>",
},
},
ErrorCodes: []ErrorCode{
ErrorCodeUnauthorized,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
{
Name: "Unknown Manifest",
Description: "The specified `name` or `tag` are unknown to the registry and the delete was unable to proceed. Clients can assume the manifest was already deleted if this response is returned.",
StatusCode: http.StatusNotFound,
ErrorCodes: []ErrorCode{
ErrorCodeNameUnknown,
ErrorCodeManifestUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
},
},
},
},
},
},
{
Name: RouteNameBlob,
Path: "/v2/{name:" + RepositoryNameRegexp.String() + "}/blobs/{digest:" + digest.DigestRegexp.String() + "}",
Entity: "Blob",
Description: "Fetch the blob identified by `name` and `digest`. Used to fetch layers by tarsum digest.",
Methods: []MethodDescriptor{
{
Method: "GET",
Description: "Retrieve the blob from the registry identified by `digest`. A `HEAD` request can also be issued to this endpoint to obtain resource information without receiving all data.",
Requests: []RequestDescriptor{
{
Name: "Fetch Blob",
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
digestPathParameter,
},
Successes: []ResponseDescriptor{
{
Description: "The blob identified by `digest` is available. The blob content will be present in the body of the request.",
StatusCode: http.StatusOK,
Headers: []ParameterDescriptor{
{
Name: "Content-Length",
Type: "integer",
Description: "The length of the requested blob content.",
Format: "<length>",
},
digestHeader,
},
Body: BodyDescriptor{
ContentType: "application/octet-stream",
Format: "<blob binary data>",
},
},
{
Description: "The blob identified by `digest` is available at the provided location.",
StatusCode: http.StatusTemporaryRedirect,
Headers: []ParameterDescriptor{
{
Name: "Location",
Type: "url",
Description: "The location where the layer should be accessible.",
Format: "<blob location>",
},
digestHeader,
},
},
},
Failures: []ResponseDescriptor{
{
Description: "There was a problem with the request that needs to be addressed by the client, such as an invalid `name` or `tag`.",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeNameInvalid,
ErrorCodeDigestInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
unauthorizedResponse,
{
Description: "The blob, identified by `name` and `digest`, is unknown to the registry.",
StatusCode: http.StatusNotFound,
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
ErrorCodes: []ErrorCode{
ErrorCodeNameUnknown,
ErrorCodeBlobUnknown,
},
},
},
},
{
Name: "Fetch Blob Part",
Description: "This endpoint may also support RFC7233 compliant range requests. Support can be detected by issuing a HEAD request. If the header `Accept-Range: bytes` is returned, range requests can be used to fetch partial content.",
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
{
Name: "Range",
Type: "string",
Description: "HTTP Range header specifying blob chunk.",
Format: "bytes=<start>-<end>",
},
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
digestPathParameter,
},
Successes: []ResponseDescriptor{
{
Description: "The blob identified by `digest` is available. The specified chunk of blob content will be present in the body of the request.",
StatusCode: http.StatusPartialContent,
Headers: []ParameterDescriptor{
{
Name: "Content-Length",
Type: "integer",
Description: "The length of the requested blob chunk.",
Format: "<length>",
},
{
Name: "Content-Range",
Type: "byte range",
Description: "Content range of blob chunk.",
Format: "bytes <start>-<end>/<size>",
},
},
Body: BodyDescriptor{
ContentType: "application/octet-stream",
Format: "<blob binary data>",
},
},
},
Failures: []ResponseDescriptor{
{
Description: "There was a problem with the request that needs to be addressed by the client, such as an invalid `name` or `tag`.",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeNameInvalid,
ErrorCodeDigestInvalid,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
unauthorizedResponse,
{
StatusCode: http.StatusNotFound,
ErrorCodes: []ErrorCode{
ErrorCodeNameUnknown,
ErrorCodeBlobUnknown,
},
Body: BodyDescriptor{
ContentType: "application/json; charset=utf-8",
Format: errorsBody,
},
},
{
Description: "The range specification cannot be satisfied for the requested content. This can happen when the range is not formatted correctly or if the range is outside of the valid size of the content.",
StatusCode: http.StatusRequestedRangeNotSatisfiable,
},
},
},
},
},
// TODO(stevvooe): We may want to add a PUT request here to
// kickoff an upload of a blob, integrated with the blob upload
// API.
},
},
{
Name: RouteNameBlobUpload,
Path: "/v2/{name:" + RepositoryNameRegexp.String() + "}/blobs/uploads/",
Entity: "Intiate Blob Upload",
Description: "Initiate a blob upload. This endpoint can be used to create resumable uploads or monolithic uploads.",
Methods: []MethodDescriptor{
{
Method: "POST",
Description: "Initiate a resumable blob upload. If successful, an upload location will be provided to complete the upload. Optionally, if the `digest` parameter is present, the request body will be used to complete the upload in a single request.",
Requests: []RequestDescriptor{
{
Name: "Initiate Monolithic Blob Upload",
Description: "Upload a blob identified by the `digest` parameter in single request. This upload will not be resumable unless a recoverable error is returned.",
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
{
Name: "Content-Length",
Type: "integer",
Format: "<length of blob>",
},
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
},
QueryParameters: []ParameterDescriptor{
{
Name: "digest",
Type: "query",
Format: "<tarsum>",
Regexp: digest.DigestRegexp,
Description: `Digest of uploaded blob. If present, the upload will be completed, in a single request, with contents of the request body as the resulting blob.`,
},
},
Body: BodyDescriptor{
ContentType: "application/octect-stream",
Format: "<binary data>",
},
Successes: []ResponseDescriptor{
{
Description: "The blob has been created in the registry and is available at the provided location.",
StatusCode: http.StatusCreated,
Headers: []ParameterDescriptor{
{
Name: "Location",
Type: "url",
Format: "<blob location>",
},
contentLengthZeroHeader,
dockerUploadUUIDHeader,
},
},
},
Failures: []ResponseDescriptor{
{
Name: "Invalid Name or Digest",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeDigestInvalid,
ErrorCodeNameInvalid,
},
},
unauthorizedResponsePush,
},
},
{
Name: "Initiate Resumable Blob Upload",
Description: "Initiate a resumable blob upload with an empty request body.",
Headers: []ParameterDescriptor{
hostHeader,
authHeader,
contentLengthZeroHeader,
},
PathParameters: []ParameterDescriptor{
nameParameterDescriptor,
},
Successes: []ResponseDescriptor{
{
Description: "The upload has been created. The `Location` header must be used to complete the upload. The response should be identical to a `GET` request on the contents of the returned `Location` header.",
StatusCode: http.StatusAccepted,
Headers: []ParameterDescriptor{
contentLengthZeroHeader,
{
Name: "Location",
Type: "url",
Format: "/v2/<name>/blobs/uploads/<uuid>",
Description: "The location of the created upload. Clients should use the contents verbatim to complete the upload, adding parameters where required.",
},
{
Name: "Range",
Format: "0-0",
Description: "Range header indicating the progress of the upload. When starting an upload, it will return an empty range, since no content has been received.",
},
dockerUploadUUIDHeader,
},
},
},
Failures: []ResponseDescriptor{
{
Name: "Invalid Name or Digest",
StatusCode: http.StatusBadRequest,
ErrorCodes: []ErrorCode{
ErrorCodeDigestInvalid,
ErrorCodeNameInvalid,
},
},
unauthorizedResponsePush,
},
},
},
},
},
},
{
Name: RouteNameBlobUploadChunk,
Path: "/v2/{name:" + RepositoryNameRegexp.String() + "}/blobs/uploads/{uuid}",
Entity: "Blob Upload",
Description: "Interact with blob uploads. Clients should never assemble URLs for this endpoint and should only take it through the `Location` header on related API requests. The `Location` header and its parameters should be preserved by clients, using the latest value returned via upload related API calls.",
Methods: []MethodDescriptor{
{
Method: "GET",
Description: "Retrieve status of upload identified by `uuid`. The primary purpose of this endpoint is to resolve the current status of a resumable upload.",
Requests: []RequestDescriptor{
{
Description: "Retrieve the progress of the current upload, as reported by the `Range` header.",
Headers: []ParameterDescriptor{
hostHeader,
authHeader,