Search in sources :

Example 1 with GitLabTag

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();
}
Also used : GitLabTag(io.dockstore.webservice.core.gitlab.GitLabTag) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) GitLabContainerRegistry(io.dockstore.webservice.core.gitlab.GitLabContainerRegistry) IOException(java.io.IOException) DockerHubImage(io.dockstore.webservice.core.dockerhub.DockerHubImage) Image(io.dockstore.webservice.core.Image) URL(java.net.URL) Type(java.lang.reflect.Type) Checksum(io.dockstore.webservice.core.Checksum) GitLabTag(io.dockstore.webservice.core.gitlab.GitLabTag) Tag(io.dockstore.webservice.core.Tag) DockerHubTag(io.dockstore.webservice.core.dockerhub.DockerHubTag)

Aggregations

Gson (com.google.gson.Gson)1 Checksum (io.dockstore.webservice.core.Checksum)1 Image (io.dockstore.webservice.core.Image)1 Tag (io.dockstore.webservice.core.Tag)1 DockerHubImage (io.dockstore.webservice.core.dockerhub.DockerHubImage)1 DockerHubTag (io.dockstore.webservice.core.dockerhub.DockerHubTag)1 GitLabContainerRegistry (io.dockstore.webservice.core.gitlab.GitLabContainerRegistry)1 GitLabTag (io.dockstore.webservice.core.gitlab.GitLabTag)1 IOException (java.io.IOException)1 Type (java.lang.reflect.Type)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1