InstanceAWSProvider implements InstanceProvider { @Override public void initialize(String provider, String providerEndpoint, SSLContext sslContext, KeyStore keyStore) { String awsCertFileName = System.getProperty(AWS_PROP_PUBLIC_CERT); if (awsCertFileName != null && !awsCertFileName.isEmpty()) { File awsCertFile = new File(awsCertFileName); X509Certificate awsCert = Crypto.loadX509Certificate(awsCertFile); awsPublicKey = awsCert.getPublicKey(); } if (awsPublicKey == null) { LOGGER.error("AWS Public Key not specified - no instance requests will be authorized"); } long timeout = TimeUnit.SECONDS.convert(5, TimeUnit.MINUTES); bootTimeOffset = 1000 * Long.parseLong( System.getProperty(AWS_PROP_BOOT_TIME_OFFSET, Long.toString(timeout))); dnsSuffix = System.getProperty(AWS_PROP_DNS_SUFFIX); if (dnsSuffix == null || dnsSuffix.isEmpty()) { LOGGER.error("AWS DNS Suffix not specified - no instance requests will be authorized"); } int certValidityDays = Integer.parseInt(System.getProperty(AWS_PROP_CERT_VALIDITY_STS_ONLY, "7")); certValidityTime = TimeUnit.MINUTES.convert(certValidityDays, TimeUnit.DAYS); awsRegion = System.getProperty(AWS_PROP_REGION_NAME); }  @Override Scheme getProviderScheme(); @Override void initialize(String provider, String providerEndpoint, SSLContext sslContext,
            KeyStore keyStore); ResourceException error(String message); ResourceException error(int errorCode, String message); @Override InstanceConfirmation confirmInstance(InstanceConfirmation confirmation); @Override InstanceConfirmation refreshInstance(InstanceConfirmation confirmation);  }
@Test public void testInitializeDefaults() { InstanceAWSProvider provider = new InstanceAWSProvider(); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null, null); assertNull(provider.awsPublicKey); assertEquals(provider.bootTimeOffset, 300000); provider.close(); }
@Test public void testInitialize() { InstanceAWSProvider provider = new InstanceAWSProvider(); System.setProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT, "src/test/resources/aws_public.cert"); System.setProperty(InstanceAWSProvider.AWS_PROP_BOOT_TIME_OFFSET, "60"); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null, null); assertNotNull(provider.awsPublicKey); assertEquals(provider.bootTimeOffset, 60000); provider.close(); System.clearProperty(InstanceAWSProvider.AWS_PROP_PUBLIC_CERT); System.clearProperty(InstanceAWSProvider.AWS_PROP_BOOT_TIME_OFFSET); }
@Test public void testInitializeDNSSuffix() { InstanceAWSProvider provider = new InstanceAWSProvider(); System.clearProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null, null); assertNull(provider.dnsSuffix); provider.close(); provider = new InstanceAWSProvider(); System.setProperty(InstanceAWSProvider.AWS_PROP_DNS_SUFFIX, ""); provider.initialize("provider", "com.yahoo.athenz.instance.provider.impl.InstanceAWSProvider", null, null); assertEquals("", provider.dnsSuffix); provider.close(); }