use of io.dockstore.webservice.core.gitlab.GitLabTag in project dockstore by dockstore.
the class AbstractImageRegistry method getTagsGitLab.
private List<Tag> getTagsGitLab(Tool tool) {
final String repo = tool.getNamespace() + "%2F" + tool.getName();
final String projectPath = GITLAB_URL + "projects/" + repo + "/registry/repositories";
final List<Tag> tags = new ArrayList<>();
Optional<String> projectResponse;
try {
URL projectURL = new URL(projectPath);
projectResponse = Optional.of(IOUtils.toString(projectURL, StandardCharsets.UTF_8));
if (projectResponse.isPresent()) {
final String projectJSON = projectResponse.get();
Gson gson = new Gson();
Type gitLabContainerRegistryListType = new TypeToken<ArrayList<GitLabContainerRegistry>>() {
}.getType();
List<GitLabContainerRegistry> registries = gson.fromJson(projectJSON, gitLabContainerRegistryListType);
final String tagsListPath = projectPath + '/' + registries.get(0).getId() + '/' + "tags";
URL tagsListURL = new URL(tagsListPath);
Optional<String> tagsListResponse = Optional.of(IOUtils.toString(tagsListURL, StandardCharsets.UTF_8));
if (tagsListResponse.isPresent()) {
String tagsListJSON = tagsListResponse.get();
Type gitLabTagType = new TypeToken<ArrayList<GitLabTag>>() {
}.getType();
List<GitLabTag> gitLabTags = gson.fromJson(tagsListJSON, gitLabTagType);
try {
for (GitLabTag gitLabTag : gitLabTags) {
final String detailedTagInfoUrlString = tagsListPath + '/' + gitLabTag.getName();
URL detailedTagInfoURL = new URL(detailedTagInfoUrlString);
Optional<String> detailedTagInfoResponse = Optional.of(IOUtils.toString(detailedTagInfoURL, StandardCharsets.UTF_8));
if (detailedTagInfoResponse.isPresent()) {
final String detailedTagInfoJSON = detailedTagInfoResponse.get();
gitLabTag = gson.fromJson(detailedTagInfoJSON, GitLabTag.class);
final Tag tag = new Tag();
tag.setName(gitLabTag.getName());
final String manifestDigest = gitLabTag.getDigest();
List<Checksum> checksums = new ArrayList<>();
checksums.add(new Checksum(manifestDigest.split(":")[0], manifestDigest.split(":")[1]));
tag.getImages().add(new Image(checksums, tool.getNamespace() + '/' + tool.getName(), tag.getName(), null, Registry.GITLAB, gitLabTag.getTotalSize(), gitLabTag.getCreatedAt()));
tags.add(tag);
}
}
} catch (IndexOutOfBoundsException | NullPointerException ex) {
LOG.error("Unable to grab image and checksum information for" + tool.getNamespace() + '/' + tool.getName(), ex);
}
return tags;
}
} else {
LOG.info("Could not get response from GitLab");
}
} catch (IOException ex) {
LOG.error("Unable to get GitLab response for " + repo, ex);
}
return Collections.emptyList();
}
Aggregations