use of com.microsoft.azure.docker.model.AzureDockerCertVault in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method createDockerKeyVault.
public static void createDockerKeyVault(DockerHost dockerHost, AzureDockerHostsManager dockerManager) {
Job createDockerHostJob = new Job(String.format("Creating Azure Key Vault %s for %s", dockerHost.certVault.name, dockerHost.name)) {
@Override
protected IStatus run(IProgressMonitor progressMonitor) {
progressMonitor.beginTask("start task", 100);
try {
progressMonitor.subTask(String.format("Reading subscription details for Docker host %s ...", dockerHost.apiUrl));
progressMonitor.worked(5);
Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).azureClient;
KeyVaultClient keyVaultClient = dockerManager.getSubscriptionsMap().get(dockerHost.sid).keyVaultClient;
if (progressMonitor.isCanceled()) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
String retryMsg = "Create";
int retries = 5;
AzureDockerCertVault certVault = null;
do {
progressMonitor.subTask(String.format("%s new key vault %s ...", retryMsg, dockerHost.certVault.name));
progressMonitor.worked(15 + 15 * retries);
if (AzureDockerUtils.DEBUG)
System.out.println(retryMsg + " new Docker key vault: " + new Date().toString());
AzureDockerCertVaultOps.createOrUpdateVault(azureClient, dockerHost.certVault, keyVaultClient);
if (AzureDockerUtils.DEBUG)
System.out.println("Done creating new key vault: " + new Date().toString());
if (progressMonitor.isCanceled()) {
progressMonitor.done();
return Status.CANCEL_STATUS;
}
certVault = AzureDockerCertVaultOps.getVault(azureClient, dockerHost.certVault.name, dockerHost.certVault.resourceGroupName, keyVaultClient);
retries++;
retryMsg = "Retry creating";
} while (// Retry couple times
retries < 5 && (certVault == null || certVault.vmUsername == null));
progressMonitor.subTask("Updating key vaults ...");
progressMonitor.worked(95);
if (AzureDockerUtils.DEBUG)
System.out.println("Refreshing key vaults: " + new Date().toString());
dockerManager.refreshDockerVaults();
dockerManager.refreshDockerVaultDetails();
if (AzureDockerUtils.DEBUG)
System.out.println("Done refreshing key vaults: " + new Date().toString());
// progressMonitor.subTask("");
// progressMonitor.worked(1);
// if (progressMonitor.isCanceled()) {
// if (displayWarningOnCreateKeyVaultCancelAction() == 0) {
// progressMonitor.done();
// return Status.CANCEL_STATUS;
// }
// }
//
progressMonitor.done();
return Status.OK_STATUS;
} catch (Exception e) {
String msg = "An error occurred while attempting to create a new Azure Key Vault." + "\n" + e.getMessage();
log.log(Level.SEVERE, "createDockerKeyVault: " + msg, e);
e.printStackTrace();
PluginUtil.displayErrorDialog(Display.getDefault().getActiveShell(), "Error Creating Azure Key Vault " + dockerHost.certVault.name, "An error occurred while attempting to create a new Azure Key Vault." + "\n" + e.getMessage());
return Status.CANCEL_STATUS;
}
}
};
createDockerHostJob.schedule();
}
use of com.microsoft.azure.docker.model.AzureDockerCertVault in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method cloneVault.
public static void cloneVault(Azure azureClientSource, AzureDockerCertVault certVaultSource, Azure azureClientDest, AzureDockerCertVault certVaultDest, KeyVaultClient keyVaultClient) throws AzureDockerException {
if (azureClientSource == null || certVaultSource == null || certVaultSource.name == null || certVaultSource.resourceGroupName == null || azureClientDest == null || certVaultDest == null || certVaultDest.name == null || certVaultDest.resourceGroupName == null || certVaultDest.region == null || (certVaultDest.servicePrincipalId == null && certVaultDest.userId == null) || keyVaultClient == null) {
throw new AzureDockerException("Unexpected argument values; azureClient, vault name, hostName, resourceGroupName and destination region and userName/servicePrincipalId cannot be null");
}
try {
AzureDockerCertVault certVaultResult = getVault(azureClientSource, certVaultSource, keyVaultClient);
certVaultResult.name = certVaultDest.name;
certVaultResult.id = certVaultDest.id;
certVaultResult.resourceGroupName = certVaultDest.resourceGroupName;
certVaultResult.region = certVaultDest.region;
certVaultResult.userId = certVaultDest.userId;
certVaultResult.servicePrincipalId = certVaultDest.servicePrincipalId;
createOrUpdateVault(azureClientDest, certVaultResult, keyVaultClient);
} catch (Exception e) {
throw new AzureDockerException(e.getMessage());
}
}
use of com.microsoft.azure.docker.model.AzureDockerCertVault in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method generateSSHKeys.
public static AzureDockerCertVault generateSSHKeys(String passPhrase, String comment) throws AzureDockerException {
try {
AzureDockerCertVault result = new AzureDockerCertVault();
JSch jsch = new JSch();
KeyPair keyPair = KeyPair.genKeyPair(jsch, KeyPair.RSA);
ByteArrayOutputStream privateKeyBuff = new ByteArrayOutputStream(2048);
ByteArrayOutputStream publicKeyBuff = new ByteArrayOutputStream(2048);
keyPair.writePublicKey(publicKeyBuff, (comment != null) ? comment : "DockerSSHCerts");
if (passPhrase == null || passPhrase.isEmpty()) {
keyPair.writePrivateKey(privateKeyBuff);
} else {
keyPair.writePrivateKey(privateKeyBuff, passPhrase.getBytes());
}
result.sshKey = privateKeyBuff.toString();
result.sshPubKey = publicKeyBuff.toString();
return result;
} catch (Exception e) {
throw new AzureDockerException(e.getMessage());
}
}
Aggregations