AWSCertRecordStoreFactory implements CertRecordStoreFactory { @Override public CertRecordStore create(PrivateKeyStore keyStore) { rdsUser = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER); rdsIamRole = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE); rdsMaster = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE); rdsPort = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_PORT, "3306")); final String rdsEngine = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_ENGINE, "mysql"); final String rdsDatabase = System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_DATABASE, "zts_store"); final String jdbcStore = String.format("jdbc:%s: String rdsToken = getAuthToken(rdsMaster, rdsPort, rdsUser, rdsIamRole); if (LOGGER.isDebugEnabled()) { LOGGER.debug("Connecting to {} with auth token {}", jdbcStore, rdsToken); } mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_VERIFY_SERVER_CERT, System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_VERIFY_SERVER_CERT, "true")); mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_USE_SSL, System.getProperty(ZTSConsts.ZTS_PROP_CERT_JDBC_USE_SSL, "true")); mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_USER, rdsUser); mysqlConnectionProperties.setProperty(ZTSConsts.DB_PROP_PASSWORD, rdsToken); PoolableDataSource dataSource = DataSourceFactory.create(jdbcStore, mysqlConnectionProperties); long credsRefreshTime = Integer.parseInt(System.getProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "300")); ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(1); scheduledThreadPool.scheduleAtFixedRate(new CredentialsUpdater(), credsRefreshTime, credsRefreshTime, TimeUnit.SECONDS); return new JDBCCertRecordStore(dataSource); }  @Override CertRecordStore create(PrivateKeyStore keyStore);  }
@Test public void testCreate() { System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE, "instance"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER, "rds-user"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE, "role"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "1"); AWSCertRecordStoreFactory factory = new TestAWSCertRecordStoreFactory(); CertRecordStore store = factory.create(null); try { Thread.sleep(2000); } catch (InterruptedException ignored) { } assertNotNull(store); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME); }
@Test public void testGetTokenException() { System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE, "instance"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER, "rds-user"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE, "role"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "1"); AWSCertRecordStoreFactory factory = new TestAWSCertRecordStoreFactory2(); CertRecordStore store = factory.create(null); assertNotNull(store); ((TestAWSCertRecordStoreFactory2) factory).setThrowGetTokenExc(true); AWSCertRecordStoreFactory.CredentialsUpdater updater = factory.new CredentialsUpdater(); updater.run(); updater.run(); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME); }
@Test public void testCredentialsUpdater() { System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE, "instance"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER, "rds-user2"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE, "role"); System.setProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME, "1"); AWSCertRecordStoreFactory factory = new TestAWSCertRecordStoreFactory(); CertRecordStore store = factory.create(null); assertNotNull(store); try { Thread.sleep(2000); } catch (InterruptedException ignored) { } System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_MASTER_INSTANCE); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_USER); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_IAM_ROLE); System.clearProperty(ZTSConsts.ZTS_PROP_AWS_RDS_CREDS_REFRESH_TIME); }