mirror of
https://github.com/floci-io/floci-cli.git
synced 2026-11-22 21:50:47 -05:00
* fix(http): keep snapshot names in one path segment and report odd server responses clearly Snapshot names are URL-encoded and names that would change the path are refused; every trailing slash is stripped from the endpoint; a non-JSON body or a redirect gets a message that says so instead of a parser error; requests use HTTP/1.1. snapshot delete reports a missing snapshot API like save and load, save warns that --message is not sent yet, and export/import no longer cite a server version that does not exist. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(http): tell a missing snapshot API from its status, not from the error text The error message carries the request path, so a snapshot named nightly404 turned a real server error into 'not available'. FlociException now carries the HTTP status and the snapshot commands ask that. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
60 lines
1.9 KiB
Java
60 lines
1.9 KiB
Java
package io.floci.cli.commands.snapshot;
|
|
|
|
import io.floci.cli.GlobalOptions;
|
|
import io.floci.cli.ProductProfile;
|
|
import io.floci.cli.docker.DockerClient;
|
|
import io.floci.cli.http.FlociException;
|
|
import io.floci.cli.http.FlociHttpClient;
|
|
import io.floci.cli.output.Ansi;
|
|
import io.floci.cli.output.Printer;
|
|
import picocli.CommandLine.*;
|
|
|
|
import java.util.concurrent.Callable;
|
|
|
|
@Command(
|
|
name = "delete",
|
|
description = "Delete a Floci AWS snapshot",
|
|
mixinStandardHelpOptions = true
|
|
)
|
|
public class SnapshotDeleteCommand implements Callable<Integer> {
|
|
|
|
protected final ProductProfile profile;
|
|
|
|
@Mixin
|
|
protected GlobalOptions global;
|
|
|
|
public SnapshotDeleteCommand() {
|
|
this(ProductProfile.AWS);
|
|
}
|
|
|
|
protected SnapshotDeleteCommand(ProductProfile profile) {
|
|
this.profile = profile;
|
|
this.global = new GlobalOptions(profile);
|
|
}
|
|
|
|
@Parameters(index = "0", description = "Snapshot name", paramLabel = "<name>")
|
|
String name;
|
|
|
|
@Override
|
|
public Integer call() {
|
|
Printer printer = global.printer();
|
|
// Resolve the endpoint from the container's port mapping, like status/services/wait do,
|
|
// so a container started with --port <n> is still found without --endpoint.
|
|
String effectiveEndpoint = global.resolvedEndpoint(new DockerClient());
|
|
FlociHttpClient client = new FlociHttpClient(effectiveEndpoint, profile);
|
|
try {
|
|
client.deleteSnapshot(name);
|
|
printer.println(Ansi.green("Snapshot deleted:") + " " + name);
|
|
return 0;
|
|
} catch (FlociException e) {
|
|
if (e.endpointMissing()) {
|
|
printer.error("Snapshot API not available on this server version.\n" +
|
|
"Track progress: " + profile.serverRepo() + "/issues");
|
|
} else {
|
|
printer.error("Failed to delete snapshot: " + e.getMessage());
|
|
}
|
|
return 1;
|
|
}
|
|
}
|
|
}
|