Exemple #1
0
        public async Task <IFileSource> GetFileAsync(VersionSpec version)
        {
            BuildServices();
            var container = Client.GetContainerReference(ContainerName);
            await container.PrepContainer();

            var path  = BuildPath(version);
            var blobs = await container.ListBlobsAsync();

            if (MatchStrategy == null)
            {
                var blob = blobs
                           .OfType <CloudBlockBlob>()
                           .FirstOrDefault(
                    b => PatternMatcher.Match(b.Name, version)
                    );
                if (blob == null)
                {
                    throw new VersionNotFoundException($"No matches found from {blobs.Count} files using {PatternMatcher?.Name} matching!");
                }
                return(blob.ToSource(version));
            }
            var match = await MatchStrategy.MatchAsync(blobs, version);

            return(match);
        }
Exemple #2
0
        public async Task <IFileSource> GetFileAsync(VersionSpec version)
        {
            var blobs = new List <S3Object>();

            using (var client = BuildClient())
            {
                ListObjectsV2Request request = new ListObjectsV2Request
                {
                    BucketName = BucketName,
                    MaxKeys    = 10
                };
                ListObjectsV2Response response;
                do
                {
                    response = await client.ListObjectsV2Async(request);

                    blobs.AddRange(response.S3Objects);
                    request.ContinuationToken = response.NextContinuationToken;
                } while (response.IsTruncated == true);
            }
            if (MatchStrategy == null)
            {
                var blob = blobs.FirstOrDefault(
                    o => PatternMatcher.Match(o.Key, version)
                    );
                if (blob == null)
                {
                    throw new VersionNotFoundException();
                }
                return(ToSource(version, blob));
            }
            var match = await MatchStrategy.MatchAsync(blobs, version);

            return(match);
        }
Exemple #3
0
        public async Task <IFileSource> GetFileAsync(VersionSpec version)
        {
            if (Credentials == null)
            {
                _logger.LogCritical("Repo details not found! Please add GitHubStorage to your app configuration and restart the server.");
                throw new UnauthorizedAccessException("Repository details not found in configuration!");
            }
            try
            {
                var releases = await Client.Repository.Release.GetAll(Credentials.Owner, Credentials.Repo);

                if (MatchStrategy == null)
                {
                    foreach (var release in releases)
                    {
                        var asset = release.Assets.FirstOrDefault(a => PatternMatcher.Match(a.Name, version));
                        if (asset != null)
                        {
                            var source = new GitHubFileSource(version, !release.Draft);
                            source.Build(asset);
                            return(source);
                        }
                    }
                    throw new VersionNotFoundException();
                }
                return(await MatchStrategy.MatchAsync(releases, version));
            }
            catch (RateLimitExceededException)
            {
                throw new VersionNotFoundException("GitHub API rate limit exceeded! Unable to fetch releases. Please add an API token to the `GitHubStorage/ApiToken` configuration key.");
            }
        }