示例#1
0
        public async Task <DependencyVersion> GetLatestMetaDataAsync(RegistryDto registry, Dependency dependency)
        {
            RegistryClientConfiguration clientConfig = new RegistryClientConfiguration(new Uri(registry.Endpoint).GetComponents(UriComponents.HostAndPort, UriFormat.SafeUnescaped));

            DependencyVersion version;

            if (!string.IsNullOrWhiteSpace(registry.Username) && !string.IsNullOrWhiteSpace(registry.Password))
            {
                using (IRegistryClient client = clientConfig.CreateClient(new PasswordOAuthAuthenticationProvider(registry.Username, registry.Password)))
                {
                    ListImageTagsResponse imageTags = await client.Tags.ListImageTagsAsync(dependency.Name, new ListImageTagsParameters());

                    version = new DependencyVersion {
                        Dependency = dependency, DependencyId = dependency.Id, Version = imageTags.Tags.Last(), IsLatest = true
                    };
                }
            }
            else
            {
                using (IRegistryClient client = clientConfig.CreateClient())
                {
                    ListImageTagsResponse imageTags = await client.Tags.ListImageTagsAsync(dependency.Name, new ListImageTagsParameters());

                    version = new DependencyVersion {
                        Dependency = dependency, DependencyId = dependency.Id, Version = imageTags.Tags.Last(), IsLatest = true
                    };
                }
            }

            return(version);
        }
示例#2
0
        private async Task <DependencyVersion> HandleV2API(RegistryDto registry, Dependency dependency)
        {
            Uri       endpoint   = new Uri(new Uri(registry.Endpoint.Trim('/') + "/", UriKind.Absolute), new Uri($"FindPackagesById()?id='{dependency.Name}'&$filter=IsLatestVersion", UriKind.Relative));
            XDocument root       = XDocument.Parse(await client.GetStringAsync(endpoint));
            string    version    = root.XPathSelectElement("(//*[local-name() = '" + "Version" + "'])").Value;
            string    projectUrl = root.XPathSelectElement("(//*[local-name() = '" + "ProjectUrl" + "'])")?.Value;

            return(new DependencyVersion {
                IsLatest = true, Version = version, ProjectUrl = projectUrl, Dependency = dependency, DependencyId = dependency.Id,
            });
        }
示例#3
0
        public async Task <DependencyVersion> GetLatestMetaDataAsync(RegistryDto registry, Dependency dependency)
        {
            string query = new Uri(new Uri(registry.Endpoint.Trim('/') + "/", UriKind.Absolute), new Uri($"{dependency.Name}", UriKind.Relative)).ToString();
            string json  = await client.GetStringAsync(query);

            JObject resp    = JObject.Parse(json);
            string  version = resp["dist-tags"]["latest"].ToString();

            return(new DependencyVersion {
                IsLatest = true, Version = version, ProjectUrl = "", Dependency = dependency, DependencyId = dependency.Id,
            });
        }
示例#4
0
        public async Task <DependencyVersion> GetLatestMetaDataAsync(RegistryDto registry, Dependency dependency)
        {
            HttpResponseMessage response = await client.GetAsync(registry.Endpoint);

            string mediaType = response.Content.Headers.ContentType.MediaType;

            if (IsV2APIEndpoint(mediaType))
            {
                return(await HandleV2API(registry, dependency));
            }

            if (IsV3APIEndpoint(mediaType))
            {
                return(await HandleV3API(registry, dependency));
            }

            throw new Exception("Unhandled MediaType");
        }
示例#5
0
        public async Task <RegistryDto> GetByIdAsync(Guid registryId)
        {
            EcoRegistry registry = await context.EcoRegistrySources.FindAsync(registryId);

            RegistryDto dto = new RegistryDto
            {
                ApiKey     = registry.ApiKey,
                Username   = registry.Username,
                Password   = registry.Password,
                Endpoint   = registry.Endpoint,
                IsEnabled  = registry.IsEnabled,
                IsPublic   = registry.IsPublic,
                Kind       = registry.Kind,
                RegistryId = registry.Id
            };

            encryptionService.Decrypt(dto);

            return(dto);
        }
示例#6
0
        private async Task <DependencyVersion> HandleV3API(RegistryDto registry, Dependency dependency)
        {
            JObject root         = JObject.Parse(await client.GetStringAsync(registry.Endpoint));
            string  registration = root["resources"].Single(x => x["@type"].Value <string>() == "RegistrationsBaseUrl")["@id"].Value <string>();
            Uri     endpoint     = new Uri(new Uri(registration.Trim('/') + "/", UriKind.Absolute), new Uri(dependency.Name.ToLower() + "/" + "index.json", UriKind.Relative));

            logger.LogTrace($"Checking {endpoint} for latest version");

            string registryReponse = await client.GetStringAsync(endpoint);

            JObject json       = JObject.Parse(registryReponse);
            string  version    = json["items"].First["upper"].Value <string>();
            string  projectUrl = null; // TODO

            logger.LogTrace($"Found latest version for {dependency.Name}: {version}");

            return(new DependencyVersion {
                IsLatest = true, Version = version, ProjectUrl = projectUrl, Dependency = dependency, DependencyId = dependency.Id,
            });
        }
示例#7
0
        public async Task <RegistryDto> UpdateAsync(RegistryDto dto)
        {
            encryptionService.Encrypt(dto);

            EcoRegistry registry = context.EcoRegistrySources.Find(dto.RegistryId);

            registry.IsEnabled = dto.IsEnabled;
            registry.IsPublic  = dto.IsPublic;
            registry.Kind      = dto.Kind;
            registry.Endpoint  = dto.Endpoint;
            registry.ApiKey    = dto.ApiKey;
            registry.Username  = dto.Username;
            registry.Password  = dto.Password;

            context.EcoRegistrySources.Update(registry);
            await context.SaveChangesAsync();

            logger.LogInformation("Updated registry {0}", registry.Id);

            return(new RegistryDto {
                Endpoint = registry.Endpoint, ApiKey = registry.ApiKey, Kind = registry.Kind, RegistryId = registry.Id, IsPublic = dto.IsPublic, IsEnabled = dto.IsEnabled
            });
        }
示例#8
0
        private async Task <DependencyVersion> GetVersionByProviderAndRegistry(Dependency dependency, IDependencyVersionProvider service, RegistryDto registry)
        {
            logger.LogInformation($"{nameof(GetVersionByProviderAndRegistry)}::[{dependency.Name}]::[{registry.Endpoint}]::SEARCH::");

            DependencyVersion version = null;

            using (var serviceScope = logger.BeginScope($"{nameof(GetVersionByProviderAndRegistry)}::[{service.GetType().Name}]::SEARCH"))
            {
                version = await service.GetLatestMetaDataAsync(registry, dependency);
            }

            if (version != null)
            {
                logger.LogInformation($"{nameof(GetVersionByProviderAndRegistry)}::[{dependency.Name}]::[{registry.Endpoint}]::SUCCESS::[{version.Version}]");
            }
            else
            {
                logger.LogInformation($"{nameof(GetVersionByProviderAndRegistry)}::[{dependency.Name}]::[{registry.Endpoint}]::FAIL");
            }

            return(version);
        }
示例#9
0
 public async Task <DependencyVersion> GetLatestMetaDataAsync(RegistryDto registry, Dependency dependency)
 {
     // https://pypi.org/pypi
     return(await Task.FromResult(new DependencyVersion()));
 }
示例#10
0
 public void Encrypt(RegistryDto registry)
 {
     registry.ApiKey   = Encrypt(registry.ApiKey);
     registry.Username = Encrypt(registry.Username);
     registry.Password = Encrypt(registry.Password);
 }