@Override protected void obtainResource() throws Exception { // See https://github.com/mhart/kinesalite#cbor-protocol-issues-with-the-java-sdk System.setProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY, "true"); this.resource = AmazonKinesisAsyncClientBuilder.standard() .withClientConfiguration( new ClientConfiguration() .withMaxErrorRetry(0) .withConnectionTimeout(1000)) .withEndpointConfiguration( new AwsClientBuilder.EndpointConfiguration("http://localhost:" + this.port, Regions.DEFAULT_REGION.getName())) .withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("", ""))) .build(); // Check connection this.resource.listStreams(); }
private Registry<ConnectionSocketFactory> createSocketFactoryRegistry(ConnectionSocketFactory sslSocketFactory) { /* * If SSL cert checking for endpoints has been explicitly disabled, * register a new scheme for HTTPS that won't cause self-signed certs to * error out. */ if (SDKGlobalConfiguration.isCertCheckingDisabled()) { if (LOG.isWarnEnabled()) { LOG.warn("SSL Certificate checking for endpoints has been " + "explicitly disabled."); } sslSocketFactory = new TrustingSocketFactory(); } return RegistryBuilder.<ConnectionSocketFactory>create() .register("http", PlainConnectionSocketFactory.getSocketFactory()) .register("https", sslSocketFactory) .build(); }
/** * Reads the specified input stream as a stream of Java properties file * content and extracts the AWS access key ID and secret access key from the * properties. * * @param inputStream * The input stream containing the AWS credential properties. * * @throws IOException * If any problems occur while reading from the input stream. */ public PropertiesCredentials(InputStream inputStream) throws IOException { Properties accountProperties = new Properties(); try { accountProperties.load(inputStream); } finally { try {inputStream.close();} catch (Exception e) {} } if ((accountProperties.getProperty(SDKGlobalConfiguration.IBM_API_KEY_SYSTEM_PROPERTY) == null) && (accountProperties.getProperty("accessKey") == null || accountProperties.getProperty("secretKey") == null)) { throw new IllegalArgumentException("The specified properties data " + "doesn't contain the expected properties 'accessKey' and 'secretKey'."); } accessKey = accountProperties.getProperty("accessKey"); secretAccessKey = accountProperties.getProperty("secretKey"); ibmApiKey = accountProperties.getProperty(SDKGlobalConfiguration.IBM_API_KEY_SYSTEM_PROPERTY); ibmServiceInstanceId = accountProperties.getProperty(SDKGlobalConfiguration.IBM_SERVICE_INSTANCE_ID_SYSTEM_PROPERTY); }
/** * Mock TokenProvider to throw OAuthServiceException on token retrieval. * Check that TokenManager retries up to the max number of retry attempts. */ @Test public void shouldRetryTokenRetrievalNoMoreThanMax() { OAuthServiceException exception = new OAuthServiceException( "Token retrival from IAM service failed with refresh token"); exception.setStatusCode(429); exception.setStatusMessage("Too many requests"); TokenProvider tokenProviderMock = mock(TokenProvider.class); when(tokenProviderMock.retrieveToken()).thenThrow(exception); defaultTokenManager = new DefaultTokenManager(tokenProviderMock); try { defaultTokenManager.getToken(); fail("Should have thrown an OAuthServiceException"); } catch (OAuthServiceException expected) { assertEquals(SDKGlobalConfiguration.IAM_MAX_RETRY, Mockito.mockingDetails(tokenProviderMock).getInvocations().size()); } }
/** * Mock TokenProvider to return non expiring token. * Token manager should not attempt to refresh. */ @Test public void shouldNotRefreshToken() { int extraTime = (int) (3600 * SDKGlobalConfiguration.IAM_REFRESH_OFFSET); long expiry = (System.currentTimeMillis() / 1000L) + (extraTime * 3); Token token = new Token(); token.setAccess_token(accessToken); token.setRefresh_token(refreshToken); token.setToken_type("Bearer"); token.setExpires_in("3600"); token.setExpiration(String.valueOf(expiry)); TokenProvider tokenProviderMock = mock(TokenProvider.class); DefaultTokenManager defaultTokenManager = spy(new DefaultTokenManager(tokenProviderMock)); when(defaultTokenManager.getProvider()).thenReturn(tokenProviderMock); when(tokenProviderMock.retrieveToken()).thenReturn(token); Mockito.doNothing().when(defaultTokenManager).submitRefreshTask(); defaultTokenManager.getToken(); verify(defaultTokenManager, times(0)).submitRefreshTask(); }
/** * Returns the buffer size override if it is specified in the system property, * otherwise returns the default value. */ @Deprecated public static int getStreamBufferSize() { int streamBufferSize = DEFAULT_STREAM_BUFFER_SIZE; String bufferSizeOverride = System.getProperty(SDKGlobalConfiguration.DEFAULT_S3_STREAM_BUFFER_SIZE); if (bufferSizeOverride != null) { try { streamBufferSize = Integer.parseInt(bufferSizeOverride); } catch (Exception e) { log.warn("Unable to parse buffer size override from value: " + bufferSizeOverride); } } return streamBufferSize; }
@Override public void init(Configuration conf, String keyPrefix) { bucketName = conf.get(keyPrefix + S3_BUCKET_NAME); String endpoint = conf.get(keyPrefix + S3_ENDPOINT_NAME); String key = conf.get(keyPrefix + S3_ACCESS_KEY); String secret = conf.get(keyPrefix + S3_ACCESS_SECRET); System.setProperty(SDKGlobalConfiguration.ACCESS_KEY_SYSTEM_PROPERTY, key); System.setProperty(SDKGlobalConfiguration.SECRET_KEY_SYSTEM_PROPERTY, secret); AWSCredentialsProvider provider = new SystemPropertiesCredentialsProvider(); client = new AmazonS3Client(provider); client.setEndpoint(endpoint); override = conf.getBoolean(keyPrefix + "override", true); acls = new AccessControlList(); acls.grantPermission(GroupGrantee.AllUsers, Permission.FullControl); acls.grantPermission(GroupGrantee.AllUsers, Permission.Read); acls.grantPermission(GroupGrantee.AllUsers, Permission.Write); }
@Before public void before() { boolean configured = !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)) && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR)) && !StringUtils.isEmpty(System.getProperty("bucketName")); if ( !configured ) { logger.warn("Skipping test because {}, {} and bucketName not " + "specified as system properties, e.g. in your Maven settings.xml file.", new Object[] { SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR }); } Assume.assumeTrue( configured ); adminUser = newOrgAppAdminRule.getAdminInfo(); organization = newOrgAppAdminRule.getOrganizationInfo(); applicationId = newOrgAppAdminRule.getApplicationInfo().getId(); bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase(); }
/** * Delete the configured s3 bucket. */ public void deleteBucket() { logger.debug("\n\nDelete bucket\n"); String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); final Iterable<? extends Module> MODULES = ImmutableSet .of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES) .overrides(overrides).buildView(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); blobStore.deleteContainer( bucketName ); }
@Before public void before() { boolean configured = !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)) && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR)) && !StringUtils.isEmpty(System.getProperty("bucketName")); if ( !configured ) { logger.warn("Skipping test because {}, {} and bucketName not " + "specified as system properties, e.g. in your Maven settings.xml file.", new Object[] { SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR }); } Assume.assumeTrue( configured ); }
public HashMap<String, Object> payloadBuilder() { HashMap<String, Object> payload = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> storage_info = new HashMap<String, Object>(); storage_info.put( "bucket_location", bucketName ); storage_info.put( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ) ); storage_info.put( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ) ); properties.put( "storage_provider", "s3" ); properties.put( "storage_info", storage_info ); payload.put( "path","test-organization/test-app" ); payload.put( "properties", properties ); return payload; }
public void deleteBucket() { String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ); Properties overrides = new Properties(); overrides.setProperty( "s3" + ".identity", accessId ); overrides.setProperty( "s3" + ".credential", secretKey ); Blob bo = null; BlobStore blobStore = null; final Iterable<? extends Module> MODULES = ImmutableSet .of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials( accessId, secretKey ).modules( MODULES ) .overrides( overrides ).buildView( BlobStoreContext.class ); blobStore = context.getBlobStore(); blobStore.deleteContainer( bucketName ); }
@Before public void before() { boolean configured = !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)) && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR)) && !StringUtils.isEmpty(System.getProperty("bucketName")); if ( !configured ) { logger.warn("Skipping test because {}, {} and bucketName not " + "specified as system properties, e.g. in your Maven settings.xml file.", new Object[] { SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR }); } Assume.assumeTrue( configured ); adminUser = newOrgAppAdminRule.getAdminInfo(); organization = newOrgAppAdminRule.getOrganizationInfo(); applicationId = newOrgAppAdminRule.getApplicationInfo().getId(); bucketPrefix = System.getProperty( "bucketName" ); bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase(); }
public HashMap<String, Object> payloadBuilder( String orgOrAppName ) { HashMap<String, Object> payload = new HashMap<String, Object>(); Map<String, Object> properties = new HashMap<String, Object>(); Map<String, Object> storage_info = new HashMap<String, Object>(); storage_info.put( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ) ); storage_info.put( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ) ); storage_info.put( "bucket_location", bucketName ); properties.put( "storage_provider", "s3" ); properties.put( "storage_info", storage_info ); payload.put( "path", orgOrAppName ); payload.put( "properties", properties ); return payload; }
@Before public void before() { configured = !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR )) && !StringUtils.isEmpty(System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR )) && !StringUtils.isEmpty(System.getProperty("bucketName")); if (!configured) { logger.warn("Skipping test because {}, {} and bucketName not " + "specified as system properties, e.g. in your Maven settings.xml file.", new Object[]{ "s3_key", "s3_access_id" }); } // if (!StringUtils.isEmpty(bucketPrefix)) { // deleteBucketsWithPrefix(); // } bucketName = bucketPrefix + RandomStringUtils.randomAlphanumeric(10).toLowerCase(); }
/** * Delete the configured s3 bucket. */ public void deleteBucket() { logger.debug("\n\nDelete bucket\n"); String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); final Iterable<? extends Module> MODULES = ImmutableSet.of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES) .overrides(overrides ).buildView(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); blobStore.deleteContainer(bucketName); }
public Entity payloadBuilder() { String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ); Entity storage_info = new Entity(); storage_info.put("s3_key", secretKey); storage_info.put("s3_access_id", accessId); storage_info.put("bucket_location", bucketName) ; Entity properties = new Entity(); properties.put("storage_provider", "s3"); properties.put("storage_info", storage_info); Entity payload = new Entity(); payload.put("properties", properties); return payload; }
@Override public File getLocation() { String overrideLocation = System.getenv(SDKGlobalConfiguration.AWS_CONFIG_FILE_ENV_VAR); if (overrideLocation != null) { return new File(overrideLocation); } return null; }
/** * Reads the specified file as a Java properties file and extracts the * AWS access key from the "accessKey" property and AWS secret access * key from the "secretKey" property. If the specified file doesn't * contain the AWS access keys an IOException will be thrown. * * @param file * The file from which to read the AWS credentials * properties. * * @throws FileNotFoundException * If the specified file isn't found. * @throws IOException * If any problems are encountered reading the AWS access * keys from the specified file. * @throws IllegalArgumentException * If the specified properties file does not contain the * required keys. */ public PropertiesCredentials(File file) throws FileNotFoundException, IOException, IllegalArgumentException { if (!file.exists()) { throw new FileNotFoundException("File doesn't exist: " + file.getAbsolutePath()); } FileInputStream stream = new FileInputStream(file); try { Properties accountProperties = new Properties(); accountProperties.load(stream); if ((accountProperties.getProperty(SDKGlobalConfiguration.IBM_API_KEY_SYSTEM_PROPERTY) == null) && (accountProperties.getProperty("accessKey") == null || accountProperties.getProperty("secretKey") == null)) { throw new IllegalArgumentException( "The specified file (" + file.getAbsolutePath() + ") doesn't contain the expected properties 'accessKey' " + "and 'secretKey'." ); } accessKey = accountProperties.getProperty("accessKey"); secretAccessKey = accountProperties.getProperty("secretKey"); ibmApiKey = accountProperties.getProperty(SDKGlobalConfiguration.IBM_API_KEY_SYSTEM_PROPERTY); ibmServiceInstanceId = accountProperties.getProperty(SDKGlobalConfiguration.IBM_SERVICE_INSTANCE_ID_SYSTEM_PROPERTY); } finally { try { stream.close(); } catch (IOException e) { } } }
@Override public AWSCredentials getCredentials() { //Load IBM properties String accessKey = StringUtils.trim(System.getProperty(ACCESS_KEY_SYSTEM_PROPERTY)); String secretKey = StringUtils.trim(System.getProperty(SECRET_KEY_SYSTEM_PROPERTY)); String apiKey = StringUtils.trim(System.getProperty(SDKGlobalConfiguration.IBM_API_KEY_SYSTEM_PROPERTY)); String serviceInstance = StringUtils.trim(System.getProperty(SDKGlobalConfiguration.IBM_SERVICE_INSTANCE_ID_SYSTEM_PROPERTY)); if (!StringUtils.isNullOrEmpty(apiKey) && tokenManager == null) { BasicIBMOAuthCredentials oAuthCreds = new BasicIBMOAuthCredentials(apiKey, serviceInstance); tokenManager = oAuthCreds.getTokenManager(); return oAuthCreds; } else if ((!StringUtils.isNullOrEmpty(apiKey) && tokenManager != null)) { return new BasicIBMOAuthCredentials(tokenManager, serviceInstance); } if (StringUtils.isNullOrEmpty(accessKey) || StringUtils.isNullOrEmpty(secretKey)) { throw new SdkClientException( "Unable to load AWS credentials from Java system " + "properties (" + ACCESS_KEY_SYSTEM_PROPERTY + " and " + SECRET_KEY_SYSTEM_PROPERTY + ")"); } return new BasicAWSCredentials(accessKey, secretKey); }
@BeforeClass public static void setupFixture() throws IOException { server = new EC2MetadataUtilsServer("localhost", 0); server.start(); System.setProperty(SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY, "http://localhost:" + server.getLocalPort()); }
@BeforeClass public static void setUp() throws IOException { SERVER = new EC2MetadataUtilsServer("localhost", 0); SERVER.start(); System.setProperty( SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY, "http://localhost:" + SERVER.getLocalPort()); }
@AfterClass public static void cleanUp() throws IOException { if (SERVER != null) { SERVER.stop(); } System.clearProperty(SDKGlobalConfiguration.EC2_METADATA_SERVICE_OVERRIDE_SYSTEM_PROPERTY); }
private void validateRequestBeforeTransmit(Request<?> request) { boolean implicitCrossRegionForbidden = areImplicitGlobalClientsDisabled(); boolean explicitCrossRegionEnabled = clientOptions.isForceGlobalBucketAccessEnabled(); // The region must be set if implicit cross region clients are not allowed if (noExplicitRegionProvided(request) && implicitCrossRegionForbidden && !explicitCrossRegionEnabled) { String error = String.format("While the %s system property is enabled, Amazon S3 clients cannot be used without " + "first configuring a region or explicitly enabling global bucket access discovery " + "in the S3 client builder.", SDKGlobalConfiguration.DISABLE_S3_IMPLICIT_GLOBAL_CLIENTS_SYSTEM_PROPERTY); throw new IllegalStateException(error); } }
/** * Returns the value of the system property * {@link SDKGlobalConfiguration#DEFAULT_S3_STREAM_BUFFER_SIZE} as an * Integer; or null if not set. This method exists for backward * compatibility reasons. */ public static Integer getS3StreamBufferSize() { String s = System.getProperty(SDKGlobalConfiguration.DEFAULT_S3_STREAM_BUFFER_SIZE); if (s == null) return null; try { return Integer.valueOf(s); } catch (Exception e) { log.warn("Unable to parse buffer size override from value: " + s); } return null; }
/** * @return true if the cached Cognito credentials are expired, otherwise false. */ public boolean areCredentialsExpired() { final Date credentialsExpirationDate = credentialsProvider.getSessionCredentitalsExpiration(); if (credentialsExpirationDate == null) { return true; } long currentTime = System.currentTimeMillis() - (long)(SDKGlobalConfiguration.getGlobalTimeOffset() * 1000); return (credentialsExpirationDate.getTime() - currentTime) < 0; }
/** * Start export job that wilk export a specific collection to the S3 bucket. */ private void exportCollection( final EntityManager em, final String collectionName ) throws Exception { logger.debug("\n\nExporting {} collection from application {}\n", collectionName, em.getApplication().getName() ); setup.getEntityIndex().refresh(em.getApplicationId()); ExportService exportService = setup.getExportService(); UUID exportUUID = exportService.schedule( new HashMap<String, Object>() {{ put( "path", organization.getName() + em.getApplication().getName()); put( "organizationId", organization.getUuid()); put( "applicationId", em.getApplication().getUuid() ); put( "collectionName", collectionName); put( "properties", new HashMap<String, Object>() {{ put( "storage_provider", "s3" ); put( "storage_info", new HashMap<String, Object>() {{ put( "s3_access_id", System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR) ); put("s3_key", System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR)); put( "bucket_location", bucketName ); }}); }}); }}); int maxRetries = 30; int retries = 0; while ( !exportService.getState( exportUUID ).equals( "FINISHED" ) && retries++ < maxRetries ) { logger.debug("Waiting for export..."); Thread.sleep(1000); } if ( retries >= maxRetries ) { throw new RuntimeException("Max retries reached"); } }
private static void deleteBucketsWithPrefix() { logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix ); String accessId = System.getProperty(SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); String secretKey = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); final Iterable<? extends Module> MODULES = ImmutableSet .of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES) .overrides(overrides).buildView(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list(); for ( Object o : blobStoreList.toArray() ) { StorageMetadata s = (StorageMetadata)o; if ( s.getName().startsWith( bucketPrefix )) { try { blobStore.deleteContainer(s.getName()); } catch ( ContainerNotFoundException cnfe ) { logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe ); } logger.debug("Deleted bucket {}", s.getName()); } } }
@Test public void errorCheckingMissingProperties() throws Exception { Map<String, Object> errorTestProperties; errorTestProperties = getRemoteTestProperties(); //test that we fail gracefully if we have missing properties setTestProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "xxx" ); try { Map<String, String> payload = hashMap( "name", "assetname" ); ApiResponse postResponse = pathResource( getOrgAppPath( "foos" ) ).post( payload ); UUID assetId = postResponse.getEntities().get( 0 ).getUuid(); assertNotNull( assetId ); // post a binary asset to that entity byte[] data = IOUtils.toByteArray( getClass().getResourceAsStream( "/cassandra_eye.jpg" ) ); ApiResponse putResponse = pathResource( getOrgAppPath( "foos/" + assetId ) ).put( data, MediaType.APPLICATION_OCTET_STREAM_TYPE ); }catch ( AwsPropertiesNotFoundException e ){ fail("Shouldn't interrupt runtime if access key isnt found."); } catch( ClientErrorException uie){ assertEquals(500,uie.getResponse().getStatus()); } finally{ setTestProperties( errorTestProperties ); } }
@Test public void errorCheckingInvalidProperties() throws Exception { Map<String, Object> errorTestProperties; errorTestProperties = getRemoteTestProperties(); //test that we fail gracefully if we have missing properties setTestProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR, "xxx"); setTestProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR, "xxx" ); setTestProperty( "usergrid.binary.bucketname", "xxx" ); try { Map<String, String> payload = hashMap( "name", "assetname" ); ApiResponse postResponse = pathResource( getOrgAppPath( "foos" ) ).post( payload ); UUID assetId = postResponse.getEntities().get( 0 ).getUuid(); assertNotNull( assetId ); // post a binary asset to that entity byte[] data = IOUtils.toByteArray( getClass().getResourceAsStream( "/cassandra_eye.jpg" ) ); ApiResponse putResponse = pathResource( getOrgAppPath( "foos/" + assetId ) ).put( data, MediaType.APPLICATION_OCTET_STREAM_TYPE ); }catch ( AwsPropertiesNotFoundException e ){ fail("Shouldn't interrupt runtime if access key isnt found."); } catch( InternalServerErrorException uie){ assertEquals( 500, uie.getResponse().getStatus() ); } finally{ setTestProperties( errorTestProperties ); } }
private static void deleteBucketsWithPrefix() { logger.debug("\n\nDelete buckets with prefix {}\n", bucketPrefix); String accessId = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); String secretKey = System.getProperty( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ); Properties overrides = new Properties(); overrides.setProperty("s3" + ".identity", accessId); overrides.setProperty("s3" + ".credential", secretKey); final Iterable<? extends Module> MODULES = ImmutableSet .of(new JavaUrlHttpCommandExecutorServiceModule(), new Log4JLoggingModule(), new NettyPayloadModule()); BlobStoreContext context = ContextBuilder.newBuilder("s3").credentials(accessId, secretKey).modules(MODULES) .overrides(overrides ).buildView(BlobStoreContext.class); BlobStore blobStore = context.getBlobStore(); final PageSet<? extends StorageMetadata> blobStoreList = blobStore.list(); for (Object o : blobStoreList.toArray()) { StorageMetadata s = (StorageMetadata) o; if (s.getName().startsWith(bucketPrefix)) { try { blobStore.deleteContainer(s.getName()); } catch (ContainerNotFoundException cnfe) { logger.warn("Attempted to delete bucket {} but it is already deleted", cnfe); } logger.debug("Deleted bucket {}", s.getName()); } } }
@Override public String getAWSAccessKeyId() { String accessKey = System.getProperty( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR); if( StringUtils.isEmpty( accessKey )){ accessKey = System.getProperty(SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR); } return StringUtils.trim(accessKey); }
@Override public String getAWSSecretKey() { String secret = System.getProperty(SDKGlobalConfiguration.SECRET_KEY_ENV_VAR); if(StringUtils.isEmpty(secret)){ secret = System.getProperty(SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR); } return StringUtils.trim(secret); }
public String getAWSAccessKeyIdJson(Map<String,Object> jsonObject){ String accessKey = (String) jsonObject.get( SDKGlobalConfiguration.ACCESS_KEY_ENV_VAR ); if ( StringUtils.isEmpty( accessKey ) ){ accessKey = (String) jsonObject.get( SDKGlobalConfiguration.ALTERNATE_ACCESS_KEY_ENV_VAR ); } if(StringUtils.isEmpty(accessKey)){ throw new AmazonClientException("Could not get aws access key from json object."); } return StringUtils.trim( accessKey ); }
public String getAWSSecretKeyJson(Map<String,Object> jsonObject){ String secretKey = (String) jsonObject.get( SDKGlobalConfiguration.SECRET_KEY_ENV_VAR ); if ( StringUtils.isEmpty( secretKey ) ){ secretKey = (String) jsonObject.get( SDKGlobalConfiguration.ALTERNATE_SECRET_KEY_ENV_VAR ); } if(StringUtils.isEmpty(secretKey)){ throw new AmazonClientException("Could not get aws secret key from json object."); } return StringUtils.trim( secretKey ); }
@Override protected void cleanupResource() throws Exception { System.clearProperty(SDKGlobalConfiguration.AWS_CBOR_DISABLE_SYSTEM_PROPERTY); this.resource.shutdown(); }
private boolean isCborEnabled() { return metadata.isSupportsCbor() && !SDKGlobalConfiguration.isCborDisabled(); }
boolean isIonBinaryEnabled() { return !SDKGlobalConfiguration.isIonBinaryDisabled(); }
public String getIBMApiKey() { return getPropertyValue(SDKGlobalConfiguration.IBM_API_KEY_SYSTEM_PROPERTY); }
public String getIBMServiceInstanceId() { return getPropertyValue(SDKGlobalConfiguration.IBM_SERVICE_INSTANCE_ID_SYSTEM_PROPERTY); }