func get()

in Sources/XCMetricsBackendLib/UploadMetrics/Repository/LogFileGCSRepository.swift [89:118]


    func get(logURL: URL) throws -> LogFile {
        logger.info("[LogFileGCSRepository] get \(logURL), bucket: \(bucketName), object: \(logURL.lastPathComponent)")
        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 localURL = try gcs.object.getMedia(bucket: bucketName, object: logURL.lastPathComponent).flatMap { gcsObject -> EventLoopFuture<URL> in
            guard let data = gcsObject.data else {
                self.logger.error("[LogFileGCSRepository] file not found")
                return groupEventLoop.makeFailedFuture(RepositoryError.unexpected(message: "File not found in GCS \(logURL.lastPathComponent)"))
            }
            do {
                self.logger.info("[LogFileGCSRepository] saving file")
                let tmp = try TemporaryFile(creatingTempDirectoryForFilename: "\(UUID().uuidString).xcactivitylog")
                try data.write(to: tmp.fileURL)
                self.logger.info("[LogFileGCSRepository] file saved to \(tmp.fileURL)")
                return groupEventLoop.makeSucceededFuture(tmp.fileURL)
            } catch {
                self.logger.error("[LogFileGCSRepository] error saving log locally \(error)")
                return groupEventLoop.makeFailedFuture(error)
            }
        }.wait()
        return LogFile(remoteURL: logURL, localURL: localURL)
    }