jclouds-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ignasi Barrera <notificati...@github.com>
Subject Re: [jclouds] fix jclouds live tests failing when a keypair is missing (#667)
Date Thu, 05 Feb 2015 09:26:45 GMT
> @@ -62,7 +64,18 @@
>     public static void checkSecretKeyFile(String secretKeyFile) {
>        checkNotNull(emptyToNull(secretKeyFile), "System property: [test.ssh.keyfile]
set to an empty string");
>        if (!new File(secretKeyFile).exists()) {
> -         throw new IllegalStateException("secretKeyFile not found at: " + secretKeyFile);
> +         // Create file if missing
> +         try {
> +            JSch jsch = new JSch();
> +            KeyPair kPair = KeyPair.genKeyPair(jsch, KeyPair.RSA, 4096);
> +            kPair.writePrivateKey(secretKeyFile);
> +            kPair.writePublicKey(secretKeyFile + ".pub", "jclouds generated key pair");
> +            kPair.dispose();

You should be able to do the same without adding a new dependency:
```java
Map<String, String> keypair = SshKeys.generate();
Files.write(keypair.get("private"), new File(secretkeyFile), Charsets.UTF_8);
Files.write(keypair.get("public"), new File(secretkeyFile + ".pub"), Charsets.UTF_8);
```

But given that this method just assigns the `Map<String, String>` variable, parhaps
you don't even need to persist it to disk. Could you test if it works if you just return the
result of the `SshKeys.generate()` call? If not, we can persist the generated keys, but it
would be better if we can avoid doing that.

---
Reply to this email directly or view it on GitHub:
https://github.com/jclouds/jclouds/pull/667/files#r24151401
Mime
View raw message