Beispiel #1
0
        /// <summary>
        /// Lists all buckets, optionaly filtering by prefix. Prefix filtering happens on client side.
        /// </summary>
        public async Task <IEnumerable <BlobId> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.Prefix);

            var request = new ListObjectsV2Request()
            {
                BucketName = _bucketName,
                Prefix     = options.Prefix ?? null
            };

            if (options.MaxResults.HasValue)
            {
                request.MaxKeys = options.MaxResults.Value;
            }


            //todo: paging
            ListObjectsV2Response response = await _client.ListObjectsV2Async(request, cancellationToken);

            return(response.S3Objects
                   .Select(s3Obj => new BlobId(StoragePath.RootFolderPath, s3Obj.Key, BlobItemKind.File)));
        }
Beispiel #2
0
        /// <summary>
        /// Lists all buckets, optionaly filtering by prefix. Prefix filtering happens on client side.
        /// </summary>
        public async Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options = null, CancellationToken cancellationToken = default)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.FilePrefix);

            AmazonS3Client client = await GetClientAsync().ConfigureAwait(false);

            IReadOnlyCollection <Blob> blobs;

            using (var browser = new AwsS3DirectoryBrowser(client, _bucketName))
            {
                blobs = await browser.ListAsync(options, cancellationToken).ConfigureAwait(false);
            }

            if (options.IncludeAttributes)
            {
                foreach (IEnumerable <Blob> page in blobs.Where(b => !b.IsFolder).Chunk(ListChunkSize))
                {
                    await Converter.AppendMetadataAsync(client, _bucketName, page, cancellationToken).ConfigureAwait(false);
                }
            }

            return(blobs);
        }
        public async Task <IEnumerable <BlobId> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.Prefix);

            var secretNames         = new List <BlobId>();
            IPage <SecretItem> page = await _vaultClient.GetSecretsAsync(_vaultUri);

            do
            {
                secretNames.AddRange(page.Select(ToBlobId));
            }while (page.NextPageLink != null && (page = await _vaultClient.GetSecretsNextAsync(page.NextPageLink)) != null);

            if (options.Prefix == null)
            {
                return(secretNames);
            }

            return(secretNames
                   .Where(options.IsMatch)
                   .Take(options.MaxResults == null ? int.MaxValue : options.MaxResults.Value));
        }
Beispiel #4
0
        public async Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.FilePrefix);

            if (!StoragePath.IsRootPath(options.FolderPath))
            {
                return(new List <Blob>());
            }

            var secretNames         = new List <Blob>();
            IPage <SecretItem> page = await _vaultClient.GetSecretsAsync(_vaultUri).ConfigureAwait(false);

            do
            {
                var ids = page
                          .Select((Func <SecretItem, Blob>)AzureKeyVaultBlobStorageProvider.ToBlobId)
                          .Where(options.IsMatch)
                          .Where(s => options.BrowseFilter == null || options.BrowseFilter(s))
                          .ToList();
                secretNames.AddRange(ids);

                if (options.MaxResults != null && secretNames.Count >= options.MaxResults.Value)
                {
                    return(secretNames.Take(options.MaxResults.Value).ToList());
                }
            }while (page.NextPageLink != null && (page = await _vaultClient.GetSecretsNextAsync(page.NextPageLink).ConfigureAwait(false)) != null);

            return(secretNames);
        }
        /// <summary>
        /// Lists all buckets, optionaly filtering by prefix. Prefix filtering happens on client side.
        /// </summary>
        public async Task <IReadOnlyCollection <BlobId> > ListAsync(ListOptions options = null, CancellationToken cancellationToken = default)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.FilePrefix);

            var request = new ListObjectsV2Request()
            {
                BucketName = _bucketName,
                Prefix     = options.FilePrefix ?? null
            };

            if (options.MaxResults.HasValue)
            {
                request.MaxKeys = options.MaxResults.Value;
            }


            //todo: paging
            AmazonS3Client client = await GetClientAsync();

            ListObjectsV2Response response = await client.ListObjectsV2Async(request, cancellationToken);

            return(response.S3Objects
                   .Select(s3Obj => new BlobId(StoragePath.RootFolderPath, s3Obj.Key, BlobItemKind.File))
                   .Where(options.IsMatch)
                   .Where(bid => (options.FolderPath == null || bid.FolderPath == options.FolderPath))
                   .Where(bid => options.BrowseFilter == null || options.BrowseFilter(bid))
                   .ToList());
        }
        /// <summary>
        /// Returns the list of blob names in this storage, optionally filtered by prefix
        /// </summary>
        public Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.FilePrefix);

            if (!Directory.Exists(_directoryFullName))
            {
                return(Task.FromResult <IReadOnlyCollection <Blob> >(new List <Blob>()));
            }

            string fullPath = GetFolder(options?.FolderPath, false);

            if (fullPath == null)
            {
                return(Task.FromResult <IReadOnlyCollection <Blob> >(new List <Blob>()));
            }

            string[] fileIds = Directory.GetFiles(
                fullPath,
                string.IsNullOrEmpty(options.FilePrefix)
               ? "*"
               : options.FilePrefix + "*",
                options.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            string[] directoryIds = Directory.GetDirectories(
                fullPath,
                string.IsNullOrEmpty(options.FilePrefix)
                  ? "*"
                  : options.FilePrefix + "*",
                options.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            var result = new List <Blob>();

            result.AddRange(directoryIds.Select(id => ToBlobItem(id, BlobItemKind.Folder, options.IncludeAttributes)));
            result.AddRange(
                fileIds.Where(fid => !fid.EndsWith(AttributesFileExtension)).Select(id => ToBlobItem(id, BlobItemKind.File, options.IncludeAttributes)));
            result = result
                     .Where(i => options.BrowseFilter == null || options.BrowseFilter(i))
                     .Take(options.MaxResults == null ? int.MaxValue : options.MaxResults.Value)
                     .ToList();
            return(Task.FromResult <IReadOnlyCollection <Blob> >(result));
        }
        /// <summary>
        /// Returns the list of blob names in this storage, optionally filtered by prefix
        /// </summary>
        public Task <IEnumerable <BlobId> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.Prefix);

            if (!_directory.Exists)
            {
                return(null);
            }

            string fullPath = GetFolder(options?.FolderPath, false);

            if (fullPath == null)
            {
                return(Task.FromResult(Enumerable.Empty <BlobId>()));
            }

            string[] fileIds = Directory.GetFiles(
                fullPath,
                string.IsNullOrEmpty(options.Prefix)
               ? "*"
               : options.Prefix + "*",
                options.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            string[] directoryIds = Directory.GetDirectories(
                fullPath,
                string.IsNullOrEmpty(options.Prefix)
                  ? "*"
                  : options.Prefix + "*",
                options.Recurse ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            var result = new List <BlobId>();

            result.AddRange(directoryIds.Select(id => ToBlobItem(id, BlobItemKind.Folder)));
            result.AddRange(fileIds.Select(id => ToBlobItem(id, BlobItemKind.File)));
            result = result.Take(options.MaxResults == null ? int.MaxValue : options.MaxResults.Value).ToList();
            return(Task.FromResult <IEnumerable <BlobId> >(result));
        }
        public async Task <IReadOnlyCollection <Blob> > ListAsync(ListOptions options, CancellationToken cancellationToken)
        {
            if (options == null)
            {
                options = new ListOptions();
            }

            GenericValidation.CheckBlobPrefix(options.FilePrefix);

            if (!StoragePath.IsRootPath(options.FolderPath))
            {
                return(new List <Blob>());
            }

            var secrets = new List <Blob>();

            await foreach (SecretProperties secretProperties in _client.GetPropertiesOfSecretsAsync(cancellationToken).ConfigureAwait(false))
            {
                Blob blob = ToBlob(secretProperties);
                if (!options.IsMatch(blob))
                {
                    continue;
                }

                if (options.BrowseFilter != null && !options.BrowseFilter(blob))
                {
                    continue;
                }

                secrets.Add(blob);

                if (options.MaxResults != null && secrets.Count >= options.MaxResults.Value)
                {
                    break;
                }
            }

            return(secrets);
        }