Search in sources :

Example 11 with AzureDockerException

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());
    }
}
Also used : AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) FileWriter(java.io.FileWriter) AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) CloudException(com.microsoft.azure.CloudException)

Example 12 with AzureDockerException

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());
    }
}
Also used : AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) AzureDockerCertVault(com.microsoft.azure.docker.model.AzureDockerCertVault) AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) CloudException(com.microsoft.azure.CloudException)

Example 13 with AzureDockerException

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());
    }
}
Also used : KeyPair(com.jcraft.jsch.KeyPair) AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) AzureDockerCertVault(com.microsoft.azure.docker.model.AzureDockerCertVault) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JSch(com.jcraft.jsch.JSch) AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) CloudException(com.microsoft.azure.CloudException)

Example 14 with AzureDockerException

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);
    }
}
Also used : AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException)

Example 15 with AzureDockerException

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);
    }
}
Also used : AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException) AzureDockerException(com.microsoft.azure.docker.model.AzureDockerException)

Aggregations

AzureDockerException (com.microsoft.azure.docker.model.AzureDockerException)16 CloudException (com.microsoft.azure.CloudException)9 AzureDockerCertVault (com.microsoft.azure.docker.model.AzureDockerCertVault)8 Vault (com.microsoft.azure.management.keyvault.Vault)3 FileWriter (java.io.FileWriter)3 JSch (com.jcraft.jsch.JSch)2 KeyPair (com.jcraft.jsch.KeyPair)2 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AzureDockerUtils (com.microsoft.azure.docker.ops.utils.AzureDockerUtils)1 DEBUG (com.microsoft.azure.docker.ops.utils.AzureDockerUtils.DEBUG)1 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)1 SecretBundle (com.microsoft.azure.keyvault.models.SecretBundle)1 SetSecretRequest (com.microsoft.azure.keyvault.requests.SetSecretRequest)1 Azure (com.microsoft.azure.management.Azure)1 SecretPermissions (com.microsoft.azure.management.keyvault.SecretPermissions)1 Pair (com.microsoft.azuretools.utils.Pair)1 ServiceCallback (com.microsoft.rest.ServiceCallback)1