private static AWSCredentialsProvider buildCredentialsProvider(Config config) { if (config.has("credentials.file")) { return new PropertiesFileCredentialsProvider( config.get("credentials.file", String.class)); } else if (config.has("credentials.access-key-id")) { final BasicAWSCredentials creds = new BasicAWSCredentials( config.get("credentials.access-key-id", String.class), config.get("credentials.secret-access-key", String.class)); return new AWSCredentialsProvider() { @Override public AWSCredentials getCredentials() { return creds; } @Override public void refresh() { } }; } else { return new DefaultAWSCredentialsProviderChain(); } }
/** * Loads AWS credentials from a properties file. * * <p>The AWS access key ID is expected to be in the <code>accessKey</code> property and the AWS * secret key is expected to be in the <code>secretKey</code> property. * * @throws GeneralSecurityException if the client initialization fails */ @Override public KmsClient withCredentials(String credentialPath) throws GeneralSecurityException { try { if (credentialPath == null) { return withDefaultCredentials(); } return withCredentialsProvider(new PropertiesFileCredentialsProvider(credentialPath)); } catch (AmazonServiceException e) { throw new GeneralSecurityException("cannot load credentials", e); } }
public SQSTestBase() { PropertiesFileCredentialsProvider file = new PropertiesFileCredentialsProvider(getTestCredsFilePath()); testCreds = (PropertiesCredentials)file.getCredentials(); sqs = new AmazonSQSClient(testCreds); }
@Override protected void starting(Description description) { final String methodName = description.getMethodName(); final String className = description.getClassName(); testBase = new SQSTestBase(); if (testBase.validateTestCreds() == false) { return; } testBase.generateCurrentQueueName(methodName); try { testBase.beforTest(); } catch (AssumptionViolatedException ave) { throw ave; } catch (Exception e) { throw new RuntimeException(e); } baseDir = "target/" + className + "/" + methodName; Attribute.AttributeMap attributeMap = new Attribute.AttributeMap.DefaultAttributeMap(); attributeMap.put(Context.OperatorContext.SPIN_MILLIS, 500); attributeMap.put(Context.DAGContext.APPLICATION_PATH, baseDir); context = mockOperatorContext(1, attributeMap); operator = new JMSStringInputOperator(); operator.setConnectionFactoryBuilder(new JMSBase.ConnectionFactoryBuilder() { @Override public ConnectionFactory buildConnectionFactory() { // Create the connection factory using the environment variable credential provider. // Connections this factory creates can talk to the queues in us-east-1 region. SQSConnectionFactory connectionFactory = SQSConnectionFactory.builder() .withRegion(Region.getRegion(Regions.US_EAST_1)) .withAWSCredentialsProvider(new PropertiesFileCredentialsProvider(testBase.getDevCredsFilePath())) .build(); return connectionFactory; } @Override public String toString() { return className + "/" + methodName + "/ConnectionFactoryBuilder"; } }); operator.setSubject(testBase.getCurrentQueueName()); // for SQS ack mode should be "AUTO_ACKNOWLEDGE" and transacted = false operator.setAckMode("AUTO_ACKNOWLEDGE"); operator.setTransacted(false); sink = new CollectorTestSink<>(); operator.output.setSink(sink); operator.setup(context); operator.activate(context); }