in gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java [242:596]
private int init(String[] args) throws IOException {
if (args.length == 0) {
printKnoxShellUsage();
return -1;
}
for (int i = 0; i < args.length; i++) { // parse command line
if (args[i].equals("create-master")) {
command = new MasterCreateCommand();
if ((args.length > i + 1) && args[i + 1].equals("--help")) {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("delete-alias")) {
String alias = null;
if (args.length >= 2) {
alias = args[++i];
}
command = new AliasDeleteCommand(alias);
if (alias == null || "--help".equals(alias)) {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("create-alias")) {
String alias = null;
if (args.length >= 2) {
alias = args[++i];
}
command = new AliasCreateCommand(alias);
if (alias == null || "--help".equals(alias)) {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("create-aliases")) {
command = new BatchAliasCreateCommand();
if (args.length < 3 || "--help".equals(alias)) {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("create-list-aliases")) {
command = new CreateListAliasesCommand();
if (args.length < 3 || "--help".equals(alias)) {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("create-cert")) {
command = new CertCreateCommand();
if ((args.length > i + 1) && args[i + 1].equals("--help")) {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("export-cert")) {
command = new CertExportCommand();
if ((args.length > i + 1) && args[i + 1].equals("--help")) {
printKnoxShellUsage();
return -1;
}
}else if(args[i].equals("user-auth-test")) {
if(i + 1 >= args.length) {
printKnoxShellUsage();
return -1;
} else {
command = new LDAPAuthCommand();
}
} else if(args[i].equals("system-user-auth-test")) {
if (i + 1 >= args.length){
printKnoxShellUsage();
return -1;
} else {
command = new LDAPSysBindCommand();
}
} else if (args[i].equals("list-alias")) {
command = new AliasListCommand();
} else if (args[i].equals("--value")) {
if (i + 1 >= args.length
|| "--generate".equals(args[i + 1]) // missing value
|| "--cluster".equals(args[i + 1])
|| "--master".equals(args[i + 1])) {
printKnoxShellUsage();
return -1;
}
this.value = args[++i];
if (command instanceof MasterCreateCommand) {
this.master = this.value;
} else if (command instanceof BatchAliasCreateCommand) {
((BatchAliasCreateCommand) command).addValue(value);
}
} else if (args[i].equals("--alias")) {
if (command instanceof BatchAliasCreateCommand) {
((BatchAliasCreateCommand) command).addName(args[++i]);
} else {
printKnoxShellUsage();
return -1;
}
} else if ( args[i].equals("version") ) {
command = new VersionCommand();
} else if ( args[i].equals("redeploy") ) {
command = new RedeployCommand();
} else if ( args[i].equals("validate-topology") ) {
if(i + 1 >= args.length) {
printKnoxShellUsage();
return -1;
} else {
command = new ValidateTopologyCommand();
}
} else if( args[i].equals("list-topologies") ){
command = new ListTopologiesCommand();
} else if ( args[i].equals("--cluster") || args[i].equals("--topology") ) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.cluster = args[++i];
if(command instanceof CreateListAliasesCommand) {
((CreateListAliasesCommand) command).toMap(this.cluster);
}
} else if (args[i].equals("service-test")) {
if( i + 1 >= args.length) {
printKnoxShellUsage();
return -1;
} else {
command = new ServiceTestCommand();
}
} else if (args[i].equals("--generate")) {
if ( command instanceof MasterCreateCommand ) {
this.master = UUID.randomUUID().toString();
} else {
this.generate = "true";
}
} else if(args[i].equals("--type")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.type = args[++i];
} else if(args[i].equals("--path")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.path = args[++i];
}else if (args[i].equals("--hostname")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.hostname = args[++i];
} else if (args[i].equals("--port")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.port = args[++i];
} else if (args[i].equals("--provider-name")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.providerName = args[++i];
} else if (args[i].equals("--topology-name")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.topologyName = args[++i];
} else if (args[i].equals("--descriptor-name")) {
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
printKnoxShellUsage();
return -1;
}
this.descriptorName = args[++i];
} else if (args[i].equals("--service-name")) {
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
printKnoxShellUsage();
return -1;
}
this.serviceName = args[++i];
} else if (args[i].equals("--service-urls-file")) {
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
printKnoxShellUsage();
return -1;
}
this.urlsFilePath = args[++i];
} else if (args[i].equals("--output-dir")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.outputDir = args[++i];
} else if (args[i].equals("--discovery-url")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.discoveryUrl = args[++i];
} else if (args[i].equals("--discovery-user")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.discoveryUser = args[++i];
} else if (args[i].equals("--discovery-pwd-alias")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.discoveryPasswordAlias = args[++i];
} else if (args[i].equals("--discovery-type")) {
if( i+1 >= args.length || args[i+1].startsWith( "-" ) ) {
printKnoxShellUsage();
return -1;
}
this.discoveryType = args[++i];
} else if (args[i].equals("--master")) {
// For testing only
if( i+1 >= args.length
|| "--generate".equals(args[i + 1]) // missing value
|| "--force".equals(args[i + 1])) {
printKnoxShellUsage();
return -1;
}
this.master = args[++i];
} else if (args[i].equals("--force")) {
this.force = true;
} else if (args[i].equals("--help")) {
printKnoxShellUsage();
return -1;
} else if(args[i].equals("--d")) {
this.debug = true;
} else if(args[i].equals("--u")) {
if(i + 1 <= args.length) {
this.user = args[++i];
} else{
printKnoxShellUsage();
return -1;
}
} else if(args[i].equals("--p")) {
if(i + 1 <= args.length) {
this.pass = args[++i];
} else{
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("--g")) {
this.groups = true;
} else if (args[i].equals("list-registry-clients")) {
command = new RemoteRegistryClientsListCommand();
} else if (args[i].equals("--registry-client")) {
if (i + 1 >= args.length || args[i + 1].startsWith("-")) {
printKnoxShellUsage();
return -1;
}
this.remoteRegistryClient = args[++i];
} else if (args[i].equalsIgnoreCase("list-provider-configs")) {
command = new RemoteRegistryListProviderConfigsCommand();
} else if (args[i].equalsIgnoreCase("list-descriptors")) {
command = new RemoteRegistryListDescriptorsCommand();
} else if (args[i].equalsIgnoreCase("upload-provider-config")) {
String fileName;
if (i <= (args.length - 1)) {
fileName = args[++i];
command = new RemoteRegistryUploadProviderConfigCommand(fileName);
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("upload-descriptor")) {
String fileName;
if (i <= (args.length - 1)) {
fileName = args[++i];
command = new RemoteRegistryUploadDescriptorCommand(fileName);
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("--entry-name")) {
if (i <= (args.length - 1)) {
remoteRegistryEntryName = args[++i];
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("delete-descriptor")) {
if (i <= (args.length - 1)) {
String entry = args[++i];
command = new RemoteRegistryDeleteDescriptorCommand(entry);
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equals("delete-provider-config")) {
if (i <= (args.length - 1)) {
String entry = args[++i];
command = new RemoteRegistryDeleteProviderConfigCommand(entry);
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equalsIgnoreCase("get-registry-acl")) {
if (i <= (args.length - 1)) {
String entry = args[++i];
command = new RemoteRegistryGetACLCommand(entry);
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equalsIgnoreCase("convert-topology")) {
if (args.length >= 5) {
command = new TopologyConverter();
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equalsIgnoreCase("generate-descriptor")) {
if (args.length >= 7) {
command = new GenerateDescriptorCommand();
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equalsIgnoreCase("--param")) {
if (i + 2 < args.length) {
params.put(args[++i], args[++i]);
} else {
printKnoxShellUsage();
return -1;
}
} else if (args[i].equalsIgnoreCase("generate-jwk")) {
command = new JWKGenerator();
} else if (args[i].equalsIgnoreCase("--jwkAlg")) {
final String algName = args[++i];
if (!SUPPORTED_JWK_ALGORITHMS.contains(algName)) {
printKnoxShellUsage();
return -1;
} else {
jwsAlgorithm = JWSAlgorithm.parse(algName);
}
} else if (args[i].equalsIgnoreCase("--saveAlias")) {
alias = args[++i];
} else if (args[i].equalsIgnoreCase("migrate-tokens") ) {
command = new TokenMigration();
} else if (args[i].equalsIgnoreCase("--progressCount") ) {
progressCount = Integer.parseInt(args[++i]);
} else if (args[i].equalsIgnoreCase("--archiveMigrated") ) {
archiveMigratedTokens = Boolean.parseBoolean(args[++i]);
} else if (args[i].equalsIgnoreCase("--migrateExpiredTokens") ) {
migrateExpiredTokens = Boolean.parseBoolean(args[++i]);
} else if (args[i].equalsIgnoreCase("--verbose") ) {
verbose = Boolean.parseBoolean(args[++i]);
} else {
printKnoxShellUsage();
return -1;
}
}
return 0;
}