From 9b6d4ccc3a79db77be1609ac449fdf64faa0bf27 Mon Sep 17 00:00:00 2001 From: Josh Stark Date: Sat, 17 Apr 2021 10:13:59 +0100 Subject: [PATCH] Added verbose output for public API to include docker template specification --- build.gradle | 2 +- .../AllImagesExternalApiResponse.java | 15 ++-- .../types/api/external/ExternalApiImage.java | 28 ++++-- .../external/templates/ApiDeviceTemplate.java | 36 ++++++++ .../external/templates/ApiEnvTemplate.java | 42 +++++++++ .../external/templates/ApiPortTemplate.java | 42 +++++++++ .../external/templates/ApiTemplateHolder.java | 85 +++++++++++++++++++ .../external/templates/ApiVolumeTemplate.java | 42 +++++++++ .../routes/LegacyExternalApiController.java | 48 +++++++++-- src/main/resources/version.properties | 6 +- 10 files changed, 326 insertions(+), 20 deletions(-) create mode 100644 src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiDeviceTemplate.java create mode 100644 src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiEnvTemplate.java create mode 100644 src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiPortTemplate.java create mode 100644 src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiTemplateHolder.java create mode 100644 src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiVolumeTemplate.java diff --git a/build.gradle b/build.gradle index 1296079..15d68e6 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ repositories { mavenCentral() } -version = '2.2.1' +version = '2.3.0' sourceSets { diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/AllImagesExternalApiResponse.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/AllImagesExternalApiResponse.java index 5397f98..5882644 100644 --- a/src/main/java/io/linuxserver/fleet/v2/types/api/external/AllImagesExternalApiResponse.java +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/AllImagesExternalApiResponse.java @@ -30,17 +30,20 @@ public class AllImagesExternalApiResponse { this.repositories = new HashMap<>(); } - public final void addImage(final String repositoryName, - final String imageName, - final long pullCount, - final String version, - final boolean stable) { + public final ExternalApiImage addImage(final String repositoryName, + final String imageName, + final long pullCount, + final String version, + final String category, + final boolean stable) { if (!repositories.containsKey(repositoryName)) { repositories.put(repositoryName, new ArrayList<>()); } - repositories.get(repositoryName).add(new ExternalApiImage(imageName, pullCount, version, stable)); + final ExternalApiImage apiImage = new ExternalApiImage(imageName, pullCount, version, category, stable); + repositories.get(repositoryName).add(apiImage); + return apiImage; } public final long getTotalPullCount() { diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiImage.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiImage.java index 35d49df..ca0ee74 100644 --- a/src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiImage.java +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/ExternalApiImage.java @@ -17,17 +17,23 @@ package io.linuxserver.fleet.v2.types.api.external; +import io.linuxserver.fleet.v2.types.api.external.templates.ApiTemplateHolder; + public class ExternalApiImage { - private String name; - private long pullCount; - private String version; - private boolean stable; + private final String name; + private final long pullCount; + private final String version; + private final String category; + private final boolean stable; - public ExternalApiImage(final String name, final long pullCount, final String version, final boolean stable) { + private ApiTemplateHolder templateSpec; + + public ExternalApiImage(final String name, final long pullCount, final String version, final String category, final boolean stable) { this.name = name; this.pullCount = pullCount; this.version = version; + this.category = category; this.stable = stable; } @@ -43,7 +49,19 @@ public class ExternalApiImage { return version; } + public final String getCategory() { + return category; + } + public final boolean isStable() { return stable; } + + public final void setTemplateSpec(final ApiTemplateHolder templateHolder) { + this.templateSpec = templateHolder; + } + + public final ApiTemplateHolder getTemplateSpec() { + return templateSpec; + } } diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiDeviceTemplate.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiDeviceTemplate.java new file mode 100644 index 0000000..0a4aabf --- /dev/null +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiDeviceTemplate.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2021 LinuxServer.io + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.linuxserver.fleet.v2.types.api.external.templates; + +public class ApiDeviceTemplate { + + private final String device; + private final String description; + + public ApiDeviceTemplate(final String device, final String description) { + this.device = device; + this.description = description; + } + + public String getDevice() { + return device; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiEnvTemplate.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiEnvTemplate.java new file mode 100644 index 0000000..74d1256 --- /dev/null +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiEnvTemplate.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 LinuxServer.io + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.linuxserver.fleet.v2.types.api.external.templates; + +public class ApiEnvTemplate { + + private final String name; + private final String exampleValue; + private final String description; + + public ApiEnvTemplate(final String name, final String exampleValue, final String description) { + this.name = name; + this.exampleValue = exampleValue; + this.description = description; + } + + public String getName() { + return name; + } + + public String getExampleValue() { + return exampleValue; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiPortTemplate.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiPortTemplate.java new file mode 100644 index 0000000..9e1f594 --- /dev/null +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiPortTemplate.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 LinuxServer.io + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.linuxserver.fleet.v2.types.api.external.templates; + +public class ApiPortTemplate { + + private final int port; + private final String protocol; + private final String description; + + public ApiPortTemplate(final int port, final String protocol, final String description) { + this.port = port; + this.protocol = protocol; + this.description = description; + } + + public int getPort() { + return port; + } + + public String getProtocol() { + return protocol; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiTemplateHolder.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiTemplateHolder.java new file mode 100644 index 0000000..570d793 --- /dev/null +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiTemplateHolder.java @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2021 LinuxServer.io + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.linuxserver.fleet.v2.types.api.external.templates; + +import java.util.ArrayList; +import java.util.List; + +public class ApiTemplateHolder { + + private final List ports = new ArrayList<>(); + private final List volumes = new ArrayList<>(); + private final List environmentVariables = new ArrayList<>(); + private final List devices = new ArrayList<>(); + private final List capabilities = new ArrayList<>(); + + public boolean hostNetwork; + public boolean privileged; + + public ApiTemplateHolder(final boolean hostNetwork, final boolean privileged) { + this.hostNetwork = hostNetwork; + this.privileged = privileged; + } + + public final void addCapability(final String cap) { + capabilities.add(cap); + } + + public final void addDevice(final ApiDeviceTemplate deviceTemplate) { + devices.add(deviceTemplate); + } + + public final void addEnv(final ApiEnvTemplate envTemplate) { + environmentVariables.add(envTemplate); + } + + public final void addPort(final ApiPortTemplate portTemplate) { + ports.add(portTemplate); + } + + public final void addVolume(final ApiVolumeTemplate volumeTemplate) { + volumes.add(volumeTemplate); + } + + public List getCapabilities() { + return capabilities; + } + + public List getDevices() { + return devices; + } + + public List getEnvironmentVariables() { + return environmentVariables; + } + + public List getPorts() { + return ports; + } + + public List getVolumes() { + return volumes; + } + + public boolean isHostNetwork() { + return hostNetwork; + } + + public boolean isPrivileged() { + return privileged; + } +} diff --git a/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiVolumeTemplate.java b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiVolumeTemplate.java new file mode 100644 index 0000000..eba4ef4 --- /dev/null +++ b/src/main/java/io/linuxserver/fleet/v2/types/api/external/templates/ApiVolumeTemplate.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2021 LinuxServer.io + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package io.linuxserver.fleet.v2.types.api.external.templates; + +public class ApiVolumeTemplate { + + private final String containerPath; + private final boolean readonly; + private final String description; + + public ApiVolumeTemplate(final String containerPath, final boolean readonly, final String description) { + this.containerPath = containerPath; + this.readonly = readonly; + this.description = description; + } + + public String getContainerPath() { + return containerPath; + } + + public boolean isReadonly() { + return readonly; + } + + public String getDescription() { + return description; + } +} diff --git a/src/main/java/io/linuxserver/fleet/v2/web/routes/LegacyExternalApiController.java b/src/main/java/io/linuxserver/fleet/v2/web/routes/LegacyExternalApiController.java index 497c9ec..baebec9 100644 --- a/src/main/java/io/linuxserver/fleet/v2/web/routes/LegacyExternalApiController.java +++ b/src/main/java/io/linuxserver/fleet/v2/web/routes/LegacyExternalApiController.java @@ -23,7 +23,11 @@ import io.linuxserver.fleet.v2.service.AbstractAppService; import io.linuxserver.fleet.v2.types.Image; import io.linuxserver.fleet.v2.types.Repository; import io.linuxserver.fleet.v2.types.api.external.AllImagesExternalApiResponse; +import io.linuxserver.fleet.v2.types.api.external.ExternalApiImage; import io.linuxserver.fleet.v2.types.api.external.ExternalApiResponse; +import io.linuxserver.fleet.v2.types.api.external.templates.*; +import io.linuxserver.fleet.v2.types.docker.DockerCapability; +import io.linuxserver.fleet.v2.types.meta.template.*; import io.linuxserver.fleet.v2.web.ApiException; import java.util.List; @@ -36,6 +40,8 @@ public class LegacyExternalApiController extends AbstractAppService { public final void fetchAllImages(final Context ctx) { + final boolean verboseOutput = ctx.queryParam("verbose", Boolean.class, "false").get(); + try { final AllImagesExternalApiResponse responseData = new AllImagesExternalApiResponse(); @@ -45,11 +51,15 @@ public class LegacyExternalApiController extends AbstractAppService { for (Image image : repository.getImages()) { - responseData.addImage(image.getRepositoryName(), - image.getName(), - image.getPullCount(), - image.getLatestTag().getVersion(), - image.isStable()); + final ExternalApiImage apiImage = responseData.addImage(image.getRepositoryName(), + image.getName(), + image.getPullCount(), + image.getLatestTag().getVersion(), + image.getMetaData().getCategory(), + image.isStable()); + if (verboseOutput) { + enrichImageWithTemplateData(apiImage, image.getMetaData().getTemplates()); + } } } @@ -59,4 +69,32 @@ public class LegacyExternalApiController extends AbstractAppService { throw new ApiException(e.getMessage(), e); } } + + private void enrichImageWithTemplateData(final ExternalApiImage apiImage, final ImageTemplateHolder templateHolder) { + + final ApiTemplateHolder apiTemplateHolder = new ApiTemplateHolder(templateHolder.isHostNetworkingEnabled(), + templateHolder.isPrivilegedMode()); + + for (PortTemplateItem port : templateHolder.getPorts()) { + apiTemplateHolder.addPort(new ApiPortTemplate(port.getPort(), port.getProtocol(), port.getDescription())); + } + + for (VolumeTemplateItem volume : templateHolder.getVolumes()) { + apiTemplateHolder.addVolume(new ApiVolumeTemplate(volume.getVolume(), volume.isReadonly(), volume.getDescription())); + } + + for (EnvironmentTemplateItem env : templateHolder.getEnv()) { + apiTemplateHolder.addEnv(new ApiEnvTemplate(env.getEnv(), env.getExampleValue(), env.getDescription())); + } + + for (DeviceTemplateItem device : templateHolder.getDevices()) { + apiTemplateHolder.addDevice(new ApiDeviceTemplate(device.getDevice(), device.getDescription())); + } + + for (DockerCapability capability : templateHolder.getCapabilities()) { + apiTemplateHolder.addCapability(capability.name()); + } + + apiImage.setTemplateSpec(apiTemplateHolder); + } } diff --git a/src/main/resources/version.properties b/src/main/resources/version.properties index 2141295..8456291 100644 --- a/src/main/resources/version.properties +++ b/src/main/resources/version.properties @@ -1,5 +1,5 @@ -#Sat Feb 13 16:35:07 GMT 2021 -app.build.date=2021-02-13T16\:35\:07 +#Sat Apr 17 10:13:48 BST 2021 +app.build.date=2021-04-17T10\:13\:48 app.build.os=Windows 10 app.build.user=jagfi -app.version=2.2.0 +app.version=2.3.0