diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e2e2603..c265fe46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ -## 0.99.2 (Unreleased) +## 0.99.2 (August 25th, 2020) + +ENHANCEMENTS: + +* [126](https://github.com/perfectsense/gyro-azure-provider/issues/126): Support subscription from auth properties file. +* [128](https://github.com/perfectsense/gyro-azure-provider/issues/128): Support remote file backend +* [130](https://github.com/perfectsense/gyro-azure-provider/issues/130): Add `exists(String file)` and `copy(String source, String dest)` methods to FileBackend. ## 0.99.1 (July 6th, 2020) diff --git a/README.md b/README.md index 829e41b9..db36db5d 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Load the Azure provider in your project by consuming it as a `plugin` directive ```shell @repository: 'https://artifactory.psdops.com/gyro-releases' -@plugin: 'gyro:gyro-azure-provider:0.99.0' +@plugin: 'gyro:gyro-azure-provider:0.99.2' ``` #### Authentication #### diff --git a/src/main/java/gyro/azure/AbstractAzureCommand.java b/src/main/java/gyro/azure/AbstractAzureCommand.java index 6dbeea1a..29d28dc6 100644 --- a/src/main/java/gyro/azure/AbstractAzureCommand.java +++ b/src/main/java/gyro/azure/AbstractAzureCommand.java @@ -36,12 +36,12 @@ import gyro.lang.ast.Node; import gyro.lang.ast.block.FileNode; import gyro.util.Bug; -import io.airlift.airline.Option; import org.apache.commons.lang3.StringUtils; +import picocli.CommandLine.Option; public abstract class AbstractAzureCommand { - @Option(name = "--credential", description = "The azure credentials to be used as defined in the project init file. When not specified the 'default' credential is used.") + @Option(names = "--credential", description = "The azure credentials to be used as defined in the project init file. When not specified the 'default' credential is used.") private String credential; private RootScope scope; @@ -91,7 +91,9 @@ public Azure getClient() { .get("azure::" + getCredential()); if (credentials == null) { - throw new GyroException(String.format("No credentials with name - '%s' found. Check the your project init file.", getCredential())); + throw new GyroException(String.format( + "No credentials with name - '%s' found. Check the your project init file.", + getCredential())); } return AzureResource.createClient((AzureCredentials) credentials); diff --git a/src/main/java/gyro/azure/AzureCommand.java b/src/main/java/gyro/azure/AzureCommand.java index 092767cf..24c09503 100644 --- a/src/main/java/gyro/azure/AzureCommand.java +++ b/src/main/java/gyro/azure/AzureCommand.java @@ -16,62 +16,29 @@ package gyro.azure; -import java.util.List; - -import gyro.azure.keyvault.AbstractVaultCommand; -import gyro.azure.network.AbstractApplicationGatewayCommand; +import gyro.azure.keyvault.AzureKeyVaultCommand; +import gyro.azure.network.AzureApplicationGatewayCommand; import gyro.core.command.GyroCommand; -import io.airlift.airline.Arguments; -import io.airlift.airline.Cli; -import io.airlift.airline.Command; -import io.airlift.airline.Help; -import org.reflections.Reflections; -import org.reflections.util.ClasspathHelper; - -@Command(name = "azure", description = "CLI command for all things azure") -public class AzureCommand implements GyroCommand { - - public static Reflections reflections; - - @Arguments(description = "", required = true) - private List arguments; - - public static Reflections getReflections() { - if (reflections == null) { - reflections = new Reflections(new org.reflections.util.ConfigurationBuilder() - .setUrls(ClasspathHelper.forPackage("gyro.azure"))); - } - - return reflections; +import picocli.CommandLine.Command; + +@Command(name = "azure", + description = "Manage azure assets.", + synopsisHeading = "%n", + header = "Add, remove, or list assets part of key-vault and application-gateway.", + descriptionHeading = "%nDescription:%n%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + commandListHeading = "%nCommands:%n", + usageHelpWidth = 100, + subcommands = { + AzureKeyVaultCommand.class, + AzureApplicationGatewayCommand.class } +) +public class AzureCommand implements GyroCommand { @Override public void execute() throws Exception { - Cli.CliBuilder builder = Cli.builder("azure") - .withDescription("CLI command for all things azure") - .withDefaultCommand(Help.class) - .withCommands(Help.class); - - // Vault command loader - AbstractVaultCommand.setVaultCommand(builder); - - // Application gateway command loader - AbstractApplicationGatewayCommand.setApplicationGatewayCommand(builder); - - Cli gitParser = builder.build(); - - Object command = gitParser.parse(arguments); - if (command instanceof Runnable) { - ((Runnable) command).run(); - } else if (command instanceof GyroCommand) { - ((GyroCommand) command).execute(); - } else { - throw new IllegalStateException(String.format( - "[%s] must be an instance of [%s] or [%s]!", - command.getClass().getName(), - Runnable.class.getName(), - GyroCommand.class.getName())); - } } } diff --git a/src/main/java/gyro/azure/keyvault/AbstractVaultCommand.java b/src/main/java/gyro/azure/keyvault/AbstractVaultCommand.java index 4bcc81f6..1ae025e1 100644 --- a/src/main/java/gyro/azure/keyvault/AbstractVaultCommand.java +++ b/src/main/java/gyro/azure/keyvault/AbstractVaultCommand.java @@ -16,21 +16,17 @@ package gyro.azure.keyvault; -import java.util.ArrayList; -import java.util.List; +import java.util.concurrent.Callable; import com.microsoft.azure.management.Azure; import com.microsoft.azure.management.keyvault.Vault; import gyro.azure.AbstractAzureCommand; -import gyro.azure.AzureCommand; import gyro.core.GyroException; import gyro.core.command.GyroCommand; import gyro.core.resource.Resource; import gyro.core.scope.RootScope; -import io.airlift.airline.Cli; -import io.airlift.airline.Help; -public abstract class AbstractVaultCommand extends AbstractAzureCommand implements GyroCommand { +public abstract class AbstractVaultCommand extends AbstractAzureCommand implements GyroCommand, Callable { public static Vault getVault(String vaultResourceName, RootScope scope, Azure client) { Resource resource = scope.findResource("azure::key-vault::" + vaultResourceName); @@ -55,12 +51,9 @@ Vault getVault(String vaultResourceName) { return getVault(vaultResourceName, scope, client); } - public static void setVaultCommand(Cli.CliBuilder builder) { - List> subTypesOf = new ArrayList<>(AzureCommand.getReflections().getSubTypesOf(AbstractVaultCommand.class)); - - builder.withGroup("key-vault") - .withDescription("Manage azure key-vault secrets, keys and certificates") - .withDefaultCommand(Help.class) - .withCommands(subTypesOf); + @Override + public Integer call() throws Exception { + execute(); + return 0; } } diff --git a/src/main/java/gyro/azure/keyvault/AddVaultCertificateCommand.java b/src/main/java/gyro/azure/keyvault/AddVaultCertificateCommand.java index c0e58a59..990198ee 100644 --- a/src/main/java/gyro/azure/keyvault/AddVaultCertificateCommand.java +++ b/src/main/java/gyro/azure/keyvault/AddVaultCertificateCommand.java @@ -26,17 +26,22 @@ import com.psddev.dari.util.ObjectUtils; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; -import io.airlift.airline.Option; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; -@Command(name = "add-certificate", description = "Add a certificate to an Azure key vault") +@Command(name = "add-certificate", + header = "Add a certificate to an Azure key vault.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class AddVaultCertificateCommand extends AbstractVaultCommand { - @Arguments(description = "The command requires three arguments. : the key-vault resource name used in the config to which the certificate would be added. : name of the certificate to be added. : the path to the certificate file (.pfx)", required = true) + @Parameters(description = "The command requires three arguments. : the key-vault resource name used in the config to which the certificate would be added. : name of the certificate to be added. : the path to the certificate file (.pfx)", arity = "1") private List arguments; - @Option(name = { "--password" }, description = "Password used to encrypt the certificate file") + @Option(names = "--password", description = "Password used to encrypt the certificate file.", arity = "0..1", interactive = true) private String password; @Override diff --git a/src/main/java/gyro/azure/keyvault/AddVaultSecretCommand.java b/src/main/java/gyro/azure/keyvault/AddVaultSecretCommand.java index 8e36d38c..c553c154 100644 --- a/src/main/java/gyro/azure/keyvault/AddVaultSecretCommand.java +++ b/src/main/java/gyro/azure/keyvault/AddVaultSecretCommand.java @@ -8,27 +8,32 @@ import com.psddev.dari.util.ObjectUtils; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; -import io.airlift.airline.Option; import org.joda.time.DateTime; - -@Command(name = "add-secret", description = "Add a secret to an Azure key vault") +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +@Command(name = "add-secret", + header = "Add a secret to an Azure key vault.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class AddVaultSecretCommand extends AbstractVaultCommand { - @Arguments(description = "The command requires three arguments. : the key-vault resource name used in the config to which the secret would be added. : name of the secret to be added. : the secret value", required = true) + @Parameters(description = "The command requires three arguments. : the key-vault resource name used in the config to which the secret would be added. : name of the secret to be added. : the secret value", arity = "1") private List arguments; - @Option(name = { "--content-type" }, description = "Content type for the secret") + @Option(names = "--content-type", description = "Content type for the secret.") private String contentType; - @Option(name = { "--expires" }, description = "A date time value value in UTC specifying the expiration time. Format 'YYYY-MM-DDTHH:MM:SS.sssZ'") + @Option(names = "--expires", description = "A date time value value in UTC specifying the expiration time. Format 'YYYY-MM-DDTHH:MM:SS.sssZ'.") private String expires; - @Option(name = { "--not-before" }, description = "A date time value value in UTC specifying the expiration not before a specific time. Format 'YYYY-MM-DDTHH:MM:SS.sssZ'") + @Option(names = "--not-before", description = "A date time value value in UTC specifying the expiration not before a specific time. Format 'YYYY-MM-DDTHH:MM:SS.sssZ'.") private String notBefore; - @Option(name = { "--enabled" }, description = "Enable/Disable the secret. Defaults to 'false'") + @Option(names = "--enabled", description = "Enable/Disable the secret. Defaults to 'false'.") private boolean enabled; @Override diff --git a/src/main/java/gyro/azure/keyvault/AzureKeyVaultCommand.java b/src/main/java/gyro/azure/keyvault/AzureKeyVaultCommand.java new file mode 100644 index 00000000..bc2164c0 --- /dev/null +++ b/src/main/java/gyro/azure/keyvault/AzureKeyVaultCommand.java @@ -0,0 +1,26 @@ +package gyro.azure.keyvault; + +import gyro.core.command.GyroCommandGroup; +import picocli.CommandLine; + +@CommandLine.Command(name = "key-vault", + description = "Manage azure key-vault secrets, keys and certificates.", + synopsisHeading = "%n", + header = "Add, remove, or list certificates and secrets of key-vault.", + descriptionHeading = "%nDescription:%n%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + commandListHeading = "%nCommands:%n", + usageHelpWidth = 100, + subcommands = { + AddVaultCertificateCommand.class, + AddVaultSecretCommand.class, + ListVaultCertificateCommand.class, + ListVaultSecretCommand.class, + RemoveVaultCertificateCommand.class, + RemoveVaultSecretCommand.class + } +) +public class AzureKeyVaultCommand implements GyroCommandGroup { + +} diff --git a/src/main/java/gyro/azure/keyvault/ListVaultCertificateCommand.java b/src/main/java/gyro/azure/keyvault/ListVaultCertificateCommand.java index e15ca93f..78acee39 100644 --- a/src/main/java/gyro/azure/keyvault/ListVaultCertificateCommand.java +++ b/src/main/java/gyro/azure/keyvault/ListVaultCertificateCommand.java @@ -17,25 +17,28 @@ package gyro.azure.keyvault; import java.util.List; -import java.util.stream.Collectors; import com.microsoft.azure.PagedList; import com.microsoft.azure.keyvault.models.CertificateItem; import com.microsoft.azure.management.keyvault.Vault; -import com.microsoft.azure.management.network.ApplicationGatewaySslCertificate; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; -import io.airlift.airline.Option; +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; -@Command(name = "list-certificate", description = "List all certificates present in an Azure key vault") +@Command(name = "list-certificate", + header = "List all certificates present in an Azure key vault.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class ListVaultCertificateCommand extends AbstractVaultCommand { - @Arguments(description = "The command requires one argument. : the key-vault resource name used in the config whose certificates would be listed", required = true) + @Parameters(description = "The command requires one argument. : the key-vault resource name used in the config whose certificates would be listed.", arity = "1") private List arguments; - @Option(name = "--show-thumbprint", description = "Show thumbprint of the certificate") + @Option(names = "--show-thumbprint", description = "Show thumbprint of the certificate.") private boolean showThumbprint; @Override @@ -49,14 +52,16 @@ public void execute() throws Exception { if (!certificateItemPagedList.isEmpty()) { certificateItemPagedList.loadAll(); - for (CertificateItem certificate: certificateItemPagedList) { + for (CertificateItem certificate : certificateItemPagedList) { StringBuilder sb = new StringBuilder(); sb.append("\n***********************"); sb.append(String.format("\nName: %s", certificate.identifier().name())); sb.append(String.format("\nVersion: %s", certificate.identifier().version())); if (showThumbprint) { - sb.append(String.format("\nThumbprint: %s", certificate.x509Thumbprint() != null ? new String(certificate.x509Thumbprint()) : null)); + sb.append(String.format( + "\nThumbprint: %s", + certificate.x509Thumbprint() != null ? new String(certificate.x509Thumbprint()) : null)); } GyroCore.ui().write(sb.toString()); diff --git a/src/main/java/gyro/azure/keyvault/ListVaultSecretCommand.java b/src/main/java/gyro/azure/keyvault/ListVaultSecretCommand.java index 14b3876c..ca9c7747 100644 --- a/src/main/java/gyro/azure/keyvault/ListVaultSecretCommand.java +++ b/src/main/java/gyro/azure/keyvault/ListVaultSecretCommand.java @@ -7,13 +7,18 @@ import com.microsoft.azure.management.keyvault.Vault; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; - -@Command(name = "list-secret", description = "List all secrets present in an Azure key vault") +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; + +@Command(name = "list-secret", + header = "List all secrets present in an Azure key vault.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class ListVaultSecretCommand extends AbstractVaultCommand { - @Arguments(description = "The command requires one argument. : the key-vault resource name used in the config whose secrets would be listed", required = true) + @Parameters(description = "The command requires one argument. : the key-vault resource name used in the config whose secrets would be listed.", arity = "1") private List arguments; @Override @@ -27,7 +32,7 @@ public void execute() throws Exception { if (!secretItemPagedList.isEmpty()) { secretItemPagedList.loadAll(); - for (SecretItem secret: secretItemPagedList) { + for (SecretItem secret : secretItemPagedList) { StringBuilder sb = new StringBuilder(); sb.append("\n***********************"); sb.append(String.format("\nName: %s", secret.identifier().name())); diff --git a/src/main/java/gyro/azure/keyvault/RemoveVaultCertificateCommand.java b/src/main/java/gyro/azure/keyvault/RemoveVaultCertificateCommand.java index a6bcfbea..70cde37f 100644 --- a/src/main/java/gyro/azure/keyvault/RemoveVaultCertificateCommand.java +++ b/src/main/java/gyro/azure/keyvault/RemoveVaultCertificateCommand.java @@ -21,13 +21,18 @@ import com.microsoft.azure.management.keyvault.Vault; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; - -@Command(name = "remove-certificate", description = "Remove a certificate from an Azure key vault") +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; + +@Command(name = "remove-certificate", + description = "Remove a certificate from an Azure key vault", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class RemoveVaultCertificateCommand extends AbstractVaultCommand { - @Arguments(description = "The command requires two arguments. : the key-vault resource name used in the config from which the certificate would be removed. : name of the certificate to be removed.", required = true) + @Parameters(description = "The command requires two arguments. : the key-vault resource name used in the config from which the certificate would be removed. : name of the certificate to be removed.", arity = "1") private List arguments; @Override diff --git a/src/main/java/gyro/azure/keyvault/RemoveVaultSecretCommand.java b/src/main/java/gyro/azure/keyvault/RemoveVaultSecretCommand.java index 14722ec8..50392adb 100644 --- a/src/main/java/gyro/azure/keyvault/RemoveVaultSecretCommand.java +++ b/src/main/java/gyro/azure/keyvault/RemoveVaultSecretCommand.java @@ -5,13 +5,18 @@ import com.microsoft.azure.management.keyvault.Vault; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; - -@Command(name = "remove-secret", description = "Remove a secret from an Azure key vault") +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; + +@Command(name = "remove-secret", + header = "Remove a secret from an Azure key vault.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class RemoveVaultSecretCommand extends AbstractVaultCommand { - @Arguments(description = "The command requires two arguments. : the key-vault resource name used in the config from which the secret would be removed. : name of the secret to be removed.", required = true) + @Parameters(description = "The command requires two arguments. : the key-vault resource name used in the config from which the secret would be removed. : name of the secret to be removed.", arity = "1") private List arguments; @Override @@ -29,4 +34,4 @@ public void execute() throws Exception { throw new GyroException("'remove-secret' needs exactly two arguments, "); } } -} \ No newline at end of file +} diff --git a/src/main/java/gyro/azure/network/AbstractApplicationGatewayCommand.java b/src/main/java/gyro/azure/network/AbstractApplicationGatewayCommand.java index ed4a91d0..f193776b 100644 --- a/src/main/java/gyro/azure/network/AbstractApplicationGatewayCommand.java +++ b/src/main/java/gyro/azure/network/AbstractApplicationGatewayCommand.java @@ -1,20 +1,16 @@ package gyro.azure.network; -import java.util.ArrayList; -import java.util.List; +import java.util.concurrent.Callable; import com.microsoft.azure.management.Azure; import com.microsoft.azure.management.network.ApplicationGateway; import gyro.azure.AbstractAzureCommand; -import gyro.azure.AzureCommand; import gyro.core.GyroException; import gyro.core.command.GyroCommand; import gyro.core.resource.Resource; import gyro.core.scope.RootScope; -import io.airlift.airline.Cli; -import io.airlift.airline.Help; -public abstract class AbstractApplicationGatewayCommand extends AbstractAzureCommand implements GyroCommand { +public abstract class AbstractApplicationGatewayCommand extends AbstractAzureCommand implements GyroCommand, Callable { ApplicationGateway getApplicationGateway(String applicationGatewayResourceName) { RootScope scope = getScope(); @@ -33,16 +29,15 @@ ApplicationGateway getApplicationGateway(String applicationGatewayResourceName) return applicationGateway; } else { - throw new GyroException(String.format("No 'application-gateway' resource found with name - %s", applicationGatewayResourceName)); + throw new GyroException(String.format( + "No 'application-gateway' resource found with name - %s", + applicationGatewayResourceName)); } } - public static void setApplicationGatewayCommand(Cli.CliBuilder builder) { - List> subTypesOf = new ArrayList<>(AzureCommand.getReflections().getSubTypesOf(AbstractApplicationGatewayCommand.class)); - - builder.withGroup("application-gateway") - .withDescription("Manage azure application gateway certificates") - .withDefaultCommand(Help.class) - .withCommands(subTypesOf); + @Override + public Integer call() throws Exception { + execute(); + return 0; } } diff --git a/src/main/java/gyro/azure/network/AddApplicationGatewayCertificateCommand.java b/src/main/java/gyro/azure/network/AddApplicationGatewayCertificateCommand.java index 9a52ed5a..488933e1 100644 --- a/src/main/java/gyro/azure/network/AddApplicationGatewayCertificateCommand.java +++ b/src/main/java/gyro/azure/network/AddApplicationGatewayCertificateCommand.java @@ -7,17 +7,22 @@ import com.psddev.dari.util.ObjectUtils; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; -import io.airlift.airline.Option; - -@Command(name = "add-certificate", description = "Add a certificate to an Azure application gateway") +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +@Command(name = "add-certificate", + header = "Add a certificate to an Azure application gateway.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class AddApplicationGatewayCertificateCommand extends AbstractApplicationGatewayCommand { - @Arguments(description = "The command requires two arguments. : the application gateway resource name used in the config to which the certificate would be added. : name of the certificate to be added. : the path to the certificate file (.pfx)", required = true) + @Parameters(description = "The command requires two arguments. : the application gateway resource name used in the config to which the certificate would be added. : name of the certificate to be added. : the path to the certificate file (.pfx)", arity = "3") private List arguments; - @Option(name = { "--password" }, description = "Password used to encrypt the certificate file") + @Option(names = "--password", description = "Password used to encrypt the certificate file.", arity = "0..1", interactive = true) private String password; @Override @@ -37,7 +42,8 @@ public void execute() throws Exception { GyroCore.ui().write("\nCertificate added."); } else { - throw new GyroException("'add-certificate' needs exactly three arguments, "); + throw new GyroException( + "'add-certificate' needs exactly three arguments, "); } } } diff --git a/src/main/java/gyro/azure/network/AzureApplicationGatewayCommand.java b/src/main/java/gyro/azure/network/AzureApplicationGatewayCommand.java new file mode 100644 index 00000000..9d9e054e --- /dev/null +++ b/src/main/java/gyro/azure/network/AzureApplicationGatewayCommand.java @@ -0,0 +1,17 @@ +package gyro.azure.network; + +import gyro.core.command.GyroCommandGroup; +import picocli.CommandLine; + +@CommandLine.Command(name = "application-gateway", + description = "Manage azure application gateway certificate.", + subcommands = { + AddApplicationGatewayCertificateCommand.class, + ImportApplicationGatewayCertificateCommand.class, + ListApplicationGatewayCertificateCommand.class, + RemoveApplicationGatewayCertificateCommand.class + } +) +public class AzureApplicationGatewayCommand implements GyroCommandGroup { + +} diff --git a/src/main/java/gyro/azure/network/ImportApplicationGatewayCertificateCommand.java b/src/main/java/gyro/azure/network/ImportApplicationGatewayCertificateCommand.java index 4bf87219..e7bc23ea 100644 --- a/src/main/java/gyro/azure/network/ImportApplicationGatewayCertificateCommand.java +++ b/src/main/java/gyro/azure/network/ImportApplicationGatewayCertificateCommand.java @@ -8,13 +8,18 @@ import gyro.azure.keyvault.AbstractVaultCommand; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; - -@Command(name = "import-certificate", description = "Import a certificate from an Azure vault to an application gateway") +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; + +@Command(name = "import-certificate", + header = "Import a certificate from an Azure vault to an application gateway.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class ImportApplicationGatewayCertificateCommand extends AbstractApplicationGatewayCommand { - @Arguments(description = "The command requires four arguments. : the application gateway resource name used in the config to which the certificate would be imported to. : name of the certificate to be created on the application gateway. : the key-vault resource name used in the config from which to import the certificate from. : name of the certificate in the vault to be imported.", required = true) + @Parameters(description = "The command requires four arguments. : the application gateway resource name used in the config to which the certificate would be imported to. : name of the certificate to be created on the application gateway. : the key-vault resource name used in the config from which to import the certificate from. : name of the certificate in the vault to be imported.", arity = "1") private List arguments; @Override diff --git a/src/main/java/gyro/azure/network/ListApplicationGatewayCertificateCommand.java b/src/main/java/gyro/azure/network/ListApplicationGatewayCertificateCommand.java index b1ba57d9..4d56ecd0 100644 --- a/src/main/java/gyro/azure/network/ListApplicationGatewayCertificateCommand.java +++ b/src/main/java/gyro/azure/network/ListApplicationGatewayCertificateCommand.java @@ -23,20 +23,25 @@ import com.microsoft.azure.management.network.ApplicationGatewaySslCertificate; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; -import io.airlift.airline.Option; - -@Command(name = "list-certificate", description = "List all certificates present in an Azure application gateway") +import picocli.CommandLine.Command; +import picocli.CommandLine.Option; +import picocli.CommandLine.Parameters; + +@Command(name = "list-certificate", + header = "List all certificates present in an Azure application gateway.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class ListApplicationGatewayCertificateCommand extends AbstractApplicationGatewayCommand { - @Arguments(description = "The command requires one argument. : the application gateway resource name used in the config whose certificates would be listed", required = true) + @Parameters(description = "The command requires one argument. : the application gateway resource name used in the config whose certificates would be listed.", arity = "1") private List arguments; - @Option(name = "--show-data", description = "Show data of the certificate") + @Option(names = "--show-data", description = "Show data of the certificate.") private boolean showData; - @Option(name = "--show-secret-id", description = "Show secret id of the certificate") + @Option(names = "--show-secret-id", description = "Show secret id of the certificate.") private boolean showSecretId; @Override @@ -50,7 +55,7 @@ public void execute() throws Exception { .values()); if (!sslCertificates.isEmpty()) { - for (ApplicationGatewaySslCertificate certificate: sslCertificates) { + for (ApplicationGatewaySslCertificate certificate : sslCertificates) { StringBuilder sb = new StringBuilder(); sb.append("\n***********************"); sb.append(String.format("\nName: %s", certificate.name())); diff --git a/src/main/java/gyro/azure/network/RemoveApplicationGatewayCertificateCommand.java b/src/main/java/gyro/azure/network/RemoveApplicationGatewayCertificateCommand.java index 212e2567..8e88f791 100644 --- a/src/main/java/gyro/azure/network/RemoveApplicationGatewayCertificateCommand.java +++ b/src/main/java/gyro/azure/network/RemoveApplicationGatewayCertificateCommand.java @@ -6,13 +6,18 @@ import com.microsoft.azure.management.network.ApplicationGatewayListener; import gyro.core.GyroCore; import gyro.core.GyroException; -import io.airlift.airline.Arguments; -import io.airlift.airline.Command; - -@Command(name = "remove-certificate", description = "Remove a certificate from an Azure application gateway") +import picocli.CommandLine.Command; +import picocli.CommandLine.Parameters; + +@Command(name = "remove-certificate", + header = "Remove a certificate from an Azure application gateway.", + synopsisHeading = "%n", + parameterListHeading = "%nParameters:%n", + optionListHeading = "%nOptions:%n", + usageHelpWidth = 100) public class RemoveApplicationGatewayCertificateCommand extends AbstractApplicationGatewayCommand { - @Arguments(description = "The command requires two arguments. : the application gateway resource name used in the config from which the certificate would be removed. : name of the certificate to be removed.", required = true) + @Parameters(description = "The command requires two arguments. : the application gateway resource name used in the config from which the certificate would be removed. : name of the certificate to be removed.", arity = "1") private List arguments; @Override @@ -34,12 +39,15 @@ public void execute() throws Exception { applicationGateway.update().withoutSslCertificate(certificateName).apply(); GyroCore.ui().write("\nCertificate removed."); } else { - throw new GyroException(String.format("Certificate '%s' cannot be removed as it is being used by listener '%s'.", certificateName, listener.name())); + throw new GyroException(String.format( + "Certificate '%s' cannot be removed as it is being used by listener '%s'.", + certificateName, + listener.name())); } - } else { - throw new GyroException("'remove-certificate' needs exactly two arguments, and "); + throw new GyroException( + "'remove-certificate' needs exactly two arguments, and "); } } } diff --git a/src/main/java/gyro/azure/package-info.java b/src/main/java/gyro/azure/package-info.java index 920ad918..32e14e02 100644 --- a/src/main/java/gyro/azure/package-info.java +++ b/src/main/java/gyro/azure/package-info.java @@ -29,7 +29,7 @@ * .. code:: shell * * {@literal @}repository: 'https://artifactory.psdops.com/gyro-releases' - * {@literal @}plugin: 'gyro:gyro-azure-provider:0.99.1' + * {@literal @}plugin: 'gyro:gyro-azure-provider:0.99.2' * * This lets Gyro load the Azure provider plugin and lets you start managing Azure resources using Gyro. *