generateSshKeyFile method
Future<({File privateKey, File publicKey})>
generateSshKeyFile(
- ProcessUtils processRunner,
- Directory snappCliDir
Generates a ssh key file in the snapp_cli directory
Implementation
Future<({File privateKey, File publicKey})> generateSshKeyFile(
ProcessUtils processRunner,
Directory snappCliDir,
) async {
logger.detail('try to generate ssh key file');
// generate random 6 digit file name
final randomNumber = Random().nextInt(900000) + 100000;
final keyFile = File('${snappCliDir.path}/id_rsa_$randomNumber');
final RunResult? result = await processRunner.runCommand(
hostPlatform.generateSshKeyCommand(filePath: keyFile.path),
parseResult: (result) => result,
parseFail: (e, s) {
throwToolExit(
'Something went wrong while generating the ssh key. \nException: $e \nStack: $s');
},
label: 'generateSshKeyCommand',
logger: logger,
);
if (result?.exitCode != 0) {
logger.detail('generateSshKeyCommand exitCode: ${result?.exitCode}');
logger.detail('generateSshKeyCommand stdout: ${result?.stdout}');
logger.detail('generateSshKeyCommand stderr: ${result?.stderr}');
throwToolExit('Something went wrong while generating the ssh key.');
}
return (privateKey: keyFile, publicKey: File('${keyFile.path}.pub'));
}