Retrieve the basic information of a lazy ingested pypi package
@@ -43,6 +43,8 @@ public class LazyIngestionProvider {
}
public static void ingestArtifactIfNecessary(String packageName, String version, String artifactRepo, Long date) throws IllegalArgumentException, IOException {
+ switch(KnowledgeBaseConnector.forge){
+ case Constants.mvnForge: {
var groupId = packageName.split(Constants.mvnCoordinateSeparator)[0];
var artifactId = packageName.split(Constants.mvnCoordinateSeparator)[1];
if(artifactRepo == null || artifactRepo.isEmpty()) {
@@ -68,6 +70,29 @@ public class LazyIngestionProvider {
KafkaWriter.sendToKafka(KnowledgeBaseConnector.kafkaProducer, KnowledgeBaseConnector.ingestTopic, jsonRecord.toString());
}
}
+ break;
+ }
+ case Constants.pypiForge: {
+ var query = "https://pypi.org/pypi/" + packageName + "/" + version +"/json";
+ String result;
+ try {
+ result = MavenUtilities.sendGetRequest(query);
+ } catch (IllegalStateException ex) {
+ throw new IllegalArgumentException("PyPI package " + packageName + ":" + version
+ + " could not be found. Make sure the PyPI coordinate is correct");
+ }
+ JSONObject json = new JSONObject(result);
+ var requiresDist = json.getJSONObject("info").get("requires_dist");
+ var createdAt = ((JSONObject) json.getJSONObject("releases").getJSONArray(version).get(1)).get("upload_time");
+ var jsonRecord = new JSONObject();
+ jsonRecord.put("product", packageName);
+ jsonRecord.put("version", version);
+ jsonRecord.put("version_timestamp", createdAt);
+ jsonRecord.put("requires_dist", requiresDist);
+ System.out.println(jsonRecord.toString());
+ break;
+ }
+ }
}
public static void ingestArtifactWithDependencies(String packageName, String version) throws IllegalArgumentException, IOException {
