use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class CloneModelAction method run.
@Override
public void run() {
// Check primary key set
try {
if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
return;
}
} catch (GeneralSecurityException ex) {
displayCredentialsErrorDialog(ex);
return;
} catch (Exception ex) {
displayErrorDialog(Messages.CloneModelAction_0, ex);
return;
}
CloneInputDialog dialog = new CloneInputDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final boolean storeCredentials = dialog.doStoreCredentials();
final UsernamePassword npw = dialog.getUsernamePassword();
if (!StringUtils.isSet(repoURL)) {
return;
}
if (GraficoUtils.isHTTP(repoURL) && !StringUtils.isSet(npw.getUsername()) && npw.getPassword().length == 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CloneModelAction_0, Messages.CloneModelAction_1);
return;
}
// Create a new local folder
File localRepoFolder = GraficoUtils.getUniqueLocalFolder(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), repoURL);
setRepository(new ArchiRepository(localRepoFolder));
try {
// Clone
Exception[] exception = new Exception[1];
IProgressService ps = PlatformUI.getWorkbench().getProgressService();
ps.busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor pm) {
try {
// Update Proxy
ProxyAuthenticator.update();
pm.beginTask(Messages.CloneModelAction_4, -1);
getRepository().cloneModel(repoURL, npw, new ProgressMonitorWrapper(pm));
} catch (Exception ex) {
exception[0] = ex;
} finally {
// Clear Proxy
ProxyAuthenticator.clear();
}
}
});
if (exception[0] != null) {
throw exception[0];
}
// Load it from the Grafico files if we can
IArchimateModel graficoModel = new GraficoModelLoader(getRepository()).loadModel();
// We couldn't load it from Grafico so create a new blank model
if (graficoModel == null) {
// New one. This will open in the tree
IArchimateModel model = IEditorModelManager.INSTANCE.createNewModel();
model.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(model);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
// And do a first commit
getRepository().commitChanges(Messages.CloneModelAction_3, false);
// Save the checksum
getRepository().saveChecksum();
}
// Store repo credentials if HTTP and option is set
if (GraficoUtils.isHTTP(repoURL) && storeCredentials) {
EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
cs.store(npw);
}
// Notify listeners
notifyChangeListeners(IRepositoryListener.REPOSITORY_ADDED);
} catch (Exception ex) {
displayErrorDialog(Messages.CloneModelAction_0, ex);
}
}
use of org.archicontribs.modelrepository.authentication.EncryptedCredentialsStorage in project archi-modelrepository-plugin by archi-contribs.
the class CreateRepoFromModelAction method run.
@Override
public void run() {
try {
if (!EncryptedCredentialsStorage.checkPrimaryKeySet()) {
return;
}
} catch (GeneralSecurityException ex) {
displayCredentialsErrorDialog(ex);
return;
} catch (IOException ex) {
displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
return;
}
NewModelRepoDialog dialog = new NewModelRepoDialog(fWindow.getShell());
if (dialog.open() != Window.OK) {
return;
}
final String repoURL = dialog.getURL();
final boolean storeCredentials = dialog.doStoreCredentials();
final UsernamePassword npw = dialog.getUsernamePassword();
if (!StringUtils.isSet(repoURL)) {
return;
}
if (GraficoUtils.isHTTP(repoURL) && !StringUtils.isSet(npw.getUsername()) && npw.getPassword().length == 0) {
MessageDialog.openError(fWindow.getShell(), Messages.CreateRepoFromModelAction_0, Messages.CreateRepoFromModelAction_3);
return;
}
// Create a new local folder
File localRepoFolder = GraficoUtils.getUniqueLocalFolder(ModelRepositoryPlugin.INSTANCE.getUserModelRepositoryFolder(), repoURL);
setRepository(new ArchiRepository(localRepoFolder));
try {
// Create a new repo
try (Git git = getRepository().createNewLocalGitRepository(repoURL)) {
}
// TODO: If the model has not been saved yet this is fine but if the model already exists
// We should tell the user this is the case
// Set new file location
fModel.setFile(getRepository().getTempModelFile());
// And Save it
IEditorModelManager.INSTANCE.saveModel(fModel);
// Export to Grafico
getRepository().exportModelToGraficoFiles();
// Commit changes
getRepository().commitChanges(Messages.CreateRepoFromModelAction_5, false);
// Push
Exception[] exception = new Exception[1];
IProgressService ps = PlatformUI.getWorkbench().getProgressService();
ps.busyCursorWhile(new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor pm) {
try {
// Update Proxy
ProxyAuthenticator.update();
pm.beginTask(Messages.CreateRepoFromModelAction_4, -1);
getRepository().pushToRemote(npw, new ProgressMonitorWrapper(pm));
} catch (Exception ex) {
exception[0] = ex;
} finally {
// Clear Proxy
ProxyAuthenticator.clear();
}
}
});
if (exception[0] != null) {
throw exception[0];
}
// Store repo credentials if HTTP and option is set
if (GraficoUtils.isHTTP(repoURL) && storeCredentials) {
EncryptedCredentialsStorage cs = EncryptedCredentialsStorage.forRepository(getRepository());
cs.store(npw);
}
// Save the checksum
getRepository().saveChecksum();
} catch (Exception ex) {
displayErrorDialog(Messages.CreateRepoFromModelAction_7, ex);
}
}
Aggregations