mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
Fix sshkey custom comment
Custom comments had been implemented but were not working.
This commit is contained in:
@ -14,6 +14,7 @@ import org.apache.commons.io.FileUtils;
|
|||||||
import io.flutter.plugin.common.MethodChannel.Result;
|
import io.flutter.plugin.common.MethodChannel.Result;
|
||||||
|
|
||||||
public class GenerateSSHKeysTask extends AsyncTask<String, Void, Void> {
|
public class GenerateSSHKeysTask extends AsyncTask<String, Void, Void> {
|
||||||
|
private final static String TAG = "GenerateSSHKeys";
|
||||||
private Result result;
|
private Result result;
|
||||||
|
|
||||||
public GenerateSSHKeysTask(Result _result) {
|
public GenerateSSHKeysTask(Result _result) {
|
||||||
@ -28,13 +29,14 @@ public class GenerateSSHKeysTask extends AsyncTask<String, Void, Void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String comment = params[1];
|
String comment = params[1];
|
||||||
|
Log.d(TAG, "Comment: " + comment);
|
||||||
|
|
||||||
final String privateKeyPath = keysDir + "/id_rsa";
|
final String privateKeyPath = keysDir + "/id_rsa";
|
||||||
final String publicKeyPath = keysDir + "/id_rsa.pub";
|
final String publicKeyPath = keysDir + "/id_rsa.pub";
|
||||||
|
|
||||||
File privateKeyFile = new File(privateKeyPath);
|
File privateKeyFile = new File(privateKeyPath);
|
||||||
if (privateKeyFile.exists()) {
|
if (privateKeyFile.exists()) {
|
||||||
Log.d("GenerateSSHKeys", "Private key already exists");
|
Log.d(TAG, "Private key already exists");
|
||||||
result.error("FAILED", "Private key already exists", null);
|
result.error("FAILED", "Private key already exists", null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -48,11 +50,11 @@ public class GenerateSSHKeysTask extends AsyncTask<String, Void, Void> {
|
|||||||
kpair.writePublicKey(publicKeyPath, comment);
|
kpair.writePublicKey(publicKeyPath, comment);
|
||||||
kpair.dispose();
|
kpair.dispose();
|
||||||
} catch (JSchException ex) {
|
} catch (JSchException ex) {
|
||||||
Log.d("GenerateSSHKeys", ex.toString());
|
Log.d(TAG, ex.toString());
|
||||||
result.error("FAILED", ex.getMessage(), null);
|
result.error("FAILED", ex.getMessage(), null);
|
||||||
return null;
|
return null;
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Log.d("GenerateSSHKeys", ex.toString());
|
Log.d(TAG, ex.toString());
|
||||||
result.error("FAILED", ex.getMessage(), null);
|
result.error("FAILED", ex.getMessage(), null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -61,7 +63,7 @@ public class GenerateSSHKeysTask extends AsyncTask<String, Void, Void> {
|
|||||||
try {
|
try {
|
||||||
publicKey = FileUtils.readFileToString(new File(publicKeyPath), Charset.defaultCharset());
|
publicKey = FileUtils.readFileToString(new File(publicKeyPath), Charset.defaultCharset());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Log.d("GenerateSSHKeys", ex.toString());
|
Log.d(TAG, ex.toString());
|
||||||
result.error("FAILED", "Failed to read the public key", null);
|
result.error("FAILED", "Failed to read the public key", null);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -124,6 +124,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
} else if (call.method.equals("generateSSHKeys")) {
|
} else if (call.method.equals("generateSSHKeys")) {
|
||||||
String comment = call.argument("comment");
|
String comment = call.argument("comment");
|
||||||
if (comment == null || comment.isEmpty()) {
|
if (comment == null || comment.isEmpty()) {
|
||||||
|
Log.d("generateSSHKeys", "Defaulting to default comment");
|
||||||
comment = "Generated on Android";
|
comment = "Generated on Android";
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +137,7 @@ public class MainActivity extends FlutterActivity {
|
|||||||
try {
|
try {
|
||||||
publicKey = FileUtils.readFileToString(new File(publicKeyPath), Charset.defaultCharset());
|
publicKey = FileUtils.readFileToString(new File(publicKeyPath), Charset.defaultCharset());
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
Log.d("GenerateSSHKeys", ex.toString());
|
Log.d("getSSHPublicKey", ex.toString());
|
||||||
result.error("FAILED", "Failed to read the public key", null);
|
result.error("FAILED", "Failed to read the public key", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,9 @@ buildGitButtons() {
|
|||||||
return <Widget>[
|
return <Widget>[
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
child: Text("Generate Keys"),
|
child: Text("Generate Keys"),
|
||||||
onPressed: generateSSHKeys,
|
onPressed: () {
|
||||||
),
|
generateSSHKeys(comment: "Git Sample App");
|
||||||
|
}),
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
child: Text("Git Clone"),
|
child: Text("Git Clone"),
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
|
|
||||||
const _platform = const MethodChannel('gitjournal.io/git');
|
const _platform = const MethodChannel('gitjournal.io/git');
|
||||||
@ -29,11 +30,11 @@ Future<String> gitClone(String cloneUrl, String folderName) async {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<String> generateSSHKeys({comment: ""}) async {
|
Future<String> generateSSHKeys({@required String comment}) async {
|
||||||
print("generateSSHKeyss");
|
print("generateSSHKeyss: " + comment);
|
||||||
try {
|
try {
|
||||||
String publicKey = await _platform.invokeMethod('generateSSHKeys', {
|
String publicKey = await _platform.invokeMethod('generateSSHKeys', {
|
||||||
comment: comment,
|
'comment': comment,
|
||||||
});
|
});
|
||||||
print("Public Key " + publicKey);
|
print("Public Key " + publicKey);
|
||||||
return publicKey;
|
return publicKey;
|
||||||
|
Reference in New Issue
Block a user