in Sources/XCMetricsBackendLib/UploadMetrics/Repository/LogFileGCSRepository.swift [62:87]
func put(logFile: File) throws -> URL {
let httpClient = HTTPClient(eventLoopGroupProvider: .shared(group))
defer {
try? httpClient.syncShutdown()
}
let groupEventLoop = group.next()
let gcs = try GoogleCloudStorageClient(credentials: credentialsConfiguration,
storageConfig: cloudStorageConfiguration,
httpClient: httpClient,
eventLoop: groupEventLoop)
let mediaLink = try gcs.object.createSimpleUpload(bucket: bucketName,
body: .byteBuffer(logFile.data.xcm_onlyFileData()),
name: logFile.filename,
contentType: "application/octet-stream")
.flatMap { uploadedObject -> EventLoopFuture<String> in
if let mediaLink = uploadedObject.mediaLink {
return groupEventLoop.makeSucceededFuture(mediaLink)
} else {
return groupEventLoop.future(error: RepositoryError.unexpected(message: "No link"))
}
}.wait()
guard let fileURL = URL(string: mediaLink) else {
throw RepositoryError.unexpected(message: "Malformed URL \(mediaLink)")
}
return fileURL
}