@Override public AWSCredentials getCredentials() { String accessKey = System.getenv(ACCESS_KEY_ENV_VAR); if (accessKey == null) { accessKey = System.getenv(ALTERNATE_ACCESS_KEY_ENV_VAR); } String secretKey = System.getenv(SECRET_KEY_ENV_VAR); if (secretKey == null) { secretKey = System.getenv(ALTERNATE_SECRET_KEY_ENV_VAR); } accessKey = StringUtils.trim(accessKey); secretKey = StringUtils.trim(secretKey); String sessionToken = StringUtils.trim(System.getenv(AWS_SESSION_TOKEN_ENV_VAR)); if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) { throw new SdkClientException( "Unable to load AWS credentials from environment variables " + "(" + ACCESS_KEY_ENV_VAR + " (or " + ALTERNATE_ACCESS_KEY_ENV_VAR + ") and " + SECRET_KEY_ENV_VAR + " (or " + ALTERNATE_SECRET_KEY_ENV_VAR + "))"); } return sessionToken == null ? new BasicAWSCredentials(accessKey, secretKey) : new BasicSessionCredentials(accessKey, secretKey, sessionToken); }
/** * Gets an {@link AWSCredentialsProvider} that may be used to connect to this container. * * @return dummy AWS credentials */ public AWSCredentialsProvider getCredentials() { return new AWSStaticCredentialsProvider(new BasicAWSCredentials("dummy", "dummy")); }
/** * Create AmazonS3 client using AWS credentials * @return AmazonS3 */ protected AmazonS3 createClient() { AmazonS3 client = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretAccessKey)); if (endPoint != null) { client.setEndpoint(endPoint); } return client; }
s3Credentials = new BasicAWSCredentials(accessKeyId, secretKey); clientConfig = new ClientConfiguration(); clientConfig.setMaxErrorRetry(Integer.parseInt(maxErrorRetry)); if(protocol.equals("HTTP")) { clientConfig.setProtocol(Protocol.HTTP); } else { clientConfig.setProtocol(Protocol.HTTPS); clientConfig.setMaxConnections(Integer.parseInt(maxConnections)); s3Client = new AmazonS3Client(s3Credentials, clientConfig); s3Client.setRegion(Region.getRegion(Regions.fromName(region))); s3Client.setEndpoint(endPoint); System.out.println("Connection successfully initialized"); } catch (Exception e){
@Provides @Singleton public SingularityS3Services provideS3Services(Optional<S3Configuration> config) { if (!config.isPresent()) { return new SingularityS3Services(); } final ImmutableList.Builder<SingularityS3Service> s3ServiceBuilder = ImmutableList.builder(); for (Map.Entry<String, S3GroupConfiguration> entry : config.get().getGroupOverrides().entrySet()) { s3ServiceBuilder.add(new SingularityS3Service(entry.getKey(), entry.getValue().getS3Bucket(), new AmazonS3Client(new BasicAWSCredentials(entry.getValue().getS3AccessKey(), entry.getValue().getS3SecretKey())))); } for (Map.Entry<String, S3GroupConfiguration> entry : config.get().getGroupS3SearchConfigs().entrySet()) { s3ServiceBuilder.add(new SingularityS3Service(entry.getKey(), entry.getValue().getS3Bucket(), new AmazonS3Client(new BasicAWSCredentials(entry.getValue().getS3AccessKey(), entry.getValue().getS3SecretKey())))); } SingularityS3Service defaultService = new SingularityS3Service(SingularityS3FormatHelper.DEFAULT_GROUP_NAME, config.get().getS3Bucket(), new AmazonS3Client(new BasicAWSCredentials(config.get().getS3AccessKey(), config.get().getS3SecretKey()))); return new SingularityS3Services(s3ServiceBuilder.build(), defaultService); }
/** * @param accessKey * @param secretKey * @return */ public static AmazonEC2Client getEC2Client( String accessKey, String secretKey ) { AWSCredentialsProvider provider; if ( accessKey != null && secretKey != null ) { AWSCredentials credentials = new BasicAWSCredentials( accessKey, secretKey ); provider = new StaticCredentialsProvider( credentials ); } else { provider = new DefaultAWSCredentialsProviderChain(); } AmazonEC2Client client = new AmazonEC2Client( provider ); ClientConfiguration configuration = new ClientConfiguration(); configuration.setProtocol( Protocol.HTTPS ); client.setConfiguration( configuration ); return client; }
final AWSCredentials basicAWSCredentials = new BasicAWSCredentials(clientOptions.getAccessKey(), clientOptions.getSecretKey()); final ClientConfiguration configuration = new ClientConfiguration(); configuration.setProtocol(clientOptions.isHttps() ? HTTPS : HTTP); configuration.setConnectionTimeout(clientOptions.getConnectionTimeout()); clientOptions.getUseTCPKeepAlive(), clientOptions.getConnectionTtl())); final AmazonS3Client client = new AmazonS3Client(basicAWSCredentials, configuration); client.setEndpoint(clientOptions.getEndPoint());
private void getFiles(String path) throws IOException{ AmazonS3 s3 = new AmazonS3Client( new BasicAWSCredentials(apiKey, apiKeySecret)); ObjectListing objList = s3.listObjects(bucket, path); for (S3ObjectSummary summary:objList.getObjectSummaries()) { //ignore folders if(! summary.getKey().endsWith(FOLDER_SUFFIX)){ S3Object obj = s3.getObject( new GetObjectRequest(bucket, summary.getKey())); logger.info("retrieving " + summary.getKey()); FileOutputStream fout = new FileOutputStream(TEMP_FOLDER + summary.getKey().substring(path.length())); InputStream in = obj.getObjectContent(); byte[] buf = new byte[1024]; int len; while ((len = in.read(buf)) > 0){ fout.write(buf, 0, len); } in.close(); fout.close(); } } } protected void afterPropertiesSet(GenericFileEndpoint<File> endpoint) throws Exception {
private AmazonAutoScaling getAmazonAutoScalingClient() { String aWSAccessId = serverConfig.getAWSAccessId(); String aWSSecretKey = serverConfig.getAWSSecretKey(); ClientConfiguration clientConfiguration = new ClientConfiguration() .withConnectionTimeout(serverConfig.getASGQueryTimeoutMs()); if (null != aWSAccessId && !"".equals(aWSAccessId) && null != aWSSecretKey && !"".equals(aWSSecretKey)) { return new AmazonAutoScalingClient( new BasicAWSCredentials(aWSAccessId, aWSSecretKey), clientConfiguration); } else { return new AmazonAutoScalingClient( new InstanceProfileCredentialsProvider(), clientConfiguration); } }
public AWSCredentials getCredentials() { if (sessionToken.isEmpty()) { return new BasicAWSCredentials(accessKey, secretKey); } else { return new BasicSessionCredentials(accessKey, secretKey, sessionToken); } } public void refresh() {}
@Override public void start() { // Set up Amazon S3 client. AWSCredentials credentials = new BasicAWSCredentials( awsAccessKeyId, awsSecretKey); ClientConfiguration config = new ClientConfiguration(); config.setProtocol(Protocol.HTTP); connection = new AmazonS3Client(credentials, config); connection.setEndpoint(endPoint); if (!connection.doesBucketExist(bucket)) { connection.createBucket(bucket); } super.start(); }
@Before public void setup() throws Exception { Properties syncProperties = TestConfig.getProperties(); endpoint = syncProperties.getProperty(TestConfig.PROP_S3_ENDPOINT); accessKey = syncProperties.getProperty(TestConfig.PROP_S3_ACCESS_KEY_ID); secretKey = syncProperties.getProperty(TestConfig.PROP_S3_SECRET_KEY); String proxyUri = syncProperties.getProperty(TestConfig.PROP_HTTP_PROXY_URI); Assume.assumeNotNull(endpoint, accessKey, secretKey); endpointUri = new URI(endpoint); ClientConfiguration config = new ClientConfiguration().withSignerOverride("S3SignerType"); if (proxyUri != null) { URI uri = new URI(proxyUri); config.setProxyHost(uri.getHost()); config.setProxyPort(uri.getPort()); } s3 = new AmazonS3Client(new BasicAWSCredentials(accessKey, secretKey), config); s3.setEndpoint(endpoint); }
private static Optional<AWSCredentials> getAwsCredentials(Configuration conf) { String accessKey = conf.get(S3_ACCESS_KEY); String secretKey = conf.get(S3_SECRET_KEY); if (isNullOrEmpty(accessKey) || isNullOrEmpty(secretKey)) { return Optional.empty(); } return Optional.of(new BasicAWSCredentials(accessKey, secretKey)); } }
@Override @NotNull @Cacheable(lifetime = Tv.TEN, unit = TimeUnit.MINUTES) public AmazonS3 client() { final AmazonS3 client = new AmazonS3Client( new BasicAWSCredentials(this.domain.key(), this.domain.secret()), new ClientConfiguration() .withSocketTimeout(0) .withProtocol(Protocol.HTTP) ); client.setEndpoint( String.format("%s.amazonaws.com", this.domain.region()) ); return client; }
public S3MockClientFactory(int port, String username, String pass) { try { this.s3.start(port, username, pass); } catch (IOException | InterruptedException | InvalidExitValueException | TimeoutException e) { throw new RuntimeException(e); } BasicAWSCredentials awsCredentials = new BasicAWSCredentials(username, pass); this.client = new AmazonS3Client(awsCredentials, new ClientConfiguration()); this.client.setEndpoint("http://127.0.0.1:" + port); this.client.createBucket(S3_BUCKET); }
private static void applicationCredentials(Config conf, String serviceName, Consumer<AWSCredentialsProvider> consumer) { String accessKey = find(conf, "aws." + serviceName + "." + ACCESS_KEY, "aws." + ACCESS_KEY); if (accessKey != null) { String secretKey = find(conf, "aws." + serviceName + "." + SECRET_KEY, "aws." + SECRET_KEY); String sessionToken = find(conf, "aws." + serviceName + "." + SESSION_TOKEN, "aws." + SESSION_TOKEN); AWSCredentials credentials = sessionToken == null ? new BasicAWSCredentials(accessKey, secretKey) : new BasicSessionCredentials(accessKey, secretKey, sessionToken); consumer.accept(new AWSStaticCredentialsProvider(credentials)); } }
@Override @Cacheable(lifetime = 1, unit = TimeUnit.HOURS) public AmazonCloudWatchClient get() { return new AmazonCloudWatchAsyncClient( new BasicAWSCredentials( Manifests.read("S3Auth-AwsCloudWatchKey"), Manifests.read("S3Auth-AwsCloudWatchSecret") ), new ClientConfiguration().withProtocol(Protocol.HTTP), Executors.newFixedThreadPool(Tv.FIFTY) ); } };
@Test public void testConstructors6() { ClientConfiguration c = new ClientConfiguration(); c.setUserAgent("test"); c.setMaxConnections(2); c.getMaxConnections(); c.getUserAgent(); AWSCredentials creds = new BasicAWSCredentials("random", "test"); StaticCredentialsProvider credProvider = new StaticCredentialsProvider(creds); LambdaInvokerFactory f = new LambdaInvokerFactory.Builder() .clientConfiguration(c) .credentialsProvider(credProvider) .region(Regions.US_WEST_2) .build(); }
@Test public void testConstructorWithBasicAwsCredentialsAndClientConfiguration() { creds = new BasicAWSCredentials("accessKey", "secretKey"); s3 = new AmazonS3Client(creds, new ClientConfiguration()); assertNotNull(s3); }
private static AmazonS3 getAmazonS3Client(AuditWriterConfiguration configuration) { AWSCredentialsProvider credentialsProvider; if (configuration.getS3AccessKey() != null && configuration.getS3SecretKey() != null) { credentialsProvider = new StaticCredentialsProvider( new BasicAWSCredentials(configuration.getS3AccessKey(), configuration.getS3SecretKey())); } else { credentialsProvider = new DefaultAWSCredentialsProviderChain(); } AmazonS3 s3 = new AmazonS3Client(credentialsProvider) .withRegion(Regions.fromName(configuration.getLogBucketRegion())); if (configuration.getS3Endpoint() != null) { s3.setEndpoint(configuration.getS3Endpoint()); } return s3; }