@@ -648,73 +648,74 @@ public final class RegistryClient: Cancellable {
648
648
}
649
649
}
650
650
651
- public func getPublishRequirements(
652
- registryURL: URL ,
653
- timeout: DispatchTimeInterval ? = . none,
654
- observabilityScope: ObservabilityScope ,
655
- callbackQueue: DispatchQueue ,
656
- completion: @escaping ( Result < PublishRequirements , Error > ) -> Void
657
- ) {
658
- let completion = self . makeAsync ( completion, on: callbackQueue)
659
-
660
- guard var components = URLComponents ( url: registryURL, resolvingAgainstBaseURL: true ) else {
661
- return completion ( . failure( RegistryError . invalidURL ( registryURL) ) )
662
- }
663
- components. appendPathComponents ( " publish-requirements " )
664
- guard let url = components. url else {
665
- return completion ( . failure( RegistryError . invalidURL ( registryURL) ) )
666
- }
667
-
668
- let request = LegacyHTTPClient . Request (
669
- method: . get,
670
- url: url,
671
- headers: [
672
- " Accept " : self . acceptHeader ( mediaType: . json) ,
673
- ] ,
674
- options: self . defaultRequestOptions ( timeout: timeout, callbackQueue: callbackQueue)
675
- )
676
-
677
- self . httpClient. execute ( request, observabilityScope: observabilityScope, progress: nil ) { result in
678
- completion (
679
- result. tryMap { response in
680
- switch response. statusCode {
681
- case 200 :
682
- let publishRequirements = try response. parseJSON (
683
- Serialization . PublishRequirements. self,
684
- decoder: self . jsonDecoder
685
- )
686
-
687
- return PublishRequirements (
688
- metadata: . init(
689
- location: publishRequirements. metadata. location. map {
690
- switch $0 {
691
- case . archive:
692
- return . archive
693
- case . request:
694
- return . request
695
- }
696
- }
697
- ) ,
698
- signing: . init(
699
- required: publishRequirements. signing. required,
700
- acceptedSignatureFormats: publishRequirements. signing. acceptedSignatureFormats. map {
701
- switch $0 {
702
- case . CMS_1_0_0:
703
- return . CMS_1_0_0
704
- }
705
- } ,
706
- trustedRootCertificates: publishRequirements. signing. trustedRootCertificates
707
- )
708
- )
709
- default :
710
- throw self . unexpectedStatusError ( response, expectedStatus: [ 200 ] )
711
- }
712
- } . mapError {
713
- RegistryError . failedRetrievingRegistryPublishRequirements ( $0)
714
- }
715
- )
716
- }
717
- }
651
+ /*
652
+ public func getPublishRequirements(
653
+ registryURL: URL,
654
+ timeout: DispatchTimeInterval? = .none,
655
+ observabilityScope: ObservabilityScope,
656
+ callbackQueue: DispatchQueue,
657
+ completion: @escaping (Result<PublishRequirements, Error>) -> Void
658
+ ) {
659
+ let completion = self.makeAsync(completion, on: callbackQueue)
660
+
661
+ guard var components = URLComponents(url: registryURL, resolvingAgainstBaseURL: true) else {
662
+ return completion(.failure(RegistryError.invalidURL(registryURL)))
663
+ }
664
+ components.appendPathComponents("publish-requirements")
665
+ guard let url = components.url else {
666
+ return completion(.failure(RegistryError.invalidURL(registryURL)))
667
+ }
668
+
669
+ let request = LegacyHTTPClient.Request(
670
+ method: .get,
671
+ url: url,
672
+ headers: [
673
+ "Accept": self.acceptHeader(mediaType: .json),
674
+ ],
675
+ options: self.defaultRequestOptions(timeout: timeout, callbackQueue: callbackQueue)
676
+ )
677
+
678
+ self.httpClient.execute(request, observabilityScope: observabilityScope, progress: nil) { result in
679
+ completion(
680
+ result.tryMap { response in
681
+ switch response.statusCode {
682
+ case 200:
683
+ let publishRequirements = try response.parseJSON(
684
+ Serialization.PublishRequirements.self,
685
+ decoder: self.jsonDecoder
686
+ )
687
+
688
+ return PublishRequirements(
689
+ metadata: .init(
690
+ location: publishRequirements.metadata.location.map {
691
+ switch $0 {
692
+ case .archive:
693
+ return .archive
694
+ case .request:
695
+ return .request
696
+ }
697
+ }
698
+ ),
699
+ signing: .init(
700
+ required: publishRequirements.signing.required,
701
+ acceptedSignatureFormats: publishRequirements.signing.acceptedSignatureFormats.map {
702
+ switch $0 {
703
+ case .CMS_1_0_0:
704
+ return .CMS_1_0_0
705
+ }
706
+ },
707
+ trustedRootCertificates: publishRequirements.signing.trustedRootCertificates
708
+ )
709
+ )
710
+ default:
711
+ throw self.unexpectedStatusError(response, expectedStatus: [200])
712
+ }
713
+ }.mapError {
714
+ RegistryError.failedRetrievingRegistryPublishRequirements($0)
715
+ }
716
+ )
717
+ }
718
+ }*/
718
719
719
720
public func publish(
720
721
registryURL: URL ,
@@ -759,43 +760,46 @@ public final class RegistryClient: Cancellable {
759
760
}
760
761
761
762
// TODO: add generic support for upload requests in Basics
762
- var body = Data ( )
763
763
let boundary = UUID ( ) . uuidString
764
+ var parts = [ String] ( )
764
765
765
766
// archive field
766
- body. append ( contentsOf: """
767
- -- \( boundary)
767
+ parts. append ( """
768
768
Content-Disposition: form-data; name= \" source-archive \" \r
769
769
Content-Type: application/zip \r
770
770
Content-Transfer-Encoding: base64 \r
771
771
Content-Length: \( packageArchiveContent. count) \r
772
772
\r
773
- \( packageArchiveContent. base64EncodedString ( ) )
774
- """ . utf8 )
773
+ \( packageArchiveContent. base64EncodedString ( ) ) \r
774
+ """ )
775
775
776
776
if let metadataContent = metadataContent {
777
- // spacer
778
- body. append ( contentsOf: " \r \n " . utf8)
779
- // metadata fiels
780
- body. append ( contentsOf: """
781
- -- \( boundary) \r
777
+ parts. append ( """
782
778
Content-Disposition: form-data; name= \" metadata \" \r
783
779
Content-Type: application/json \r
784
780
Content-Transfer-Encoding: quoted-printable \r
785
781
Content-Length: \( metadataContent. count) \r
786
782
\r
787
- \( metadataContent)
788
- """ . utf8 )
783
+ \( metadataContent) \r
784
+ """ )
789
785
}
790
786
787
+ let bodyString = """
788
+ -- \( boundary) \r
789
+ \( parts. joined ( separator: " \n -- \( boundary) \r \n " ) )
790
+ -- \( boundary) -- \r \n
791
+ """
792
+
791
793
let request = LegacyHTTPClient . Request (
792
794
method: . put,
793
795
url: url,
794
796
headers: [
797
+ " Content-Type " : " multipart/form-data;boundary= \" \( boundary) \" " ,
795
798
" Accept " : self . acceptHeader ( mediaType: . json) ,
799
+ " Expect " : " 100-continue " ,
796
800
" Prefer " : " respond-async " ,
797
801
] ,
798
- body: body ,
802
+ body: Data ( bodyString . utf8 ) ,
799
803
options: self . defaultRequestOptions ( timeout: timeout, callbackQueue: callbackQueue)
800
804
)
801
805
@@ -1024,12 +1028,21 @@ extension RegistryClient {
1024
1028
}
1025
1029
1026
1030
extension RegistryClient {
1027
- public struct PublishRequirements {
1031
+ public struct PublishConfiguration {
1028
1032
public let metadata : Metadata
1029
1033
public let signing : Signing
1030
1034
1035
+ public init ( metadata: Metadata , signing: Signing ) {
1036
+ self . metadata = metadata
1037
+ self . signing = signing
1038
+ }
1039
+
1031
1040
public struct Metadata {
1032
1041
public let location : [ MetadataLocation ]
1042
+
1043
+ public init ( location: [ MetadataLocation ] ) {
1044
+ self . location = location
1045
+ }
1033
1046
}
1034
1047
1035
1048
public enum MetadataLocation {
@@ -1041,6 +1054,16 @@ extension RegistryClient {
1041
1054
public let required : Bool
1042
1055
public let acceptedSignatureFormats : [ SignatureFormat ]
1043
1056
public let trustedRootCertificates : [ String ]
1057
+
1058
+ public init (
1059
+ required: Bool ,
1060
+ acceptedSignatureFormats: [ SignatureFormat ] ,
1061
+ trustedRootCertificates: [ String ]
1062
+ ) {
1063
+ self . required = required
1064
+ self . acceptedSignatureFormats = acceptedSignatureFormats
1065
+ self . trustedRootCertificates = trustedRootCertificates
1066
+ }
1044
1067
}
1045
1068
}
1046
1069
}
0 commit comments