foojayio / foojayio/discoclient

DiscoClient.getPkgInfoByEphemeralId and downloadPkg not working

Open
#20 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
8
Forks
7
PR merge metrics
No merged PRs in 30d

Description

I have tried to use `DiscoClient.downloadPkg` which calls `DiscoClient.getPkgInfoByEphemeralId`.
But I get the following error:
```
java.lang.NullPointerException: Cannot invoke "com.google.gson.JsonArray.size()" because "jsonArray" is null
at io.foojay.api.discoclient@2.0.39/io.foojay.api.discoclient.DiscoClient.getPkgInfoByEphemeralId(DiscoClient.java:1556)
at io.foojay.api.discoclient@2.0.39/io.foojay.api.discoclient.DiscoClient.downloadPkg(DiscoClient.java:1691)
at io.foojay.api.discoclient@2.0.39/io.foojay.api.discoclient.DiscoClient.downloadPkg(DiscoClient.java:1679)
```
Which is a here:
https://github.com/foojayio/discoclient/blob/8a8bb4f7c5deef6e09ae4d24322926cd008a7b8f/src/main/java/io/foojay/api/discoclient/DiscoClient.java#L1554-L1557

The JsonObject returned by the API looks as follows:
```json
{
"_links": {
"self": [
{
"href": "/disco/v3.0/ephemeral_ids/f7bddbcbba0e705cfa297fd965408e32",
"templated": false
}
]
},
"_embedded": {
"errors": [
{
"message": "Page Not Found"
}
]
},
"message": "Not Found"
}
```
The `ephemeral_ids` endpoint is also not documented in swagger.
I have tried this for basically all packages:
```java
DiscoClient client = new DiscoClient();
for (Distribution distribution : client.getDistributions()) {
System.out.println(distribution.getName());
List packages = client.getPkgs(
List.of(distribution),
new VersionNumber(25),
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null,
null
);

for (Pkg pkg : packages) {
Path path = Paths.get("test").resolve(pkg.getFileName());
Files.createDirectories(path.getParent());
try {
client.downloadPkg(pkg.getId(), path.toAbsolutePath().toString());
return;
} catch (Exception e) {
System.out.println(distribution.getName() + " : " + pkg.getId());
e.printStackTrace();
}
}
}
```

Is the `ephemeral_ids` endpoint really part of the v3 API?
Usage in the client is confusing, here getPkgInfoByPkgId is used if API is v3:
https://github.com/foojayio/discoclient/blob/8a8bb4f7c5deef6e09ae4d24322926cd008a7b8f/src/main/java/io/foojay/api/discoclient/DiscoClient.java#L1507-L1511
This works well. But here if API version is v3, the package is downloaded by ephemeral id:
https://github.com/foojayio/discoclient/blob/8a8bb4f7c5deef6e09ae4d24322926cd008a7b8f/src/main/java/io/foojay/api/discoclient/DiscoClient.java#L1676-L1683
If I invert the if-statement it works. Is it possible that some of the if-statements should be different and use the `ephemeral_ids` only if not on API v3?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.