/// <summary> /// Uploads multiple files given the globbing patterns provided by the selection properties. /// </summary> /// <param name="clientFactory"></param> /// <param name="deployment"></param> /// <param name="selection"></param> private IEnumerable <S3UploadResult> UploadMultiFileSelection(Func <AmazonS3Client> clientFactory, RunningDeployment deployment, S3MultiFileSelectionProperties selection) { Guard.NotNull(deployment, "Deployment may not be null"); Guard.NotNull(selection, "Mutli file selection properties may not be null"); Guard.NotNull(clientFactory, "Client factory must not be null"); var files = fileSystem.EnumerateFilesWithGlob(deployment.StagingDirectory, selection.Pattern).ToList(); if (!files.Any()) { Log.Info($"The glob pattern '{selection.Pattern}' didn't match any files. Nothing was uploaded to S3."); yield break; } Log.Info($"Glob pattern '{selection.Pattern}' matched {files.Count} files."); var substitutionPatterns = selection.VariableSubstitutionPatterns?.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; new SubstituteInFilesConvention(fileSystem, fileSubstituter, _ => substitutionPatterns.Any(), _ => substitutionPatterns) .Install(deployment); foreach (var matchedFile in files) { yield return(CreateRequest(matchedFile, GetBucketKey(fileSystem, matchedFile, new S3MultiFileSelectionBucketKeyAdapter(selection)), selection) .Tee(x => LogPutObjectRequest(matchedFile, x)) //We only warn on multi file uploads .Map(x => HandleUploadRequest(clientFactory(), x, WarnAndIgnoreException))); } }
/// <summary> /// Uploads multiple files given the globbing patterns provided by the selection properties. /// </summary> /// <param name="clientFactory"></param> /// <param name="deployment"></param> /// <param name="selection"></param> private async Task <IEnumerable <S3UploadResult> > UploadMultiFileSelection(Func <AmazonS3Client> clientFactory, RunningDeployment deployment, S3MultiFileSelectionProperties selection) { Guard.NotNull(deployment, "Deployment may not be null"); Guard.NotNull(selection, "Multi file selection properties may not be null"); Guard.NotNull(clientFactory, "Client factory must not be null"); var results = new List <S3UploadResult>(); var files = new RelativeGlobber((@base, pattern) => fileSystem.EnumerateFilesWithGlob(@base, pattern), deployment.StagingDirectory).EnumerateFilesWithGlob(selection.Pattern).ToList(); if (!files.Any()) { Log.Info($"The glob pattern '{selection.Pattern}' didn't match any files. Nothing was uploaded to S3."); return(results); } Log.Info($"Glob pattern '{selection.Pattern}' matched {files.Count} files"); var substitutionPatterns = SplitFilePatternString(selection.VariableSubstitutionPatterns); if (substitutionPatterns.Any()) { substituteInFiles.Substitute(deployment.CurrentDirectory, substitutionPatterns); } var structuredSubstitutionPatterns = SplitFilePatternString(selection.StructuredVariableSubstitutionPatterns); if (structuredSubstitutionPatterns.Any()) { structuredConfigVariablesService.ReplaceVariables(deployment.CurrentDirectory, structuredSubstitutionPatterns.ToList()); } foreach (var matchedFile in files) { var request = CreateRequest(matchedFile.FilePath, $"{selection.BucketKeyPrefix}{matchedFile.MappedRelativePath}", selection); LogPutObjectRequest(matchedFile.FilePath, request); results.Add(await HandleUploadRequest(clientFactory(), request, WarnAndIgnoreException)); } return(results); }
/// <summary> /// Uploads multiple files given the globbing patterns provided by the selection properties. /// </summary> /// <param name="clientFactory"></param> /// <param name="deployment"></param> /// <param name="selection"></param> private async Task <IEnumerable <S3UploadResult> > UploadMultiFileSelection(Func <AmazonS3Client> clientFactory, RunningDeployment deployment, S3MultiFileSelectionProperties selection) { Guard.NotNull(deployment, "Deployment may not be null"); Guard.NotNull(selection, "Multi file selection properties may not be null"); Guard.NotNull(clientFactory, "Client factory must not be null"); var results = new List <S3UploadResult>(); var files = new RelativeGlobber((@base, pattern) => fileSystem.EnumerateFilesWithGlob(@base, pattern), deployment.StagingDirectory).EnumerateFilesWithGlob(selection.Pattern).ToList(); if (!files.Any()) { Log.Info($"The glob pattern '{selection.Pattern}' didn't match any files. Nothing was uploaded to S3."); return(results); } Log.Info($"Glob pattern '{selection.Pattern}' matched {files.Count} files"); var substitutionPatterns = selection.VariableSubstitutionPatterns?.Split(new[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries) ?? new string[0]; new SubstituteInFilesConvention(fileSystem, fileSubstituter, _ => substitutionPatterns.Any(), _ => substitutionPatterns) .Install(deployment); foreach (var matchedFile in files) { var request = CreateRequest(matchedFile.FilePath, () => $"{selection.BucketKeyPrefix}{matchedFile.MappedRelativePath}", selection); LogPutObjectRequest(matchedFile.FilePath, request); results.Add(await HandleUploadRequest(clientFactory(), request, WarnAndIgnoreException)); } return(results); }
public S3MultiFileSelectionBucketKeyAdapter(S3MultiFileSelectionProperties properties) { this.properties = properties; }