コード例 #1
0
        public void SetUp()
        {
            bucket            = "test-bucket";
            existingResource  = "test-resource";
            notFoundResource  = "not-found";
            files             = new[] { "file1", "file2" };
            cancellationToken = CancellationToken.None;

            s3Client = Substitute.For <IAwsS3Client>();
            s3Client.List(bucket, existingResource, cancellationToken).Returns(files);
            s3Client.List(bucket, notFoundResource, cancellationToken).Returns(new string[] { });
            s3Client.Download(bucket, resource: Arg.Any <string>(), destinationPath: Arg.Any <string>(), cancellationToken);
            s3Client.Download(bucket, resourceKey: Arg.Any <string>(), cancellationToken).Returns(new FileResponse("key", default));

            fileRetriever = new S3FileRetriever(s3Client);
        }
コード例 #2
0
        private async Task <string[]> FindFilesMatchingExpression(
            string bucket,
            string fileKey,
            string resourceExpressionPattern    = default,
            CancellationToken cancellationToken = default)
        {
            resourceExpressionPattern ??= DefaultResourceExpressionPattern;
            log.Debug("Using resource name expression pattern {resourceExpressionPattern}", resourceExpressionPattern);

            var regex = new Regex(resourceExpressionPattern, RegexOptions.CultureInvariant | RegexOptions.IgnoreCase | RegexOptions.Singleline);
            var files = (await s3Client.List(bucket, fileKey, cancellationToken)).Where(file => regex.IsMatch(file)).ToArray();

            if (files.Any() == false)
            {
                log.Warn("No files under {bucket}/{resource} matching {resourceExpressionPattern}", bucket, fileKey, resourceExpressionPattern);
                throw new ResourceNotFoundException(bucket, fileKey, resourceExpressionPattern);
            }

            return(files);
        }