public KeyPair addFingerprintToKeyPair(String publicKeyMaterial, KeyPair keyPair) { // add in the fingerprint as it makes correlating keys in ssh logs possible keyPair = keyPair.toBuilder().fingerprint(fingerprintPublicKey(publicKeyMaterial)).build(); return keyPair; }
public KeyPair addFingerprintToKeyPair(String publicKeyMaterial, KeyPair keyPair) { // add in the fingerprint as it makes correlating keys in ssh logs possible keyPair = keyPair.toBuilder().fingerprint(fingerprintPublicKey(publicKeyMaterial)).build(); return keyPair; }
public KeyPair addFingerprintToKeyPair(String publicKeyMaterial, KeyPair keyPair) { // add in the fingerprint as it makes correlating keys in ssh logs possible keyPair = keyPair.toBuilder().fingerprint(fingerprintPublicKey(publicKeyMaterial)).build(); return keyPair; }
@Override public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { RegionAndName key = new RegionAndName(region, group); KeyPair pair; if (and(hasPublicKeyMaterial, or(doesntNeedSshAfterImportingPublicKey, hasLoginCredential)).apply(options)) { pair = importExistingKeyPair.apply(new RegionNameAndPublicKeyMaterial(region, group, options.getPublicKey())); options.dontAuthorizePublicKey(); if (hasLoginCredential.apply(options)) pair = pair.toBuilder().keyMaterial(options.getLoginPrivateKey()).build(); credentialsMap.put(key, pair); } else { if (hasPublicKeyMaterial.apply(options)) { logger.warn("to avoid creating temporary keys in aws-ec2, use templateOption overrideLoginCredentialWith(id_rsa)"); } return super.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options); } return pair.getKeyName(); }
@Override public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { RegionAndName key = new RegionAndName(region, group); KeyPair pair; if (and(hasPublicKeyMaterial, or(doesntNeedSshAfterImportingPublicKey, hasLoginCredential)).apply(options)) { pair = importExistingKeyPair.apply(new RegionNameAndPublicKeyMaterial(region, group, options.getPublicKey())); options.dontAuthorizePublicKey(); if (hasLoginCredential.apply(options)) pair = pair.toBuilder().keyMaterial(options.getLoginPrivateKey()).build(); credentialsMap.put(key, pair); } else { if (hasPublicKeyMaterial.apply(options)) { logger.warn("to avoid creating temporary keys in aws-ec2, use templateOption overrideLoginCredentialWith(id_rsa)"); } return super.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options); } return pair.getKeyName(); }
@Override public String createNewKeyPairUnlessUserSpecifiedOtherwise(String region, String group, TemplateOptions options) { RegionAndName key = new RegionAndName(region, group); KeyPair pair; if (and(hasPublicKeyMaterial, or(doesntNeedSshAfterImportingPublicKey, hasLoginCredential)).apply(options)) { pair = importExistingKeyPair.apply(new RegionNameAndPublicKeyMaterial(region, group, options.getPublicKey())); options.dontAuthorizePublicKey(); if (hasLoginCredential.apply(options)) pair = pair.toBuilder().keyMaterial(options.getLoginPrivateKey()).build(); credentialsMap.put(key, pair); } else { if (hasPublicKeyMaterial.apply(options)) { logger.warn("to avoid creating temporary keys in aws-ec2, use templateOption overrideLoginCredentialWith(id_rsa)"); } return super.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options); } return pair.getKeyName(); }
@Test public void testCreateNewKeyPairUnlessUserSpecifiedOtherwise_importsKeyPairAndUnsetsTemplateInstructionWhenPublicKeySuppliedAndAddsCredentialToMapWhenOverridingCredsAreSet() { // setup constants String region = Region.AP_SOUTHEAST_1; String group = "group"; // create mocks CreateKeyPairPlacementAndSecurityGroupsAsNeededAndReturnRunOptions strategy = setupStrategy(); AWSEC2TemplateOptions options = keyPair(group).authorizePublicKey("ssh-rsa").overrideLoginCredentials( LoginCredentials.builder().user("foo").privateKey(CREDENTIALS.credential).build()); KeyPair keyPair = new KeyPair(region, group, "//TODO", null, null); // setup expectations expect( strategy.importExistingKeyPair.apply(new RegionNameAndPublicKeyMaterial(region, group, CREDENTIALS.credential))).andReturn(keyPair); expect( strategy.credentialsMap.put(new RegionAndName(region, group), keyPair.toBuilder().keyMaterial(CREDENTIALS.credential).build())).andReturn(null); // replay mocks replayStrategy(strategy); // run assertEquals(strategy.createNewKeyPairUnlessUserSpecifiedOtherwise(region, group, options), group); // verify mocks verifyStrategy(strategy); }