-
Notifications
You must be signed in to change notification settings - Fork 269
/
GroupsResourceImpl.java
1479 lines (1290 loc) · 70.6 KB
/
GroupsResourceImpl.java
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 io.apicurio.registry.rest.v2;
import com.google.common.hash.Hashing;
import io.apicurio.common.apps.logging.Logged;
import io.apicurio.common.apps.logging.audit.Audited;
import io.apicurio.registry.auth.Authorized;
import io.apicurio.registry.auth.AuthorizedLevel;
import io.apicurio.registry.auth.AuthorizedStyle;
import io.apicurio.registry.content.ContentHandle;
import io.apicurio.registry.content.TypedContent;
import io.apicurio.registry.content.extract.ContentExtractor;
import io.apicurio.registry.content.extract.ExtractedMetaData;
import io.apicurio.registry.content.util.ContentTypeUtil;
import io.apicurio.registry.metrics.health.liveness.ResponseErrorLivenessCheck;
import io.apicurio.registry.metrics.health.readiness.ResponseTimeoutReadinessCheck;
import io.apicurio.registry.model.BranchId;
import io.apicurio.registry.model.GA;
import io.apicurio.registry.model.GAV;
import io.apicurio.registry.model.VersionExpressionParser;
import io.apicurio.registry.rest.HeadersHack;
import io.apicurio.registry.rest.MissingRequiredParameterException;
import io.apicurio.registry.rest.ParametersConflictException;
import io.apicurio.registry.rest.RestConfig;
import io.apicurio.registry.rest.v2.beans.ArtifactContent;
import io.apicurio.registry.rest.v2.beans.ArtifactMetaData;
import io.apicurio.registry.rest.v2.beans.ArtifactOwner;
import io.apicurio.registry.rest.v2.beans.ArtifactReference;
import io.apicurio.registry.rest.v2.beans.ArtifactSearchResults;
import io.apicurio.registry.rest.v2.beans.Comment;
import io.apicurio.registry.rest.v2.beans.CreateGroupMetaData;
import io.apicurio.registry.rest.v2.beans.EditableMetaData;
import io.apicurio.registry.rest.v2.beans.GroupMetaData;
import io.apicurio.registry.rest.v2.beans.GroupSearchResults;
import io.apicurio.registry.rest.v2.beans.IfExists;
import io.apicurio.registry.rest.v2.beans.NewComment;
import io.apicurio.registry.rest.v2.beans.Rule;
import io.apicurio.registry.rest.v2.beans.SortBy;
import io.apicurio.registry.rest.v2.beans.SortOrder;
import io.apicurio.registry.rest.v2.beans.UpdateState;
import io.apicurio.registry.rest.v2.beans.VersionMetaData;
import io.apicurio.registry.rest.v2.beans.VersionSearchResults;
import io.apicurio.registry.rules.RuleApplicationType;
import io.apicurio.registry.rules.RulesService;
import io.apicurio.registry.storage.RegistryStorage;
import io.apicurio.registry.storage.RegistryStorage.RetrievalBehavior;
import io.apicurio.registry.storage.dto.ArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.ArtifactReferenceDto;
import io.apicurio.registry.storage.dto.ArtifactSearchResultsDto;
import io.apicurio.registry.storage.dto.ArtifactVersionMetaDataDto;
import io.apicurio.registry.storage.dto.CommentDto;
import io.apicurio.registry.storage.dto.ContentWrapperDto;
import io.apicurio.registry.storage.dto.EditableArtifactMetaDataDto;
import io.apicurio.registry.storage.dto.EditableVersionMetaDataDto;
import io.apicurio.registry.storage.dto.GroupMetaDataDto;
import io.apicurio.registry.storage.dto.GroupSearchResultsDto;
import io.apicurio.registry.storage.dto.OrderBy;
import io.apicurio.registry.storage.dto.OrderDirection;
import io.apicurio.registry.storage.dto.RuleConfigurationDto;
import io.apicurio.registry.storage.dto.SearchFilter;
import io.apicurio.registry.storage.dto.StoredArtifactVersionDto;
import io.apicurio.registry.storage.dto.VersionSearchResultsDto;
import io.apicurio.registry.storage.error.ArtifactAlreadyExistsException;
import io.apicurio.registry.storage.error.ArtifactNotFoundException;
import io.apicurio.registry.storage.error.InvalidArtifactIdException;
import io.apicurio.registry.storage.error.InvalidGroupIdException;
import io.apicurio.registry.storage.error.VersionNotFoundException;
import io.apicurio.registry.storage.impl.sql.RegistryContentUtils;
import io.apicurio.registry.types.ArtifactState;
import io.apicurio.registry.types.ContentTypes;
import io.apicurio.registry.types.Current;
import io.apicurio.registry.types.ReferenceType;
import io.apicurio.registry.types.RuleType;
import io.apicurio.registry.types.VersionState;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProvider;
import io.apicurio.registry.types.provider.ArtifactTypeUtilProviderFactory;
import io.apicurio.registry.util.ArtifactIdGenerator;
import io.apicurio.registry.util.ArtifactTypeUtil;
import io.apicurio.registry.utils.ArtifactIdValidator;
import io.apicurio.registry.utils.IoUtil;
import io.apicurio.registry.utils.JAXRSClientUtil;
import io.quarkus.security.identity.SecurityIdentity;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.interceptor.Interceptors;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.ws.rs.BadRequestException;
import jakarta.ws.rs.HttpMethod;
import jakarta.ws.rs.NotAllowedException;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import org.apache.commons.lang3.tuple.Pair;
import org.jose4j.base64url.Base64;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.math.BigInteger;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ARTIFACT_ID;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_ARTIFACT_TYPE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_CANONICAL;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_DESCRIPTION;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_DESCRIPTION_ENCODED;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_EDITABLE_METADATA;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_FROM_URL;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_GROUP_ID;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_IF_EXISTS;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_NAME;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_NAME_ENCODED;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_RULE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_RULE_TYPE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_SHA;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_UPDATE_STATE;
import static io.apicurio.common.apps.logging.audit.AuditingConstants.KEY_VERSION;
import static io.apicurio.registry.logging.audit.AuditingConstants.KEY_OWNER;
import static io.apicurio.registry.rest.v2.V2ApiUtil.defaultGroupIdToNull;
/**
* Implements the {@link GroupsResource} JAX-RS interface.
*/
@ApplicationScoped
@Interceptors({ ResponseErrorLivenessCheck.class, ResponseTimeoutReadinessCheck.class })
@Logged
public class GroupsResourceImpl implements GroupsResource {
private static final String EMPTY_CONTENT_ERROR_MESSAGE = "Empty content is not allowed.";
@SuppressWarnings("unused")
private static final Integer GET_GROUPS_LIMIT = 1000;
@Inject
RulesService rulesService;
@Inject
ArtifactIdGenerator idGenerator;
@Inject
RestConfig restConfig;
@Inject
SecurityIdentity securityIdentity;
@Inject
@Current
RegistryStorage storage;
@Inject
ArtifactTypeUtilProviderFactory factory;
@Inject
io.apicurio.registry.rest.v3.GroupsResourceImpl v3;
@Context
HttpServletRequest request;
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getLatestArtifact(java.lang.String, java.lang.String,
* Boolean)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public Response getLatestArtifact(String groupId, String artifactId, Boolean dereference) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
if (dereference == null) {
dereference = Boolean.FALSE;
}
try {
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
RetrievalBehavior.ACTIVE_STATES);
ArtifactVersionMetaDataDto metaData = storage.getArtifactVersionMetaData(
latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(),
latestGAV.getRawVersionId());
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(
defaultGroupIdToNull(groupId), artifactId, latestGAV.getRawVersionId());
TypedContent contentToReturn = TypedContent.create(artifact.getContent(),
artifact.getContentType());
ArtifactTypeUtilProvider artifactTypeProvider = factory
.getArtifactTypeProvider(metaData.getArtifactType());
if (dereference && !artifact.getReferences().isEmpty()) {
if (artifactTypeProvider.supportsReferencesWithContext()) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils
.recursivelyResolveReferencesWithContext(contentToReturn,
metaData.getArtifactType(), artifact.getReferences(),
storage::getContentByReference);
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(
rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer()
.dereference(contentToReturn, RegistryContentUtils.recursivelyResolveReferences(
artifact.getReferences(), storage::getContentByReference));
}
}
Response.ResponseBuilder builder = Response.ok(contentToReturn.getContent(),
contentToReturn.getContentType());
checkIfDeprecated(metaData::getState, groupId, artifactId, metaData.getVersion(), builder);
return builder.build();
} catch (VersionNotFoundException e) {
throw new ArtifactNotFoundException(e.getGroupId(), e.getArtifactId());
}
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifact(String, String, String, String, String,
* String, String, InputStream)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3", KEY_NAME,
"4", KEY_NAME_ENCODED, "5", KEY_DESCRIPTION, "6", KEY_DESCRIPTION_ENCODED })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public ArtifactMetaData updateArtifact(String groupId, String artifactId, String xRegistryVersion,
String xRegistryName, String xRegistryNameEncoded, String xRegistryDescription,
String xRegistryDescriptionEncoded, InputStream data) {
return this.updateArtifactWithRefs(groupId, artifactId, xRegistryVersion, xRegistryName,
xRegistryNameEncoded, xRegistryDescription, xRegistryDescriptionEncoded, data,
Collections.emptyList());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifact(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String,
* io.apicurio.registry.rest.v2.beans.ArtifactContent)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3", KEY_NAME,
"4", KEY_NAME_ENCODED, "5", KEY_DESCRIPTION, "6", KEY_DESCRIPTION_ENCODED })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public ArtifactMetaData updateArtifact(String groupId, String artifactId, String xRegistryVersion,
String xRegistryName, String xRegistryNameEncoded, String xRegistryDescription,
String xRegistryDescriptionEncoded, ArtifactContent data) {
requireParameter("content", data.getContent());
return this.updateArtifactWithRefs(groupId, artifactId, xRegistryVersion, xRegistryName,
xRegistryNameEncoded, xRegistryDescription, xRegistryDescriptionEncoded,
IoUtil.toStream(data.getContent()), data.getReferences());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactVersionReferences(java.lang.String,
* java.lang.String, java.lang.String, io.apicurio.registry.types.ReferenceType)
*/
@Override
public List<ArtifactReference> getArtifactVersionReferences(String groupId, String artifactId,
String version, ReferenceType refType) {
if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}
if (refType == null || refType == ReferenceType.OUTBOUND) {
return storage.getArtifactVersionContent(defaultGroupIdToNull(groupId), artifactId, version)
.getReferences().stream().map(V2ApiUtil::referenceDtoToReference)
.collect(Collectors.toList());
} else {
return storage.getInboundArtifactReferences(defaultGroupIdToNull(groupId), artifactId, version)
.stream().map(V2ApiUtil::referenceDtoToReference).collect(Collectors.toList());
}
}
private ArtifactMetaData updateArtifactWithRefs(String groupId, String artifactId,
String xRegistryVersion, String xRegistryName, String xRegistryNameEncoded,
String xRegistryDescription, String xRegistryDescriptionEncoded, InputStream data,
List<ArtifactReference> references) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
maxOneOf("X-Registry-Name", xRegistryName, "X-Registry-Name-Encoded", xRegistryNameEncoded);
maxOneOf("X-Registry-Description", xRegistryDescription, "X-Registry-Description-Encoded",
xRegistryDescriptionEncoded);
String artifactName = getOneOf(xRegistryName, decode(xRegistryNameEncoded));
String artifactDescription = getOneOf(xRegistryDescription, decode(xRegistryDescriptionEncoded));
ContentHandle content = ContentHandle.create(data);
if (content.bytes().length == 0) {
throw new BadRequestException(EMPTY_CONTENT_ERROR_MESSAGE);
}
return updateArtifactInternal(groupId, artifactId, xRegistryVersion, artifactName,
artifactDescription, content, getContentType(), references);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifact(java.lang.String, java.lang.String)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void deleteArtifact(String groupId, String artifactId) {
if (!restConfig.isArtifactDeletionEnabled()) {
throw new NotAllowedException("Artifact deletion operation is not enabled.", HttpMethod.GET,
(String[]) null);
}
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
storage.deleteArtifact(defaultGroupIdToNull(groupId), artifactId);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactMetaData(java.lang.String,
* java.lang.String)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public ArtifactMetaData getArtifactMetaData(String groupId, String artifactId) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
ArtifactMetaDataDto dto = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
RetrievalBehavior.ACTIVE_STATES);
ArtifactVersionMetaDataDto vdto = storage.getArtifactVersionMetaData(
latestGAV.getRawGroupIdWithNull(), latestGAV.getRawArtifactId(), latestGAV.getRawVersionId());
ArtifactMetaData amd = V2ApiUtil.dtoToMetaData(defaultGroupIdToNull(groupId), artifactId,
dto.getArtifactType(), dto);
amd.setContentId(vdto.getContentId());
amd.setGlobalId(vdto.getGlobalId());
amd.setVersion(vdto.getVersion());
amd.setName(vdto.getName());
amd.setDescription(vdto.getDescription());
amd.setModifiedBy(vdto.getOwner());
amd.setModifiedOn(new Date(vdto.getCreatedOn()));
amd.setLabels(V2ApiUtil.toV2Labels(vdto.getLabels()));
amd.setProperties(V2ApiUtil.toV2Properties(vdto.getLabels()));
amd.setState(ArtifactState.fromValue(vdto.getState().name()));
return amd;
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifactMetaData(java.lang.String,
* java.lang.String, io.apicurio.registry.rest.v2.beans.EditableMetaData)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_EDITABLE_METADATA })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactMetaData(String groupId, String artifactId, EditableMetaData data) {
GAV latestGAV = storage.getBranchTip(new GA(groupId, artifactId), BranchId.LATEST,
RetrievalBehavior.ALL_STATES);
storage.updateArtifactVersionMetaData(groupId, artifactId, latestGAV.getRawVersionId(),
EditableVersionMetaDataDto.builder().name(data.getName()).description(data.getDescription())
.labels(V2ApiUtil.toV3Labels(data.getLabels(), data.getProperties())).build());
}
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public ArtifactOwner getArtifactOwner(String groupId, String artifactId) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
ArtifactMetaDataDto dto = storage.getArtifactMetaData(defaultGroupIdToNull(groupId), artifactId);
ArtifactOwner owner = new ArtifactOwner();
owner.setOwner(dto.getOwner());
return owner;
}
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_OWNER })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.AdminOrOwner)
public void updateArtifactOwner(String groupId, String artifactId, ArtifactOwner data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("data", data);
if (data.getOwner().isEmpty()) {
throw new MissingRequiredParameterException("Missing required owner");
}
EditableArtifactMetaDataDto emd = EditableArtifactMetaDataDto.builder().owner(data.getOwner())
.build();
storage.updateArtifactMetaData(defaultGroupIdToNull(groupId), artifactId, emd);
}
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public GroupMetaData getGroupById(String groupId) {
GroupMetaDataDto group = storage.getGroupMetaData(groupId);
return V2ApiUtil.groupDtoToGroup(group);
}
@Override
@Authorized(style = AuthorizedStyle.GroupOnly, level = AuthorizedLevel.Write)
public void deleteGroupById(String groupId) {
if (!restConfig.isGroupDeletionEnabled()) {
throw new NotAllowedException("Group deletion operation is not enabled.", HttpMethod.GET,
(String[]) null);
}
storage.deleteGroup(groupId);
}
@Override
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Read)
public GroupSearchResults listGroups(BigInteger limit, BigInteger offset, SortOrder order,
SortBy orderby) {
if (orderby == null) {
orderby = SortBy.name;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
}
if (limit == null) {
limit = BigInteger.valueOf(20);
}
final OrderBy oBy = OrderBy.valueOf(orderby.name());
final OrderDirection oDir = order == null || order == SortOrder.asc ? OrderDirection.asc
: OrderDirection.desc;
Set<SearchFilter> filters = Collections.emptySet();
GroupSearchResultsDto resultsDto = storage.searchGroups(filters, oBy, oDir, offset.intValue(),
limit.intValue());
return V2ApiUtil.dtoToSearchResults(resultsDto);
}
@Override
@Authorized(style = AuthorizedStyle.None, level = AuthorizedLevel.Write)
public GroupMetaData createGroup(CreateGroupMetaData data) {
GroupMetaDataDto.GroupMetaDataDtoBuilder group = GroupMetaDataDto.builder().groupId(data.getId())
.description(data.getDescription()).labels(data.getProperties());
String user = securityIdentity.getPrincipal().getName();
group.owner(user).createdOn(new Date().getTime());
storage.createGroup(group.build());
return V2ApiUtil.groupDtoToGroup(storage.getGroupMetaData(data.getId()));
}
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public VersionMetaData getArtifactVersionMetaDataByContent(String groupId, String artifactId,
Boolean canonical, ArtifactContent artifactContent) {
return getArtifactVersionMetaDataByContent(groupId, artifactId, canonical,
IoUtil.toStream(artifactContent.getContent()), artifactContent.getReferences());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactVersionMetaDataByContent(java.lang.String,
* java.lang.String, java.lang.Boolean, java.io.InputStream)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public VersionMetaData getArtifactVersionMetaDataByContent(String groupId, String artifactId,
Boolean canonical, InputStream data) {
return getArtifactVersionMetaDataByContent(groupId, artifactId, canonical, data,
Collections.emptyList());
}
private VersionMetaData getArtifactVersionMetaDataByContent(String groupId, String artifactId,
Boolean canonical, InputStream data, List<ArtifactReference> artifactReferences) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
if (canonical == null) {
canonical = Boolean.FALSE;
}
String contentType = getContentType();
ContentHandle content = ContentHandle.create(data);
if (content.bytes().length == 0) {
throw new BadRequestException(EMPTY_CONTENT_ERROR_MESSAGE);
}
if (ContentTypeUtil.isApplicationYaml(getContentType())) {
content = ContentTypeUtil.yamlToJson(content);
contentType = ContentTypes.APPLICATION_JSON;
}
final List<ArtifactReferenceDto> artifactReferenceDtos = toReferenceDtos(artifactReferences);
TypedContent typedContent = TypedContent.create(content, contentType);
ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaDataByContent(
defaultGroupIdToNull(groupId), artifactId, canonical, typedContent, artifactReferenceDtos);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId,
dto.getArtifactType(), dto);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#listArtifactRules(java.lang.String, java.lang.String)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public List<RuleType> listArtifactRules(String groupId, String artifactId) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
return storage.getArtifactRules(defaultGroupIdToNull(groupId), artifactId);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#createArtifactRule(java.lang.String, java.lang.String,
* io.apicurio.registry.rest.v2.beans.Rule)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_RULE })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void createArtifactRule(String groupId, String artifactId, Rule data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
RuleType type = data.getType();
requireParameter("type", type);
if (data.getConfig() == null || data.getConfig().isEmpty()) {
throw new MissingRequiredParameterException("Config");
}
RuleConfigurationDto config = new RuleConfigurationDto();
config.setConfiguration(data.getConfig());
if (!storage.isArtifactExists(defaultGroupIdToNull(groupId), artifactId)) {
throw new ArtifactNotFoundException(groupId, artifactId);
}
storage.createArtifactRule(defaultGroupIdToNull(groupId), artifactId, data.getType(), config);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifactRules(java.lang.String,
* java.lang.String)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void deleteArtifactRules(String groupId, String artifactId) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
storage.deleteArtifactRules(defaultGroupIdToNull(groupId), artifactId);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactRuleConfig(java.lang.String,
* java.lang.String, io.apicurio.registry.types.RuleType)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public Rule getArtifactRuleConfig(String groupId, String artifactId, RuleType rule) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("rule", rule);
RuleConfigurationDto dto = storage.getArtifactRule(defaultGroupIdToNull(groupId), artifactId, rule);
Rule rval = new Rule();
rval.setConfig(dto.getConfiguration());
rval.setType(rule);
return rval;
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifactRuleConfig(java.lang.String,
* java.lang.String, io.apicurio.registry.types.RuleType, io.apicurio.registry.rest.v2.beans.Rule)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_RULE_TYPE, "3",
KEY_RULE })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public Rule updateArtifactRuleConfig(String groupId, String artifactId, RuleType rule, Rule data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("rule", rule);
RuleConfigurationDto dto = new RuleConfigurationDto(data.getConfig());
storage.updateArtifactRule(defaultGroupIdToNull(groupId), artifactId, rule, dto);
Rule rval = new Rule();
rval.setType(rule);
rval.setConfig(data.getConfig());
return rval;
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifactRule(java.lang.String, java.lang.String,
* io.apicurio.registry.types.RuleType)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_RULE_TYPE })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void deleteArtifactRule(String groupId, String artifactId, RuleType rule) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("rule", rule);
storage.deleteArtifactRule(defaultGroupIdToNull(groupId), artifactId, rule);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifactState(java.lang.String,
* java.lang.String, io.apicurio.registry.rest.v2.beans.UpdateState)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_UPDATE_STATE })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactState(String groupId, String artifactId, UpdateState data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("body.state", data.getState());
// Possible race condition here. Worst case should be that the update fails with a reasonable message.
GAV latestGAV = storage.getBranchTip(new GA(defaultGroupIdToNull(groupId), artifactId),
BranchId.LATEST, RetrievalBehavior.ALL_STATES);
updateArtifactVersionState(groupId, artifactId, latestGAV.getRawVersionId(), data);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#testUpdateArtifact(java.lang.String, java.lang.String,
* java.io.InputStream)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void testUpdateArtifact(String groupId, String artifactId, InputStream data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
ContentHandle content = ContentHandle.create(data);
if (content.bytes().length == 0) {
throw new BadRequestException(EMPTY_CONTENT_ERROR_MESSAGE);
}
String ct = getContentType();
if (ContentTypeUtil.isApplicationYaml(ct)) {
content = ContentTypeUtil.yamlToJson(content);
ct = ContentTypes.APPLICATION_JSON;
}
String artifactType = lookupArtifactType(groupId, artifactId);
TypedContent typedContent = TypedContent.create(content, ct);
rulesService.applyRules(defaultGroupIdToNull(groupId), artifactId, artifactType, typedContent,
RuleApplicationType.UPDATE, Collections.emptyList(), Collections.emptyMap()); // TODO:references
// not supported
// for testing
// update
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactVersion(String, String, String, Boolean)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public Response getArtifactVersion(String groupId, String artifactId, String version,
Boolean dereference) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
if (dereference == null) {
dereference = Boolean.FALSE;
}
if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}
ArtifactVersionMetaDataDto metaData = storage
.getArtifactVersionMetaData(defaultGroupIdToNull(groupId), artifactId, version);
if (VersionState.DISABLED.equals(metaData.getState())) {
throw new VersionNotFoundException(groupId, artifactId, version);
}
StoredArtifactVersionDto artifact = storage.getArtifactVersionContent(defaultGroupIdToNull(groupId),
artifactId, version);
TypedContent contentToReturn = TypedContent.create(artifact.getContent(), artifact.getContentType());
ArtifactTypeUtilProvider artifactTypeProvider = factory
.getArtifactTypeProvider(metaData.getArtifactType());
if (dereference && !artifact.getReferences().isEmpty()) {
if (artifactTypeProvider.supportsReferencesWithContext()) {
RegistryContentUtils.RewrittenContentHolder rewrittenContent = RegistryContentUtils
.recursivelyResolveReferencesWithContext(contentToReturn, metaData.getArtifactType(),
artifact.getReferences(), storage::getContentByReference);
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(
rewrittenContent.getRewrittenContent(), rewrittenContent.getResolvedReferences());
} else {
contentToReturn = artifactTypeProvider.getContentDereferencer().dereference(contentToReturn,
RegistryContentUtils.recursivelyResolveReferences(artifact.getReferences(),
storage::getContentByReference));
}
}
Response.ResponseBuilder builder = Response.ok(contentToReturn.getContent(),
contentToReturn.getContentType());
checkIfDeprecated(metaData::getState, groupId, artifactId, version, builder);
return builder.build();
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifactVersion(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void deleteArtifactVersion(String groupId, String artifactId, String version) {
if (!restConfig.isArtifactVersionDeletionEnabled()) {
throw new NotAllowedException("Artifact version deletion operation is not enabled.",
HttpMethod.GET, (String[]) null);
}
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
storage.deleteArtifactVersion(defaultGroupIdToNull(groupId), artifactId, version);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactVersionMetaData(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public VersionMetaData getArtifactVersionMetaData(String groupId, String artifactId, String version) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}
ArtifactVersionMetaDataDto dto = storage.getArtifactVersionMetaData(defaultGroupIdToNull(groupId),
artifactId, version);
return V2ApiUtil.dtoToVersionMetaData(defaultGroupIdToNull(groupId), artifactId,
dto.getArtifactType(), dto);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifactVersionMetaData(java.lang.String,
* java.lang.String, java.lang.String, io.apicurio.registry.rest.v2.beans.EditableMetaData)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3",
KEY_EDITABLE_METADATA })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactVersionMetaData(String groupId, String artifactId, String version,
EditableMetaData data) {
v3.updateArtifactVersionMetaData(groupId, artifactId, version,
io.apicurio.registry.rest.v3.beans.EditableVersionMetaData.builder()
.description(data.getDescription())
.labels(V2ApiUtil.toV3Labels(data.getLabels(), data.getProperties()))
.name(data.getName()).build());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifactVersionMetaData(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void deleteArtifactVersionMetaData(String groupId, String artifactId, String version) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
EditableVersionMetaDataDto vmd = EditableVersionMetaDataDto.builder().name("").description("")
.labels(Map.of()).build();
storage.updateArtifactVersionMetaData(defaultGroupIdToNull(groupId), artifactId, version, vmd);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#addArtifactVersionComment(java.lang.String,
* java.lang.String, java.lang.String, io.apicurio.registry.rest.v2.beans.NewComment)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public Comment addArtifactVersionComment(String groupId, String artifactId, String version,
NewComment data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
CommentDto newComment = storage.createArtifactVersionComment(defaultGroupIdToNull(groupId),
artifactId, version, data.getValue());
return V2ApiUtil.commentDtoToComment(newComment);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifactVersionComment(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3",
"comment_id" }) // TODO
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void deleteArtifactVersionComment(String groupId, String artifactId, String version,
String commentId) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
requireParameter("commentId", commentId);
storage.deleteArtifactVersionComment(defaultGroupIdToNull(groupId), artifactId, version, commentId);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#getArtifactVersionComments(java.lang.String,
* java.lang.String, java.lang.String)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Read)
public List<Comment> getArtifactVersionComments(String groupId, String artifactId, String version) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
if ("latest".equals(version)) {
var gav = VersionExpressionParser.parse(new GA(groupId, artifactId), "branch=latest",
(ga, branchId) -> storage.getBranchTip(ga, branchId, RetrievalBehavior.ALL_STATES));
version = gav.getRawVersionId();
}
return storage.getArtifactVersionComments(defaultGroupIdToNull(groupId), artifactId, version).stream()
.map(V2ApiUtil::commentDtoToComment).collect(Collectors.toList());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifactVersionComment(java.lang.String,
* java.lang.String, java.lang.String, java.lang.String,
* io.apicurio.registry.rest.v2.beans.NewComment)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3",
"comment_id" }) // TODO
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactVersionComment(String groupId, String artifactId, String version,
String commentId, NewComment data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
requireParameter("commentId", commentId);
requireParameter("value", data.getValue());
storage.updateArtifactVersionComment(defaultGroupIdToNull(groupId), artifactId, version, commentId,
data.getValue());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#updateArtifactVersionState(java.lang.String,
* java.lang.String, java.lang.String, io.apicurio.registry.rest.v2.beans.UpdateState)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_ID, "2", KEY_VERSION, "3",
KEY_UPDATE_STATE })
@Authorized(style = AuthorizedStyle.GroupAndArtifact, level = AuthorizedLevel.Write)
public void updateArtifactVersionState(String groupId, String artifactId, String version,
UpdateState data) {
requireParameter("groupId", groupId);
requireParameter("artifactId", artifactId);
requireParameter("version", version);
VersionState newState = VersionState.fromValue(data.getState().name());
storage.updateArtifactVersionState(groupId, artifactId, version, newState, false);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#listArtifactsInGroup(String, BigInteger, BigInteger,
* SortOrder, SortBy)
*/
@Override
@Authorized(style = AuthorizedStyle.GroupOnly, level = AuthorizedLevel.Read)
public ArtifactSearchResults listArtifactsInGroup(String groupId, BigInteger limit, BigInteger offset,
SortOrder order, SortBy orderby) {
requireParameter("groupId", groupId);
if (orderby == null) {
orderby = SortBy.name;
}
if (offset == null) {
offset = BigInteger.valueOf(0);
}
if (limit == null) {
limit = BigInteger.valueOf(20);
}
final OrderBy oBy = OrderBy.valueOf(orderby.name());
final OrderDirection oDir = order == null || order == SortOrder.asc ? OrderDirection.asc
: OrderDirection.desc;
Set<SearchFilter> filters = new HashSet<>();
filters.add(SearchFilter.ofGroupId(defaultGroupIdToNull(groupId)));
ArtifactSearchResultsDto resultsDto = storage.searchArtifacts(filters, oBy, oDir, offset.intValue(),
limit.intValue());
return V2ApiUtil.dtoToSearchResults(resultsDto);
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#deleteArtifactsInGroup(java.lang.String)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID })
@Authorized(style = AuthorizedStyle.GroupOnly, level = AuthorizedLevel.Write)
public void deleteArtifactsInGroup(String groupId) {
if (!restConfig.isArtifactDeletionEnabled()) {
throw new NotAllowedException("Artifact deletion operation is not enabled.", HttpMethod.GET,
(String[]) null);
}
requireParameter("groupId", groupId);
storage.deleteArtifacts(defaultGroupIdToNull(groupId));
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#createArtifact(String, String, String, String,
* IfExists, Boolean, String, String, String, String, String, String, InputStream)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_TYPE, "2", KEY_ARTIFACT_ID, "3",
KEY_VERSION, "4", KEY_IF_EXISTS, "5", KEY_CANONICAL, "6", KEY_DESCRIPTION, "7",
KEY_DESCRIPTION_ENCODED, "8", KEY_NAME, "9", KEY_NAME_ENCODED, "10", KEY_FROM_URL, "11",
KEY_SHA })
@Authorized(style = AuthorizedStyle.GroupOnly, level = AuthorizedLevel.Write)
public ArtifactMetaData createArtifact(String groupId, String xRegistryArtifactType,
String xRegistryArtifactId, String xRegistryVersion, IfExists ifExists, Boolean canonical,
String xRegistryDescription, String xRegistryDescriptionEncoded, String xRegistryName,
String xRegistryNameEncoded, String xRegistryContentHash, String xRegistryHashAlgorithm,
InputStream data) {
return this.createArtifactWithRefs(groupId, xRegistryArtifactType, xRegistryArtifactId,
xRegistryVersion, ifExists, canonical, xRegistryDescription, xRegistryDescriptionEncoded,
xRegistryName, xRegistryNameEncoded, xRegistryContentHash, xRegistryHashAlgorithm, data,
Collections.emptyList());
}
/**
* @see io.apicurio.registry.rest.v2.GroupsResource#createArtifact(String, String, String, String,
* IfExists, Boolean, String, String, String, String, String, String, ArtifactContent)
*/
@Override
@Audited(extractParameters = { "0", KEY_GROUP_ID, "1", KEY_ARTIFACT_TYPE, "2", KEY_ARTIFACT_ID, "3",
KEY_VERSION, "4", KEY_IF_EXISTS, "5", KEY_CANONICAL, "6", KEY_DESCRIPTION, "7",
KEY_DESCRIPTION_ENCODED, "8", KEY_NAME, "9", KEY_NAME_ENCODED, "10", KEY_FROM_URL, "11",
KEY_SHA })
@Authorized(style = AuthorizedStyle.GroupOnly, level = AuthorizedLevel.Write)
public ArtifactMetaData createArtifact(String groupId, String xRegistryArtifactType,
String xRegistryArtifactId, String xRegistryVersion, IfExists ifExists, Boolean canonical,
String xRegistryDescription, String xRegistryDescriptionEncoded, String xRegistryName,
String xRegistryNameEncoded, String xRegistryContentHash, String xRegistryHashAlgorithm,
ArtifactContent data) {
requireParameter("content", data.getContent());
Client client = null;
InputStream content;
try {
try {
URL url = new URL(data.getContent());
client = JAXRSClientUtil.getJAXRSClient(restConfig.getDownloadSkipSSLValidation());
content = fetchContentFromURL(client, url.toURI());
} catch (MalformedURLException | URISyntaxException e) {
content = IoUtil.toStream(data.getContent());
}
return this.createArtifactWithRefs(groupId, xRegistryArtifactType, xRegistryArtifactId,
xRegistryVersion, ifExists, canonical, xRegistryDescription, xRegistryDescriptionEncoded,
xRegistryName, xRegistryNameEncoded, xRegistryContentHash, xRegistryHashAlgorithm,
content, data.getReferences());
} catch (KeyManagementException kme) {
throw new RuntimeException(kme);
} catch (NoSuchAlgorithmException nsae) {
throw new RuntimeException(nsae);
} finally {
if (client != null) {
client.close();
}
}
}
public enum RegistryHashAlgorithm {
SHA256, MD5
}