org.apache.gobblin.crypto.JCEKSKeystoreCredentialStoreCli Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gobblin-crypto-provider Show documentation
Show all versions of gobblin-crypto-provider Show documentation
A distributed data integration framework for streaming and batch data ecosystems.
The newest version!
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.gobblin.crypto;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.security.KeyStoreException;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import javax.xml.bind.DatatypeConverter;
import lombok.extern.slf4j.Slf4j;
import org.apache.gobblin.annotation.Alias;
import org.apache.gobblin.runtime.cli.CliApplication;
@Alias(value = "keystore", description = "Examine JCE Keystore files")
@Slf4j
public class JCEKSKeystoreCredentialStoreCli implements CliApplication {
private static final Map actionMap = ImmutableMap
.of("generate_keys", new GenerateKeyAction(), "list_keys", new ListKeysAction(), "help", new HelpAction(),
"export", new ExportKeyAction());
@Override
public void run(String[] args) {
if (args.length < 2) {
System.out.println("Must specify an action!");
new HelpAction().run(args);
return;
}
String actionStr = args[1];
Action action = actionMap.get(actionStr);
if (action == null) {
System.out.println("Action " + actionStr + " unknown!");
new HelpAction().run(args);
return;
}
action.run(Arrays.copyOfRange(args, 1, args.length));
}
public static JCEKSKeystoreCredentialStore loadKeystore(String path)
throws IOException {
char[] password = getPasswordFromConsole();
return new JCEKSKeystoreCredentialStore(path, String.valueOf(password));
}
/**
* Abstract class for any action of this tool
*/
static abstract class Action {
/**
* Return any additional Options for this action. The framework will always add a 'help' option.
*/
protected abstract List © 2015 - 2025 Weber Informatics LLC | Privacy Policy