use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method saveSshKeysToLocalFiles.
public static void saveSshKeysToLocalFiles(String localPath, AzureDockerCertVault certVault) throws AzureDockerException {
try {
String sep = AzureDockerUtils.getPathSeparator();
if (certVault.sshKey != null) {
FileWriter file = new FileWriter(localPath + sep + "id_rsa");
file.write(certVault.sshKey);
file.close();
}
if (certVault.sshPubKey != null) {
FileWriter file = new FileWriter(localPath + sep + "id_rsa.pub");
file.write(certVault.sshPubKey);
file.close();
}
} catch (Exception e) {
throw new AzureDockerException(e.getMessage());
}
}
use of com.microsoft.azure.docker.model.AzureDockerException 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.AzureDockerException 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());
}
}
use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerSSHOps method upload.
public static void upload(Session session, InputStream from, String fileName, String toPath, boolean isUserHomeBased, String filePerm) {
try {
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
String absolutePath = isUserHomeBased ? channel.getHome() + "/" + toPath : toPath;
String path = "";
for (String dir : absolutePath.split("/")) {
path = path + "/" + dir;
try {
channel.mkdir(path);
} catch (Exception ee) {
}
}
channel.cd(absolutePath);
channel.put(from, fileName);
if (filePerm != null) {
channel.chmod(Integer.parseInt(filePerm), absolutePath + "/" + fileName);
}
channel.disconnect();
} catch (Exception e) {
throw new AzureDockerException(e.getMessage(), e);
}
}
use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerSSHOps method download.
public static String download(Session session, String fileName, String fromPath, boolean isUserHomeBased) {
try {
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
BufferedOutputStream buff = new BufferedOutputStream(outputStream);
String absolutePath = isUserHomeBased ? channel.getHome() + "/" + fromPath : fromPath;
channel.cd(absolutePath);
channel.get(fileName, buff);
channel.disconnect();
return outputStream.toString();
} catch (Exception e) {
throw new AzureDockerException(e.getMessage(), e);
}
}
Aggregations