use of org.ovirt.engine.ssoreg.db.DBUtils in project ovirt-engine by oVirt.
the class SsoRegistrationToolExecutor method main.
public static void main(String... args) {
int exitStatus = 1;
List<String> cmdArgs = new ArrayList<>(Arrays.asList(args));
try {
final Map<String, String> contextSubstitutions = new HashMap<>();
contextSubstitutions.put("@ENGINE_ETC@", ENGINE_ETC);
contextSubstitutions.put("@PROGRAM_NAME@", PROGRAM_NAME);
setupLogger();
ArgumentsParser parser;
final Map<String, String> substitutions = new HashMap<>(contextSubstitutions);
try (InputStream stream = SsoRegistrationToolExecutor.class.getResourceAsStream("arguments.properties")) {
parser = new ArgumentsParser(stream, "core");
parser.getSubstitutions().putAll(substitutions);
}
parser.parse(cmdArgs);
Map<String, Object> argMap = parser.getParsedArgs();
setupLogger(argMap);
log.debug("Version: {}-{} ({})", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DISPLAY_NAME);
if ((Boolean) argMap.get("help")) {
System.out.format("Usage: %s", parser.getUsage());
throw new ExitException("Help", 0);
} else if ((Boolean) argMap.get("version")) {
System.out.format("%s-%s (%s)%n", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_DISPLAY_NAME);
throw new ExitException("Version", 0);
}
if (!parser.getErrors().isEmpty()) {
for (Throwable t : parser.getErrors()) {
log.error(t.getMessage());
log.debug(t.getMessage(), t);
}
throw new ExitException("Parsing error", 1);
}
DBUtils dbUtils = new DBUtils();
log.info("=========================================================================");
log.info("================== oVirt Sso Client Registration Tool ===================");
log.info("=========================================================================");
String clientId = getUserInput("Client Id: ");
String certificateFile = getUserInput("Client CA Certificate File Location: ");
while (!new File(certificateFile).exists()) {
System.out.format("%s is not a valid certificate, please enter path to an existing certificate.%n", certificateFile);
certificateFile = getUserInput("Enter Client CA Certificate File Location: ");
}
String callbackPrefix = getUserInput("Callback Prefix URL: ");
while (!callbackPrefix.startsWith("http") && !callbackPrefix.startsWith("https")) {
System.out.format("%s is not a valid URL, please enter a proper URL.%n", callbackPrefix);
callbackPrefix = getUserInput("Enter Callback Prefix URL: ");
}
String clientSecret = generateClientSecret();
String encodedClientSecret = encode(argMap, clientSecret);
dbUtils.unregisterClient(clientId);
dbUtils.registerClient(clientId, encodedClientSecret, certificateFile, callbackPrefix);
String tmpFile = createTmpSsoClientConfFile(clientId, clientSecret, certificateFile, callbackPrefix);
System.out.println("Client registration completed successfully");
System.out.format("Client secret has been written to file %s%n", tmpFile);
log.info("========================================================================");
log.info("========================= Execution Completed ==========================");
log.info("========================================================================");
exitStatus = 0;
} catch (ExitException e) {
log.debug(e.getMessage(), e);
exitStatus = e.getExitCode();
} catch (Throwable t) {
t.printStackTrace();
log.error(t.getMessage() != null ? t.getMessage() : t.getClass().getName());
log.debug("Exception:", t);
}
log.debug("Exiting with status '{}'", exitStatus);
System.exit(exitStatus);
}
Aggregations