diff options
| author | zeapo <mohamed@zenadi.com> | 2014-12-17 23:33:30 +0100 |
|---|---|---|
| committer | zeapo <mohamed@zenadi.com> | 2015-01-04 14:53:58 +0100 |
| commit | 7b1204373dc44d16e4e443067825eb946905857a (patch) | |
| tree | acd1f6a2d907e561b19c75d1e833dae23ea82337 /app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java | |
| parent | d29f308848d4ad5ae277e3d8c032fab0a0ee7401 (diff) | |
| download | HardenedPass-7b1204373dc44d16e4e443067825eb946905857a.tar.gz HardenedPass-7b1204373dc44d16e4e443067825eb946905857a.zip | |
add support for pull and push operations
Diffstat (limited to 'app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java')
| -rw-r--r-- | app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java index e8659229..65436969 100644 --- a/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java +++ b/app/src/main/java/com/zeapo/pwdstore/git/GitOperation.java @@ -36,7 +36,8 @@ public abstract class GitOperation { /** * Creates a new git operation - * @param fileDir the git working tree directory + * + * @param fileDir the git working tree directory * @param callingActivity the calling activity */ public GitOperation(File fileDir, Activity callingActivity) { @@ -46,20 +47,22 @@ public abstract class GitOperation { /** * Sets the authentication using user/pwd scheme + * * @param username the username * @param password the password * @return the current object */ public GitOperation setAuthentication(String username, String password) { SshSessionFactory.setInstance(new GitConfigSessionFactory()); - this.provider = new UsernamePasswordCredentialsProvider(username,password); + this.provider = new UsernamePasswordCredentialsProvider(username, password); return this; } /** * Sets the authentication using ssh-key scheme - * @param sshKey the ssh-key file - * @param username the username + * + * @param sshKey the ssh-key file + * @param username the username * @param passphrase the passphrase * @return the current object */ @@ -72,13 +75,21 @@ public abstract class GitOperation { /** * Executes the GitCommand in an async task + * * @throws Exception */ public void execute() throws Exception { - Log.d(TAG, command + " << "); - new GitAsyncTask(callingActivity, true, false, CloneCommand.class).execute(command); + new GitAsyncTask(callingActivity, true, false, GitCommand.class).execute(command); } + /** + * Executes the GitCommand in an async task after creating the authentication + * + * @param connectionMode the server-connection mode + * @param username the username + * @param sshKey the ssh-key file + * @throws Exception + */ public void executeAfterAuthentication(String connectionMode, final String username, @Nullable final File sshKey) throws Exception { if (connectionMode.equalsIgnoreCase("ssh-key")) { if (sshKey == null || !sshKey.exists()) { @@ -89,6 +100,8 @@ public abstract class GitOperation { @Override public void onClick(DialogInterface dialog, int id) { try { + // Ask the UserPreference to provide us with the ssh-key + // onResult has to be handled by the callingActivity Intent intent = new Intent(callingActivity.getApplicationContext(), UserPreference.class); intent.putExtra("operation", "get_ssh_key"); callingActivity.startActivityForResult(intent, GET_SSH_KEY_FROM_CLONE); @@ -115,11 +128,10 @@ public abstract class GitOperation { .setView(passphrase) .setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - - SshSessionFactory.setInstance(new GitConfigSessionFactory()); try { + // Authenticate using the ssh-key and then execute the command setAuthentication(sshKey, username, passphrase.getText().toString()).execute(); - } catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } @@ -142,11 +154,10 @@ public abstract class GitOperation { .setView(password) .setPositiveButton(callingActivity.getResources().getString(R.string.dialog_ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { - - setAuthentication(username, password.getText().toString()); + // authenticate using the user/pwd and then execute the command try { - execute(); - } catch (Exception e){ + setAuthentication(username, password.getText().toString()).execute(); + } catch (Exception e) { e.printStackTrace(); } |
