com.amazonaws.auth.AWSCredentials Java Examples

The following examples show how to use com.amazonaws.auth.AWSCredentials. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: S3UploadSystemTest.java    From micro-server with Apache License 2.0 6 votes vote down vote up
private static TransferManager createManager() {
    AWSCredentials credentials = new AWSCredentials() {

        @Override
        public String getAWSAccessKeyId() {
            return System.getProperty("s3.accessKey");
        }

        @Override
        public String getAWSSecretKey() {
            return System.getProperty("s3.secretKey");
        }

    };
    return new TransferManager(
                                  credentials);
}
 
Example #2
Source File: AWSGlueClientFactoryTest.java    From aws-glue-data-catalog-client-for-apache-hive-metastore with Apache License 2.0 6 votes vote down vote up
@Test
public void testCredentialsCreatedBySessionCredentialsProviderFactory() throws Exception {
  hiveConf.setStrings(SessionCredentialsProviderFactory.AWS_ACCESS_KEY_CONF_VAR, FAKE_ACCESS_KEY);
  hiveConf.setStrings(SessionCredentialsProviderFactory.AWS_SECRET_KEY_CONF_VAR, FAKE_SECRET_KEY);
  hiveConf.setStrings(SessionCredentialsProviderFactory.AWS_SESSION_TOKEN_CONF_VAR, FAKE_SESSION_TOKEN);

  SessionCredentialsProviderFactory factory = new SessionCredentialsProviderFactory();
  AWSCredentialsProvider provider = factory.buildAWSCredentialsProvider(hiveConf);
  AWSCredentials credentials = provider.getCredentials();

  assertThat(credentials, instanceOf(BasicSessionCredentials.class));

  BasicSessionCredentials sessionCredentials = (BasicSessionCredentials) credentials;

  assertEquals(FAKE_ACCESS_KEY, sessionCredentials.getAWSAccessKeyId());
  assertEquals(FAKE_SECRET_KEY, sessionCredentials.getAWSSecretKey());
  assertEquals(FAKE_SESSION_TOKEN, sessionCredentials.getSessionToken());
}
 
Example #3
Source File: AmazonS3InstallationServiceTest.java    From java-slack-sdk with MIT License 6 votes vote down vote up
@Test
public void operations() throws Exception {
    AWSCredentials credentials = mock(AWSCredentials.class);
    when(credentials.getAWSAccessKeyId()).thenReturn("valid key");
    AmazonS3 s3 = mock(AmazonS3.class);
    when(s3.doesBucketExistV2(anyString())).thenReturn(true);

    AmazonS3InstallationService service = new AmazonS3InstallationService("test-bucket") {
        @Override
        protected AWSCredentials getCredentials() {
            return credentials;
        }

        @Override
        protected AmazonS3 createS3Client() {
            return s3;
        }
    };
    service.initializer().accept(null);

    service.saveInstallerAndBot(new DefaultInstaller());
    service.deleteBot(new DefaultBot());
    service.deleteInstaller(new DefaultInstaller());
    service.findBot("E123", "T123");
    service.findInstaller("E123", "T123", "U123");
}
 
Example #4
Source File: MockAwsSqs.java    From aws-codecommit-trigger-plugin with Apache License 2.0 6 votes vote down vote up
private void start() throws IOException {
    System.out.println("starting mock sqs server");
    //this.port = findFreeLocalPort(); @see https://github.com/findify/sqsmock/pull/7
    this.api = new SQSService(this.port, 1);
    this.api.start();

    AWSCredentials credentials = new AnonymousAWSCredentials();
    this.sqsClient = new MockSQSClient(credentials);

    this.endpoint = String.format("http://localhost:%s", this.port);
    this.sqsClient.setEndpoint(endpoint);

    this.sqsUrl = this.sqsClient.createQueue(this.getClass().getSimpleName()).getQueueUrl();
    ((MockSQSClient)this.sqsClient).setQueueUrl(this.sqsUrl);

    this.started = true;
}
 
Example #5
Source File: CodeBuildBaseCredentials.java    From aws-codebuild-jenkins-plugin with Apache License 2.0 6 votes vote down vote up
@Override
public void refresh() {
    if (!iamRoleArn.isEmpty()) {
        if (!haveCredentialsExpired()) {
            return;
        }

        AWSCredentialsProvider credentialsProvider = getBasicCredentialsOrDefaultChain(accessKey, secretKey);
        AWSCredentials credentials = credentialsProvider.getCredentials();

        AssumeRoleRequest assumeRequest = new AssumeRoleRequest()
                .withRoleArn(iamRoleArn)
                .withExternalId(externalId)
                .withDurationSeconds(3600)
                .withRoleSessionName(ROLE_SESSION_NAME);

        AssumeRoleResult assumeResult = new AWSSecurityTokenServiceClient(credentials).assumeRole(assumeRequest);

        roleCredentials = assumeResult.getCredentials();
    }
}
 
Example #6
Source File: AwsCredentialProviderPlugin.java    From pulsar with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a V2 credential provider for use with the v2 SDK.
 *
 * Defaults to an implementation that pulls credentials from a v1 provider
 */
default software.amazon.awssdk.auth.credentials.AwsCredentialsProvider getV2CredentialsProvider() {
    // make a small wrapper to forward requests to v1, this allows
    // for this interface to not "break" for implementers
    AWSCredentialsProvider v1Provider = getCredentialProvider();
    return () -> {
        AWSCredentials creds = v1Provider.getCredentials();
        if (creds instanceof AWSSessionCredentials) {
            return software.amazon.awssdk.auth.credentials.AwsSessionCredentials.create(
                    creds.getAWSAccessKeyId(),
                    creds.getAWSSecretKey(),
                    ((AWSSessionCredentials) creds).getSessionToken());
        } else {
            return software.amazon.awssdk.auth.credentials.AwsBasicCredentials.create(
                    creds.getAWSAccessKeyId(),
                    creds.getAWSSecretKey());
        }
    };
}
 
Example #7
Source File: AmazonS3SourceMockTests.java    From spring-cloud-stream-app-starters with Apache License 2.0 6 votes vote down vote up
@Test
@Override
public void test() throws Exception {
	for (int i = 1; i <= 2; i++) {
		Message<?> received = this.messageCollector.forChannel(this.channels.output())
				.poll(10, TimeUnit.SECONDS);
		assertNotNull(received);
		assertThat(received, hasPayload(new File(this.config.getLocalDir(), i + ".test")));
	}

	assertEquals(2, this.config.getLocalDir().list().length);

	AWSCredentialsProvider awsCredentialsProvider =
			TestUtils.getPropertyValue(this.amazonS3, "awsCredentialsProvider", AWSCredentialsProvider.class);

	AWSCredentials credentials = awsCredentialsProvider.getCredentials();
	assertEquals(AWS_ACCESS_KEY, credentials.getAWSAccessKeyId());
	assertEquals(AWS_SECRET_KEY, credentials.getAWSSecretKey());

	assertEquals(Region.US_GovCloud, this.amazonS3.getRegion());
	assertEquals(new URI("https://s3-us-gov-west-1.amazonaws.com"),
			TestUtils.getPropertyValue(this.amazonS3, "endpoint"));
}
 
Example #8
Source File: TestPrestoS3FileSystem.java    From presto with Apache License 2.0 6 votes vote down vote up
@Test
public void testAssumeRoleStaticCredentials()
        throws Exception
{
    Configuration config = new Configuration(false);
    config.set(S3_ACCESS_KEY, "test_access_key");
    config.set(S3_SECRET_KEY, "test_secret_key");
    config.set(S3_IAM_ROLE, "test_role");

    try (PrestoS3FileSystem fs = new PrestoS3FileSystem()) {
        fs.initialize(new URI("s3n://test-bucket/"), config);
        AWSCredentialsProvider tokenService = getStsCredentialsProvider(fs, "test_role");
        assertInstanceOf(tokenService, AWSStaticCredentialsProvider.class);

        AWSCredentials credentials = tokenService.getCredentials();
        assertEquals(credentials.getAWSAccessKeyId(), "test_access_key");
        assertEquals(credentials.getAWSSecretKey(), "test_secret_key");
    }
}
 
Example #9
Source File: PropertyAWSCredentialsProvider.java    From suro with Apache License 2.0 6 votes vote down vote up
@Override
public AWSCredentials getCredentials() {
    if (accessKey != null && secretKey != null) {
        return new AWSCredentials() {
            @Override
            public String getAWSAccessKeyId() {
                return accessKey;
            }

            @Override
            public String getAWSSecretKey() {
                return secretKey;
            }
        };
    } 
    else {
        return null;
    }
}
 
Example #10
Source File: AWSCredentialsConfigurator.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Credentials configure(final Host host) {
    final Credentials credentials = new Credentials(host.getCredentials());
    if(!credentials.validate(host.getProtocol(), new LoginOptions(host.getProtocol()).password(false))) {
        // Lookup from default profile if no access key is set in bookmark
        for(AWSCredentialsProvider provider : providers) {
            try {
                final AWSCredentials c = provider.getCredentials();
                credentials.setUsername(c.getAWSAccessKeyId());
                credentials.setPassword(c.getAWSSecretKey());
                if(c instanceof AWSSessionCredentials) {
                    credentials.setToken(((AWSSessionCredentials) c).getSessionToken());
                }
                break;
            }
            catch(SdkClientException e) {
                log.debug(String.format("Ignore failure loading credentials from provider %s", provider));
                // Continue searching with next provider
            }
        }
    }
    return credentials;
}
 
Example #11
Source File: S3ObjectsProviderTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private AmazonS3 getS3ClientMock( AWSCredentials credentials ) throws Exception {
  AmazonS3 s3Client = mock( AmazonS3.class );
  when( s3Client.listBuckets() ).thenReturn( generateTestBuckets( TEST_USER_BUCKETS_NAMES ) );
  // BUCKET2 - not empty bucket
  when( s3Client.listObjects( BUCKET2.getName() ) ).thenReturn( bucket2Objects );
  // BUCKET3 - empty bucket
  when( s3Client.listObjects( BUCKET3.getName() ) ).thenReturn( bucket3Objects );

  when( s3Client.getObject( any( String.class ), any( String.class ) ) ).thenReturn( testObject );
  ObjectMetadata mockMetaData = mock( ObjectMetadata.class );
  when( s3Client.getObjectMetadata( BUCKET1.getName(), "test3Object" ) ).thenReturn( mockMetaData );

  doReturn( false ).when( s3Client ).doesBucketExistV2( UNKNOWN_BUCKET );
  doReturn( true ).when( s3Client ).doesBucketExistV2( BUCKET2_NAME );
  doReturn( true ).when( s3Client ).doesBucketExistV2( BUCKET3_NAME );

  return s3Client;
}
 
Example #12
Source File: AbstractAWSProcessor.java    From localization_nifi with Apache License 2.0 6 votes vote down vote up
protected AWSCredentials getCredentials(final ProcessContext context) {
    final String accessKey = context.getProperty(ACCESS_KEY).evaluateAttributeExpressions().getValue();
    final String secretKey = context.getProperty(SECRET_KEY).evaluateAttributeExpressions().getValue();

    final String credentialsFile = context.getProperty(CREDENTIALS_FILE).getValue();

    if (credentialsFile != null) {
        try {
            return new PropertiesCredentials(new File(credentialsFile));
        } catch (final IOException ioe) {
            throw new ProcessException("Could not read Credentials File", ioe);
        }
    }

    if (accessKey != null && secretKey != null) {
        return new BasicAWSCredentials(accessKey, secretKey);
    }

    return new AnonymousAWSCredentials();

}
 
Example #13
Source File: AirpalModule.java    From airpal with Apache License 2.0 6 votes vote down vote up
@Singleton
@Provides
@Nullable
public AmazonS3 provideAmazonS3Client(@Nullable AWSCredentials awsCredentials, @Nullable EncryptionMaterialsProvider encryptionMaterialsProvider)
{
    if (awsCredentials == null) {
        if (encryptionMaterialsProvider == null) {
            return new AmazonS3Client(new InstanceProfileCredentialsProvider());
        }
        else {
            return new AmazonS3EncryptionClient(new InstanceProfileCredentialsProvider(), encryptionMaterialsProvider);
        }
    }

    if (encryptionMaterialsProvider == null) {
        return new AmazonS3Client(awsCredentials);
    }
    else {
        return new AmazonS3EncryptionClient(awsCredentials, encryptionMaterialsProvider);
    }
}
 
Example #14
Source File: IvonaSpeechCloudClient.java    From ivona-speechcloud-sdk-java with Apache License 2.0 6 votes vote down vote up
private <Y> Request<Y> prepareRequest(Request<Y> request, ExecutionContext executionContext, boolean signRequest) {
    request.setEndpoint(endpoint);
    request.setTimeOffset(timeOffset);

    AWSCredentials credentials = awsCredentialsProvider.getCredentials();

    AmazonWebServiceRequest originalRequest = request.getOriginalRequest();
    if (originalRequest != null && originalRequest.getRequestCredentials() != null) {
        credentials = originalRequest.getRequestCredentials();
    }
    if (signRequest) {
        // expiration date is not currently supported on service side, but presignRequest method requires
        // this argument so one with default value is provided.
        Date expirationDate = DateTime.now(DateTimeZone.UTC)
                .plusMinutes(DEFAULT_GET_REQUEST_EXPIRATION_MINUTES).toDate();
        signer.presignRequest(request, credentials, expirationDate);
    } else {
        executionContext.setSigner(signer);
        executionContext.setCredentials(credentials);
    }
    return request;
}
 
Example #15
Source File: V2CredentialWrapper.java    From amazon-kinesis-client with Apache License 2.0 6 votes vote down vote up
@Override
public AwsCredentials resolveCredentials() {
    AWSCredentials current = oldCredentialsProvider.getCredentials();
    if (current instanceof AWSSessionCredentials) {
        return AwsSessionCredentials.create(current.getAWSAccessKeyId(), current.getAWSSecretKey(), ((AWSSessionCredentials) current).getSessionToken());
    }
    return new AwsCredentials() {
        @Override
        public String accessKeyId() {
            return current.getAWSAccessKeyId();
        }

        @Override
        public String secretAccessKey() {
            return current.getAWSSecretKey();
        }
    };
}
 
Example #16
Source File: STSCredentialsConfigurator.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
protected AWSSecurityTokenService getTokenService(final Host host, final String region, final String accessKey, final String secretKey, final String sessionToken) {
    final ClientConfiguration configuration = new CustomClientConfiguration(host,
        new ThreadLocalHostnameDelegatingTrustManager(trust, host.getHostname()), key);
    return AWSSecurityTokenServiceClientBuilder.standard()
        .withCredentials(new AWSStaticCredentialsProvider(StringUtils.isBlank(sessionToken) ? new AWSCredentials() {
            @Override
            public String getAWSAccessKeyId() {
                return accessKey;
            }

            @Override
            public String getAWSSecretKey() {
                return secretKey;
            }
        } : new AWSSessionCredentials() {
            @Override
            public String getAWSAccessKeyId() {
                return accessKey;
            }

            @Override
            public String getAWSSecretKey() {
                return secretKey;
            }

            @Override
            public String getSessionToken() {
                return sessionToken;
            }
        }))
        .withClientConfiguration(configuration)
        .withRegion(StringUtils.isNotBlank(region) ? Regions.fromName(region) : Regions.DEFAULT_REGION).build();
}
 
Example #17
Source File: S3StorageTest.java    From digdag with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp()
        throws Exception
{
    assumeThat(TEST_S3_ENDPOINT, not(isEmptyOrNullString()));

    AWSCredentials credentials = new BasicAWSCredentials(TEST_S3_ACCESS_KEY_ID, TEST_S3_SECRET_ACCESS_KEY);
    AmazonS3Client s3 = new AmazonS3Client(credentials);
    s3.setEndpoint(TEST_S3_ENDPOINT);

    String bucket = UUID.randomUUID().toString();
    s3.createBucket(bucket);

    ConfigFactory cf = new ConfigFactory(objectMapper());
    Config config = cf.create()
        .set("endpoint", TEST_S3_ENDPOINT)
        .set("bucket", bucket)  // use unique bucket name
        .set("credentials.access-key-id", TEST_S3_ACCESS_KEY_ID)
        .set("credentials.secret-access-key", TEST_S3_SECRET_ACCESS_KEY)
        ;
    storage = new S3StorageFactory().newStorage(config);
}
 
Example #18
Source File: AbstractDynamoDBProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Create client using AWSCredentials
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AmazonDynamoDBClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().debug("Creating client with aws credentials");

    final AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials, config);

    return client;
}
 
Example #19
Source File: BucketClass.java    From cloudExplorer with GNU General Public License v3.0 5 votes vote down vote up
Boolean VersioningStatus(String access_key, String secret_key, String bucket, String endpoint, Boolean enable) {
    String message = null;
    boolean result = false;
    AWSCredentials credentials = new BasicAWSCredentials(access_key, secret_key);
    AmazonS3 s3Client = new AmazonS3Client(credentials,
            new ClientConfiguration());

    if (endpoint.contains("amazonaws.com")) {
        String aws_endpoint = s3Client.getBucketLocation(new GetBucketLocationRequest(bucket));
        if (aws_endpoint.contains("US")) {
            s3Client.setEndpoint("https://s3.amazonaws.com");
        } else if (aws_endpoint.contains("us-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("eu-west")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("ap-")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else if (aws_endpoint.contains("sa-east-1")) {
            s3Client.setEndpoint("https://s3-" + aws_endpoint + ".amazonaws.com");
        } else {
            s3Client.setEndpoint("https://s3." + aws_endpoint + ".amazonaws.com");
        }
    } else {
        s3Client.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build());
        s3Client.setEndpoint(endpoint);
    }
    try {
        message = s3Client.getBucketVersioningConfiguration(bucket).getStatus().toString();
        if (message.contains("Enabled") || message.contains("Suspended")) {
            result = true;
        } else {
            result = false;
        }
    } catch (Exception versioning) {
    }

    return result;
}
 
Example #20
Source File: BasicAWSCredentialsProvider.java    From big-c with Apache License 2.0 5 votes vote down vote up
public AWSCredentials getCredentials() {
  if (!StringUtils.isEmpty(accessKey) && !StringUtils.isEmpty(secretKey)) {
    return new BasicAWSCredentials(accessKey, secretKey);
  }
  throw new AmazonClientException(
      "Access key or secret key is null");
}
 
Example #21
Source File: AbstractDynamoDBProcessor.java    From localization_nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Create client using AWSCredentials
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AmazonDynamoDBClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().debug("Creating client with aws credentials");

    final AmazonDynamoDBClient client = new AmazonDynamoDBClient(credentials, config);

    return client;
}
 
Example #22
Source File: S3PersistWriter.java    From streams with Apache License 2.0 5 votes vote down vote up
@Override
public void prepare(Object configurationObject) {

  lineWriterUtil = LineReadWriteUtil.getInstance(s3WriterConfiguration);

  // Connect to S3
  synchronized (this) {

    try {
      // if the user has chosen to not set the object mapper, then set a default object mapper for them.
      if (this.objectMapper == null) {
        this.objectMapper = StreamsJacksonMapper.getInstance();
      }

      // Create the credentials Object
      if (this.amazonS3Client == null) {
        AWSCredentials credentials = new BasicAWSCredentials(s3WriterConfiguration.getKey(), s3WriterConfiguration.getSecretKey());

        ClientConfiguration clientConfig = new ClientConfiguration();
        clientConfig.setProtocol(Protocol.valueOf(s3WriterConfiguration.getProtocol().toString()));

        // We do not want path style access
        S3ClientOptions clientOptions = new S3ClientOptions();
        clientOptions.setPathStyleAccess(false);

        this.amazonS3Client = new AmazonS3Client(credentials, clientConfig);
        if (StringUtils.isNotEmpty(s3WriterConfiguration.getRegion())) {
          this.amazonS3Client.setRegion(Region.getRegion(Regions.fromName(s3WriterConfiguration.getRegion())));
        }
        this.amazonS3Client.setS3ClientOptions(clientOptions);
      }
    } catch (Exception ex) {
      LOGGER.error("Exception while preparing the S3 client: {}", ex);
    }

    Preconditions.checkArgument(this.amazonS3Client != null);
  }
}
 
Example #23
Source File: DefaultGeoWaveAWSCredentialsProvider.java    From geowave with Apache License 2.0 5 votes vote down vote up
@Override
public AWSCredentials getCredentials() {
  try {
    return super.getCredentials();
  } catch (final SdkClientException exception) {

  }
  // fall back to anonymous credentials
  return new AnonymousAWSCredentials();
}
 
Example #24
Source File: BlobStoreManagedLedgerOffloaderTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Test
public void testSessionCredentialSupplier() throws Exception {
    PowerMockito.mockStatic(CredentialsUtil.class);
    PowerMockito.when(CredentialsUtil.getAWSCredentialProvider(any())).thenReturn(new AWSCredentialsProvider() {
        @Override
        public AWSCredentials getCredentials() {
            return new AWSSessionCredentials() {
                @Override
                public String getSessionToken() {
                    return "token";
                }

                @Override
                public String getAWSAccessKeyId() {
                    return "access";
                }

                @Override
                public String getAWSSecretKey() {
                    return "secret";
                }
            };
        }

        @Override
        public void refresh() {

        }
    });

    Supplier<Credentials> creds = BlobStoreManagedLedgerOffloader.getCredentials("aws-s3", any());

    Assert.assertTrue(creds.get() instanceof SessionCredentials);
    SessionCredentials sessCreds = (SessionCredentials) creds.get();
    Assert.assertEquals(sessCreds.getAccessKeyId(), "access");
    Assert.assertEquals(sessCreds.getSecretAccessKey(), "secret");
    Assert.assertEquals(sessCreds.getSessionToken(), "token");
}
 
Example #25
Source File: TerrapinUtil.java    From terrapin with Apache License 2.0 5 votes vote down vote up
static public List<Pair<Path, Long>> getS3FileList(AWSCredentials credentials,
    String s3Bucket, String s3KeyPrefix) {
  List<Pair<Path, Long>> fileSizePairList = Lists.newArrayListWithCapacity(
      Constants.MAX_ALLOWED_SHARDS);
  AmazonS3Client s3Client = new AmazonS3Client(credentials);
  // List files and build the path using the s3n: prefix.
  // Note that keys > marker are retrieved where the > is by lexicographic order.
  String prefix = s3KeyPrefix;
  String marker = prefix;
  while (true) {
    boolean reachedEnd = false;
    ObjectListing listing = s3Client.listObjects(new ListObjectsRequest().
        withBucketName(s3Bucket).
        withMarker(marker));
    List<S3ObjectSummary> summaries = listing.getObjectSummaries();

    if (summaries.isEmpty()) {
      break;
    }

    for (S3ObjectSummary summary: summaries) {
      if (summary.getKey().startsWith(prefix)) {
        fileSizePairList.add(new ImmutablePair(new Path("s3n", s3Bucket, "/" + summary.getKey()),
            summary.getSize()));
        if (fileSizePairList.size() > Constants.MAX_ALLOWED_SHARDS) {
          throw new RuntimeException("Too many files " + fileSizePairList.size());
        }
      } else {
        // We found a key which does not match the prefix, stop.
        reachedEnd = true;
        break;
      }
    }
    if (reachedEnd) {
      break;
    }
    marker = summaries.get(summaries.size() - 1).getKey();
  }
  return fileSizePairList;
}
 
Example #26
Source File: AwsCredentialsFactory.java    From sequenceiq-samples with Apache License 2.0 5 votes vote down vote up
public AWSCredentials createSimpleAWSCredentials(String accessKey, String secretAccessKey) {
	String aKey = accessKey;
	String sAccessKey = secretAccessKey;
	try {
		aKey = URLDecoder.decode(aKey, ("UTF-8"));
		sAccessKey = URLDecoder.decode(sAccessKey, ("UTF-8"));
	} catch (UnsupportedEncodingException e) {
		System.out.println(aKey + ":" + sAccessKey + e.getMessage());
	}
	return new SimpleAWSCredentials(aKey, sAccessKey);
}
 
Example #27
Source File: AbstractSQSProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Create client using AWSCredentials
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AmazonSQSClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().info("Creating client using aws credentials ");

    return new AmazonSQSClient(credentials, config);
}
 
Example #28
Source File: AbstractKinesisStreamProcessor.java    From nifi with Apache License 2.0 5 votes vote down vote up
/**
 * Create client using AWSCredentails
 *
 * @deprecated use {@link #createClient(ProcessContext, AWSCredentialsProvider, ClientConfiguration)} instead
 */
@Override
protected AmazonKinesisClient createClient(final ProcessContext context, final AWSCredentials credentials, final ClientConfiguration config) {
    getLogger().info("Creating client using aws credentials");

    return new AmazonKinesisClient(credentials, config);
}
 
Example #29
Source File: PooledS3Connection.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public AWSCredentials getCredentials() {
          try {
              return super.getCredentials();
          } catch (AmazonClientException ace) {
              return null; // fall back to anonymous
          }
}
 
Example #30
Source File: AWSCredentialsConfigurator.java    From cyberduck with GNU General Public License v3.0 5 votes vote down vote up
public static AWSCredentialsProvider toAWSCredentialsProvider(final Credentials credentials) {
    return credentials.isTokenAuthentication() ?
        new AWSSessionCredentialsProvider() {
            @Override
            public AWSSessionCredentials getCredentials() {
                return new AWSSessionCredentials() {
                    @Override
                    public String getSessionToken() {
                        return credentials.getToken();
                    }

                    @Override
                    public String getAWSAccessKeyId() {
                        return credentials.getUsername();
                    }

                    @Override
                    public String getAWSSecretKey() {
                        return credentials.getPassword();
                    }
                };
            }

            @Override
            public void refresh() {
                // Not supported
            }
        } :
        new AWSStaticCredentialsProvider(new AWSCredentials() {
            @Override
            public String getAWSAccessKeyId() {
                return credentials.getUsername();
            }

            @Override
            public String getAWSSecretKey() {
                return credentials.getPassword();
            }
        });
}