use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method getSSHKeysFromLocalFile.
public static AzureDockerCertVault getSSHKeysFromLocalFile(String localPath) throws AzureDockerException {
AzureDockerCertVault certVault = new AzureDockerCertVault();
try {
certVault.sshKey = new String(Files.readAllBytes(Paths.get(localPath, "id_rsa")));
certVault.sshPubKey = new String(Files.readAllBytes(Paths.get(localPath, "id_rsa.pub")));
} catch (Exception e) {
throw new AzureDockerException(e.getMessage());
}
return certVault;
}
use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method getVault.
public static AzureDockerCertVault getVault(AzureDockerCertVault certVault, KeyVaultClient keyVaultClient) throws AzureDockerException {
if (certVault == null || keyVaultClient == null || certVault.uri == null) {
throw new AzureDockerException("Unexpected argument values; azureClient, vault name and resourceGroupName cannot be null");
}
String vaultUri = certVault.uri;
try {
SecretBundle secret = keyVaultClient.getSecret(vaultUri, SECRETENTRY_DOCKERHOSTNAMES);
if (secret != null) {
certVault.hostName = secret.value();
} else {
certVault.hostName = null;
return null;
}
} catch (Exception e) {
return null;
}
//Execute Key Vault Secret read in parallel
Map<String, String> secretNamesAndValueMap = new HashMap<>();
Observable.from(DOCKERHOST_SECRETS).flatMap(secretName -> {
return Observable.create(new Observable.OnSubscribe<Pair<String, String>>() {
@Override
public void call(Subscriber<? super Pair<String, String>> subscriber) {
keyVaultClient.getSecretAsync(vaultUri, secretName, new ServiceCallback<SecretBundle>() {
@Override
public void failure(Throwable throwable) {
subscriber.onCompleted();
}
@Override
public void success(SecretBundle secretBundle) {
if (secretBundle != null) {
subscriber.onNext(new Pair<>(secretName, secretBundle.value()));
}
subscriber.onCompleted();
}
});
}
}).subscribeOn(Schedulers.io());
}, 5).subscribeOn(Schedulers.io()).toBlocking().subscribe(new Action1<Pair<String, String>>() {
@Override
public void call(Pair<String, String> secretNameAndValue) {
secretNamesAndValueMap.put(secretNameAndValue.first(), secretNameAndValue.second());
}
});
String currentSecretValue;
currentSecretValue = secretNamesAndValueMap.get("vmUsername");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.vmUsername = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("vmPwd");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.vmPwd = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("sshKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.sshKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("sshPubKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.sshPubKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsCACert");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsCACert = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsCAKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsCAKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsClientCert");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsClientCert = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsClientKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsClientKey = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsServerCert");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsServerCert = currentSecretValue;
}
currentSecretValue = secretNamesAndValueMap.get("tlsServerKey");
if (currentSecretValue != null && !currentSecretValue.isEmpty()) {
certVault.tlsServerKey = currentSecretValue;
}
return certVault;
}
use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method getVault.
public static AzureDockerCertVault getVault(Azure azureClient, AzureDockerCertVault certVault, KeyVaultClient keyVaultClient) throws AzureDockerException {
if (azureClient == null || certVault == null || keyVaultClient == null || certVault.name == null || certVault.resourceGroupName == null) {
throw new AzureDockerException("Unexpected argument values; azureClient, vault name and resourceGroupName cannot be null");
}
Vault vault;
try {
vault = azureClient.vaults().getByResourceGroup(certVault.resourceGroupName, certVault.name);
certVault.uri = vault.vaultUri();
} catch (Exception e) {
throw new AzureDockerException(e.getMessage());
}
return getVault(certVault, keyVaultClient);
}
use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method getVault.
public static AzureDockerCertVault getVault(Azure azureClient, String name, String resourceGroupName, KeyVaultClient keyVaultClient) throws AzureDockerException {
if (azureClient == null || keyVaultClient == null || name == null || resourceGroupName == null) {
throw new AzureDockerException("Unexpected argument values; azureClient, vault name and resourceGroupName cannot be null");
}
AzureDockerCertVault tempVault = new AzureDockerCertVault();
tempVault.name = name;
tempVault.resourceGroupName = resourceGroupName;
return getVault(azureClient, tempVault, keyVaultClient);
}
use of com.microsoft.azure.docker.model.AzureDockerException in project azure-tools-for-java by Microsoft.
the class AzureDockerCertVaultOps method saveTlsCertsToLocalFiles.
public static void saveTlsCertsToLocalFiles(String localPath, AzureDockerCertVault certVault) throws AzureDockerException {
try {
String sep = AzureDockerUtils.getPathSeparator();
if (certVault.tlsCACert != null) {
FileWriter file = new FileWriter(localPath + sep + "ca.pem");
file.write(certVault.tlsCACert);
file.close();
}
if (certVault.tlsCAKey != null) {
FileWriter file = new FileWriter(localPath + sep + "ca-key.pem");
file.write(certVault.tlsCACert);
file.close();
}
if (certVault.tlsClientCert != null) {
FileWriter file = new FileWriter(localPath + sep + "cert.pem");
file.write(certVault.tlsClientCert);
file.close();
}
if (certVault.tlsClientKey != null) {
FileWriter file = new FileWriter(localPath + sep + "key.pem");
file.write(certVault.tlsClientKey);
file.close();
}
if (certVault.tlsServerCert != null) {
FileWriter file = new FileWriter(localPath + sep + "server.pem");
file.write(certVault.tlsServerCert);
file.close();
}
if (certVault.tlsServerKey != null) {
FileWriter file = new FileWriter(localPath + sep + "server-key.pem");
file.write(certVault.tlsServerKey);
file.close();
}
} catch (Exception e) {
throw new AzureDockerException(e.getMessage());
}
}
Aggregations