Skip to content

Commit

Permalink
conda service implementation
Browse files Browse the repository at this point in the history
removed extra semicolon

added architecture to conda revisions

removed base version

fix version fetching

fixed lint errors

update
  • Loading branch information
Basit Ayantunde committed Nov 24, 2023
1 parent 2e2083f commit a290ed0
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 0 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ The format of harvested data is tool-specific. Tool output is stored in the tool
- composer
- rubygem
- deb
- conda

## Provider Registry

Expand All @@ -258,6 +259,9 @@ The format of harvested data is tool-specific. Tool output is stored in the tool
- packagist.org
- proxy.golang.org
- ftp.debian.org
- repo.anaconda.com/pkgs/main (anaconda-main)
- repo.anaconda.com/pkgs/r (anaconda-r)
- conda.anaconda.org/conda-forge (conda-forge)

## Tool Name Registry

Expand Down
1 change: 1 addition & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ function createApp(config) {
app.use('/', require('./routes/index'))
app.use('/origins/github', require('./routes/originGitHub')())
app.use('/origins/crate', require('./routes/originCrate')())
app.use('/origins/conda', require('./routes/originConda')())
app.use('/origins/pod', require('./routes/originPod')())
app.use('/origins/npm', require('./routes/originNpm')())
app.use('/origins/maven', require('./routes/originMaven')())
Expand Down
2 changes: 2 additions & 0 deletions business/statsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class StatsService {
_getStatLookup() {
return {
total: () => this._getType('total'),
conda: () => this._getType('conda'),
condasource: () => this._getType('condasource'),
crate: () => this._getType('crate'),
gem: () => this._getType('gem'),
git: () => this._getType('git'),
Expand Down
4 changes: 4 additions & 0 deletions lib/licenseMatcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ class HarvestLicenseMatchPolicy {
switch (type) {
case 'maven':
return new BaseHarvestLicenseMatchStrategy('maven', ['manifest.summary.licenses'])
case 'conda':
return new BaseHarvestLicenseMatchStrategy('conda', ['registryData.license'])
case 'condasource':
return new BaseHarvestLicenseMatchStrategy('condasource', ['registryData.license'])
case 'crate':
return new BaseHarvestLicenseMatchStrategy('crate', ['registryData.license'])
case 'pod':
Expand Down
40 changes: 40 additions & 0 deletions providers/summary/clearlydefined.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ const mavenBasedUrls = {
gradleplugin: 'https://plugins.gradle.org/m2'
}

const condaChannels = {
'anaconda-main': 'https://repo.anaconda.com/pkgs/main',
'anaconda-r': 'https://repo.anaconda.com/pkgs/r',
'conda-forge': 'https://conda.anaconda.org/conda-forge'
}

class ClearlyDescribedSummarizer {
constructor(options) {
this.options = options
Expand All @@ -44,6 +50,12 @@ class ClearlyDescribedSummarizer {
case 'npm':
this.addNpmData(result, data, coordinates)
break
case 'conda':
this.addCondaData(result, data, coordinates)
break
case 'condasource':
this.addCondaSrcData(result, data, coordinates)
break
case 'crate':
this.addCrateData(result, data, coordinates)
break
Expand Down Expand Up @@ -191,6 +203,34 @@ class ClearlyDescribedSummarizer {
if (licenses.length) setIfValue(result, 'licensed.declared', SPDX.normalize(licenses.join(' OR ')))
}

addCondaData(result, data, coordinates) {
setIfValue(result, 'described.releaseDate', extractDate(data.releaseDate))
if (!data.registryData) return
const architecture = coordinates.revision.split('_')[1]
setIfValue(result, 'described.urls.registry', new URL(`${condaChannels[coordinates.provider]}/${architecture}/repodata.json`).href)
const downloadUrl = new URL(`${condaChannels[coordinates.provider]}/${architecture}/${data.registryData.packageFile}`).href
if (data.registryData.channelData.home) {
setIfValue(result, 'described.projectWebsite', data.registryData.channelData.home)
}
setIfValue(result, 'described.urls.download', downloadUrl)
setIfValue(result, 'licensed.declared', SPDX.normalize(data.declaredLicenses))
}

addCondaSrcData(result, data, coordinates) {
setIfValue(result, 'described.releaseDate', extractDate(data.releaseDate))
if (!data.registryData) return
if (data.registryData.channelData.source_url) {
const downloadUrl = new URL(`${data.registryData.channelData.source_url}`).href
setIfValue(result, 'described.urls.download', downloadUrl)
}
setIfValue(result, 'described.urls.registry', new URL(`${condaChannels[coordinates.provider]}/channeldata.json`).href)
if (data.registryData.channelData.home) {
setIfValue(result, 'described.projectWebsite', data.registryData.channelData.home)
}
setIfValue(result, 'licensed.declared', SPDX.normalize(data.declaredLicenses))
}


addCrateData(result, data, coordinates) {
setIfValue(result, 'described.releaseDate', extractDate(get(data, 'registryData.created_at')))
setIfValue(result, 'described.projectWebsite', get(data, 'manifest.homepage'))
Expand Down
72 changes: 72 additions & 0 deletions routes/originConda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) Microsoft Corporation and others. Licensed under the MIT license.
// SPDX-License-Identifier: MIT

const asyncMiddleware = require('../middleware/asyncMiddleware')
const router = require('express').Router()
const requestPromise = require('request-promise-native')
const { uniq } = require('lodash')
const condaChannels = {
'anaconda-main': 'https://repo.anaconda.com/pkgs/main',
'anaconda-r': 'https://repo.anaconda.com/pkgs/r',
'conda-forge': 'https://conda.anaconda.org/conda-forge'
}

router.get(
'/:name/:channel/revisions',
asyncMiddleware(async (request, response) => {
const { name, channel } = request.params
if (!condaChannels[channel]) {
return response.status(404).send([])
}
const url = `${condaChannels[channel]}/channeldata.json`
const channelData = await requestPromise({ url, method: 'GET', json: true })
if (channelData.packages[name]) {
let revisions = []
for (let subdir of channelData.packages[name].subdirs) {
const repoUrl = `${condaChannels[channel]}/${subdir}/repodata.json`
const repoData = await requestPromise({ url: repoUrl, method: 'GET', json: true })
if (repoData['packages']) {
Object.entries(repoData['packages'])
.forEach(([, packageData]) => {
if (packageData.name == name) {
revisions.push(`${packageData.version}_${subdir}`)
}
})
}
if (repoData['packages.conda']) {
Object.entries(repoData['packages.conda'])
.forEach(([, packageData]) => {
if (packageData.name == name) {
revisions.push(`${packageData.version}_${subdir}`)
}
})
}
}
return response.status(200).send(uniq(revisions))
} else {
return response.status(404).send([])
}
})
)

router.get(
'/:name/:channel',
asyncMiddleware(async (request, response) => {
const { name, channel } = request.params
if (!condaChannels[channel]) {
return response.status(404).send([])
}
const url = `${condaChannels[channel]}/channeldata.json`
const channelData = await requestPromise({ url, method: 'GET', json: true })
let matches = Object.entries(channelData.packages).filter(([packageName,]) => packageName.includes(name)).map(
([packageName,]) => { return { id: packageName } }
)
return response.status(200).send(matches)
})
)

function setup() {
return router
}

module.exports = setup
5 changes: 5 additions & 0 deletions schemas/curation-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"type": "string",
"enum": [
"npm",
"conda",
"condasource",
"crate",
"git",
"maven",
Expand All @@ -45,8 +47,11 @@
"provider": {
"type": "string",
"enum": [
"anaconda-main",
"anaconda-r",
"npmjs",
"cocoapods",
"conda-forge",
"cratesio",
"github",
"gitlab",
Expand Down
5 changes: 5 additions & 0 deletions schemas/curations-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
"type": "string",
"enum": [
"npm",
"conda",
"condasource",
"crate",
"git",
"go",
Expand All @@ -47,8 +49,11 @@
"provider": {
"type": "string",
"enum": [
"anaconda-main",
"anaconda-r",
"npmjs",
"cocoapods",
"conda-forge",
"cratesio",
"github",
"gitlab",
Expand Down
5 changes: 5 additions & 0 deletions schemas/definition-1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"type": {
"enum": [
"npm",
"conda",
"condasource",
"crate",
"git",
"maven",
Expand All @@ -48,8 +50,11 @@
},
"provider": {
"enum": [
"anaconda-main",
"anaconda-r",
"npmjs",
"cocoapods",
"conda-forge",
"cratesio",
"github",
"gitlab",
Expand Down

0 comments on commit a290ed0

Please sign in to comment.