Added verbose output for public API to include docker template specification

This commit is contained in:
Josh Stark 2021-04-17 10:13:59 +01:00
parent 808fa21924
commit 9b6d4ccc3a
10 changed files with 326 additions and 20 deletions

View File

@ -9,7 +9,7 @@ repositories {
mavenCentral()
}
version = '2.2.1'
version = '2.3.0'
sourceSets {

View File

@ -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() {

View File

@ -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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
package io.linuxserver.fleet.v2.types.api.external.templates;
import java.util.ArrayList;
import java.util.List;
public class ApiTemplateHolder {
private final List<ApiPortTemplate> ports = new ArrayList<>();
private final List<ApiVolumeTemplate> volumes = new ArrayList<>();
private final List<ApiEnvTemplate> environmentVariables = new ArrayList<>();
private final List<ApiDeviceTemplate> devices = new ArrayList<>();
private final List<String> 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<String> getCapabilities() {
return capabilities;
}
public List<ApiDeviceTemplate> getDevices() {
return devices;
}
public List<ApiEnvTemplate> getEnvironmentVariables() {
return environmentVariables;
}
public List<ApiPortTemplate> getPorts() {
return ports;
}
public List<ApiVolumeTemplate> getVolumes() {
return volumes;
}
public boolean isHostNetwork() {
return hostNetwork;
}
public boolean isPrivileged() {
return privileged;
}
}

View File

@ -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 <https://www.gnu.org/licenses/>.
*/
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;
}
}

View File

@ -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);
}
}

View File

@ -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