SetupAdminAccess extends PuppetActivity { @Override public String createPuppetScript(Pool pool, Machine machine) throws Exception { return Mustache.toString(getClass(), ADMIN_ACCESS_TEMPLATE, ImmutableMap.of( "user", pool.getAdminAccess().getUsername(), "publicKey", getRawSshKey(pool)) ); } SetupAdminAccess(); @Override AdminAccess overrideAdminAccess(Pool pool); @Override String createPuppetScript(Pool pool, Machine machine); @Override Map<String, String> createAdditionalFiles(Pool pool, Machine machine); static final String DEFAULT_UBUNTU_AMI_USER; static final String ADMIN_ACCESS_TEMPLATE; static final String SSHD_CONFIG_TEMPLATE; static final String SUDOERS_TEMPLATE; }
@Test public void testCreatePuppetScript() throws Exception { Pool pool = mock(Pool.class); final AdminAccess adminAccess = AdminAccess.builder() .privateKey(TestConstants.PRIVATE_KEY) .publicKey(TestConstants.PUBLIC_KEY) .username(System.getProperty("user.name")) .createAdminAccess(); when(pool.getAdminAccess()).thenReturn(adminAccess); PuppetActivity activity = new SetupAdminAccess(); String content = activity.createPuppetScript(pool, null); final String username = adminAccess.getUsername(); assertThat(content).contains(username) .contains(adminAccess.getPublicKey().split(" ")[1]) .contains(String.format("user { \"%s\":", username)) .contains(String.format("file { \"/home/%s/.ssh\":", username)); }