public IEnumerable <Mutation> Generate(PackageURL arg)
        {
            if (!arg.HasNamespace())
            {
                yield break;
            }

            yield return(this.Generate(arg.ToString()).Single()); // Should only ever have one mutation.
        }
Beispiel #2
0
        /// <inheritdoc />
        public override IEnumerable <ArtifactUri <NPMArtifactType> > GetArtifactDownloadUris(PackageURL purl)
        {
            string feedUrl = (purl.Qualifiers?["repository_url"] ?? ENV_NPM_API_ENDPOINT).EnsureTrailingSlash();

            string artifactUri = purl.HasNamespace() ?
                                 $"{feedUrl}{purl.GetNamespaceFormatted()}/{purl.Name}/-/{purl.Name}-{purl.Version}.tgz" : // If there's a namespace.
                                 $"{feedUrl}{purl.Name}/-/{purl.Name}-{purl.Version}.tgz";                                 // If there isn't a namespace.

            yield return(new ArtifactUri <NPMArtifactType>(NPMArtifactType.Tarball, artifactUri));
        }
Beispiel #3
0
        /// <inheritdoc />
        public override async Task <string?> GetMetadataAsync(PackageURL purl, bool useCache = true)
        {
            try
            {
                string?    packageName = purl.HasNamespace() ? $"{purl.GetNamespaceFormatted()}/{purl.Name}" : purl.Name;
                HttpClient httpClient  = CreateHttpClient();

                string?content = await GetHttpStringCache(httpClient, $"{ENV_NPM_API_ENDPOINT}/{packageName}", useCache);

                return(content);
            }
            catch (Exception ex)
            {
                Logger.Debug(ex, $"Error fetching NPM metadata: {ex.Message}");
                return(null);
            }
        }
Beispiel #4
0
 public override Uri GetPackageAbsoluteUri(PackageURL purl)
 {
     return(new Uri(ENV_NPM_API_ENDPOINT.EnsureTrailingSlash() + (purl.HasNamespace() ? $"{purl.GetNamespaceFormatted()}/{purl.Name}" : purl.Name)));
 }