Refine search
String storageConnectionString = String.format(AzureStorageUtils.FORMAT_BASE_URI, accountName); StorageCredentials creds = new StorageCredentialsSharedAccessSignature(sasToken); cloudBlobClient = new CloudBlobClient(new URI(storageConnectionString), creds); } else { String blobConnString = String.format(AzureStorageUtils.FORMAT_BLOB_CONNECTION_STRING, accountName, accountKey); CloudStorageAccount storageAccount = CloudStorageAccount.parse(blobConnString); cloudBlobClient = storageAccount.createCloudBlobClient();
public void init() { try { String endpoint = String.format(ENDPOINT_TEMPLATE, configuration.getAccountName()); CloudStorageAccount cosmosAccount = CloudStorageAccount.parse( String.format( COSMOS_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getAccountKey(), endpoint)); tableClient = cosmosAccount.createCloudTableClient(); // Create the tables if the do not exist tableClient.getTableReference(JOB_TABLE).createIfNotExists(); tableClient.getTableReference(JOB_DATA_TABLE).createIfNotExists(); CloudStorageAccount blobAccount = CloudStorageAccount.parse( String.format( BLOB_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getBlobKey())); blobClient = blobAccount.createCloudBlobClient(); blobClient.getContainerReference(BLOB_CONTAINER).createIfNotExists(); } catch (StorageException | URISyntaxException | InvalidKeyException e) { throw new MicrosoftStorageException(e); } }
connectionString = String.format(FORMAT_QUEUE_BASE_URI, storageAccountName); StorageCredentials storageCredentials = new StorageCredentialsSharedAccessSignature(sasToken); cloudQueueClient = new CloudQueueClient(new URI(connectionString), storageCredentials); } else { connectionString = String.format(FORMAT_QUEUE_CONNECTION_STRING, storageAccountName, storageAccountKey); CloudStorageAccount storageAccount = CloudStorageAccount.parse(connectionString); cloudQueueClient = storageAccount.createCloudQueueClient();
public AzureUploadManager(SecorConfig config) throws Exception { super(config); final String storageConnectionString = "DefaultEndpointsProtocol=" + mConfig.getAzureEndpointsProtocol() + ";" + "AccountName=" + mConfig.getAzureAccountName() + ";" + "AccountKey=" + mConfig.getAzureAccountKey() + ";"; CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); blobClient = storageAccount.createCloudBlobClient(); }
String storageConnectionString = getStorageConnectionString(protocol, account, key, tableEndPoint); try { storageAccount = CloudStorageAccount.parse(storageConnectionString); } catch (Exception e) { throw new DBException("Could not connect to the account.\n", e); tableClient = storageAccount.createCloudTableClient(); try { cloudTable = tableClient.getTableReference(table);
public static CloudQueueClient createCloudQueueClient(SharedAccessAccountPolicy policy, boolean useHttps) throws StorageException, InvalidKeyException, URISyntaxException { CloudStorageAccount sasAccount = getAccount(); final String token = sasAccount.generateSharedAccessSignature(policy); final StorageCredentials creds = new StorageCredentialsSharedAccessSignature(token); final URI queueUri = new URI(useHttps ? "https" : "http", sasAccount.getQueueEndpoint().getAuthority(), sasAccount.getQueueEndpoint().getPath(), sasAccount.getQueueEndpoint().getQuery(), null); sasAccount = new CloudStorageAccount(creds, sasAccount.getBlobEndpoint(), queueUri, sasAccount.getTableEndpoint(), sasAccount.getFileEndpoint()); return sasAccount.createCloudQueueClient(); }
@Test public void testDevelopmentStorageWithTwoUris() throws URISyntaxException { CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); URI primaryClientURI = account.getBlobStorageUri().getPrimaryUri(); URI primaryContainerURI = new URI(primaryClientURI.toString() + "/container"); URI secondaryClientURI = account.getBlobStorageUri().getSecondaryUri(); StorageUri singleURI = new StorageUri(primaryClientURI); assertTrue(primaryClientURI.equals(singleURI.getPrimaryUri())); assertNull(singleURI.getSecondaryUri()); StorageUri singleURI2 = new StorageUri(primaryClientURI); assertTrue(singleURI.equals(singleURI2)); StorageUri singleURI3 = new StorageUri(secondaryClientURI); assertFalse(singleURI.equals(singleURI3)); StorageUri multiURI = new StorageUri(primaryClientURI, secondaryClientURI); assertTrue(primaryClientURI.equals(multiURI.getPrimaryUri())); assertTrue(secondaryClientURI.equals(multiURI.getSecondaryUri())); assertFalse(multiURI.equals(singleURI)); StorageUri multiURI2 = new StorageUri(primaryClientURI, secondaryClientURI); assertTrue(multiURI.equals(multiURI2)); try { new StorageUri(primaryClientURI, primaryContainerURI); fail("StorageUri constructor should fail if both URIs do not point to the same resource"); } catch (IllegalArgumentException e) { assertEquals(SR.STORAGE_URI_MUST_MATCH, e.getMessage()); } StorageUri multiURI3 = new StorageUri(secondaryClientURI, primaryClientURI); assertFalse(multiURI.equals(multiURI3)); }
@Test public void testIsUsePathStyleUri() throws InvalidKeyException, URISyntaxException, StorageException { // normal account StorageCredentials creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); CloudStorageAccount account = new CloudStorageAccount(creds); testIsUsePathStyleUri(creds, account.getTableEndpoint().toString(), false); // normal account with path creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); account = new CloudStorageAccount(creds); testIsUsePathStyleUri(creds, account.getTableEndpoint().toString() + "/mytable", false); // custom endpoint creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); testIsUsePathStyleUri(creds, "http://www.contoso.com", false); // dev store account = CloudStorageAccount.getDevelopmentStorageAccount(); testIsUsePathStyleUri(account.getCredentials(), account.getTableEndpoint().toString(), true); // dev store with proxy account = CloudStorageAccount.getDevelopmentStorageAccount(new URI("http://ipv4.fiddler")); testIsUsePathStyleUri(account.getCredentials(), account.getTableEndpoint().toString(), true); // custom endpoints ipv4 with path-style (internal test) creds = new StorageCredentialsAccountAndKey("testAccountName", "/g6UPBuy0ypCpAbYTL6/KA+dI/7gyoWvLFYmah3IviUP1jykOHHOlA=="); testIsUsePathStyleUri(creds, "http://93.184.216.119/testAccountName", true); }
@Test public void testCloudStorageAccountDefaultStorageAccountWithHttps() throws URISyntaxException, InvalidKeyException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); assertEquals(cloudStorageAccount.getBlobEndpoint(), new URI(String.format("https://%s.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueEndpoint(), new URI(String.format("https://%s.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableEndpoint(), new URI(String.format("https://%s.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileEndpoint(), new URI(String.format("https://%s.file.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getBlobStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.blob.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getQueueStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.queue.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getTableStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.table.core.windows.net", ACCOUNT_NAME))); assertEquals(cloudStorageAccount.getFileStorageUri().getSecondaryUri(), new URI(String.format("https://%s-secondary.file.core.windows.net", ACCOUNT_NAME))); String cloudStorageAccountToStringWithSecrets = cloudStorageAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(cloudStorageAccountToStringWithSecrets); AccountsAreEqual(testAccount, cloudStorageAccount); }
/** * Evaluates connection settings and returns a CloudStorageAccount representing Development Storage. * * @param settings * A <code>java.util.Map</code> of key/value pairs which represents the connection settings. * @return A {@link CloudStorageAccount} object constructed from the values provided in the connection settings, or * null if * one cannot be constructed. * @throws URISyntaxException * if the connection settings contains an invalid URI */ private static CloudStorageAccount tryConfigureDevStore(final Map<String, String> settings) throws URISyntaxException { if (matchesSpecification( settings, allRequired(USE_DEVELOPMENT_STORAGE_NAME), optional(DEVELOPMENT_STORAGE_PROXY_URI_NAME))) { if (!Boolean.parseBoolean(settings.get(USE_DEVELOPMENT_STORAGE_NAME))) { throw new IllegalArgumentException(SR.INVALID_CONNECTION_STRING_DEV_STORE_NOT_TRUE); } URI devStoreProxyUri = null; if (settings.containsKey(DEVELOPMENT_STORAGE_PROXY_URI_NAME)) { devStoreProxyUri = new URI(settings.get(DEVELOPMENT_STORAGE_PROXY_URI_NAME)); } return getDevelopmentStorageAccount(devStoreProxyUri); } else { return null; } }
@Test public void testCloudStorageAccountWithStorageUri() throws URISyntaxException, InvalidKeyException { StorageUri blobEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + BLOB_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + BLOB_SERVICE + ENDPOINT_SUFFIX)); StorageUri queueEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + QUEUE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + QUEUE_SERVICE + ENDPOINT_SUFFIX)); StorageUri tableEndpoint = new StorageUri(new URI("http://" + ACCOUNT_NAME + TABLE_SERVICE + ENDPOINT_SUFFIX), new URI("http://" + ACCOUNT_NAME + SECONDARY_SUFFIX + TABLE_SERVICE + ENDPOINT_SUFFIX)); CloudStorageAccount account = CloudStorageAccount.parse(String.format( "DefaultEndpointsProtocol=http;AccountName=%s;AccountKey=dummyKey", ACCOUNT_NAME)); assertEquals(blobEndpoint, account.getBlobStorageUri()); assertEquals(queueEndpoint, account.getQueueStorageUri()); assertEquals(tableEndpoint, account.getTableStorageUri()); assertEquals(blobEndpoint, account.createCloudBlobClient().getStorageUri()); assertEquals(queueEndpoint, account.createCloudQueueClient().getStorageUri()); assertEquals(tableEndpoint, account.createCloudTableClient().getStorageUri()); assertEquals(blobEndpoint.getPrimaryUri(), account.getBlobEndpoint()); assertEquals(queueEndpoint.getPrimaryUri(), account.getQueueEndpoint()); assertEquals(tableEndpoint.getPrimaryUri(), account.getTableEndpoint()); }
@Test public void testCloudStorageAccountAnonymousRoundtrip() throws InvalidKeyException, URISyntaxException { String accountString = "BlobEndpoint=http://blobs/"; assertEquals(accountString, CloudStorageAccount.parse(accountString).toString(true)); CloudStorageAccount account = new CloudStorageAccount( null, new StorageUri(new URI("http://blobs/")), null, null, null); AccountsAreEqual(account, CloudStorageAccount.parse(account.toString(true))); }
@Test public void testCloudStorageAccountDevStoreProxyUri() throws InvalidKeyException, URISyntaxException { CloudStorageAccount account = CloudStorageAccount .parse("UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://ipv4.fiddler"); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
@Test public void testCloudStorageAccountDevelopmentStorageAccount() throws InvalidKeyException, URISyntaxException { CloudStorageAccount devstoreAccount = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(devstoreAccount.getBlobStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10000/devstoreaccount1")); assertEquals(devstoreAccount.getQueueStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10001/devstoreaccount1")); assertEquals(devstoreAccount.getTableStorageUri().getPrimaryUri(), new URI( "http://127.0.0.1:10002/devstoreaccount1")); assertEquals(devstoreAccount.getBlobStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10000/devstoreaccount1-secondary")); assertEquals(devstoreAccount.getQueueStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10001/devstoreaccount1-secondary")); assertEquals(devstoreAccount.getTableStorageUri().getSecondaryUri(), new URI( "http://127.0.0.1:10002/devstoreaccount1-secondary")); String devstoreAccountToStringWithSecrets = devstoreAccount.toString(true); CloudStorageAccount testAccount = CloudStorageAccount.parse(devstoreAccountToStringWithSecrets); AccountsAreEqual(testAccount, devstoreAccount); // Following should not throw exception: CloudStorageAccount.parse(devstoreAccountToStringWithSecrets); }
@Test public void testCloudStorageAccountDefaultEndpointOverride() throws URISyntaxException, InvalidKeyException { CloudStorageAccount account = CloudStorageAccount .parse("DefaultEndpointsProtocol=http;BlobEndpoint=http://customdomain.com/;AccountName=asdf;AccountKey=123="); assertEquals(new URI("http://customdomain.com/"), account.getBlobEndpoint()); assertNull(account.getBlobStorageUri().getSecondaryUri()); }
@Test public void testCloudStorageAccountDevStore() throws URISyntaxException { // default CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://127.0.0.1:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://127.0.0.1:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); // proxy account = CloudStorageAccount.getDevelopmentStorageAccount(new URI("http://ipv4.fiddler")); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1"), account.getBlobEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1"), account.getQueueEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1"), account.getTableEndpoint()); assertEquals(new URI("http://ipv4.fiddler:10000/devstoreaccount1-secondary"), account.getBlobStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10001/devstoreaccount1-secondary"), account.getQueueStorageUri() .getSecondaryUri()); assertEquals(new URI("http://ipv4.fiddler:10002/devstoreaccount1-secondary"), account.getTableStorageUri() .getSecondaryUri()); }
private void connectUsingCredentials(String accountName, StorageCredentials credentials, String containerName) throws URISyntaxException, StorageException, AzureException { URI blobEndPoint; if (isStorageEmulatorAccount(accountName)) { isStorageEmulator = true; CloudStorageAccount account = CloudStorageAccount.getDevelopmentStorageAccount(); storageInteractionLayer.createBlobClient(account); } else { blobEndPoint = new URI(getHTTPScheme() + "://" + accountName); storageInteractionLayer.createBlobClient(blobEndPoint, credentials); } suppressRetryPolicyInClientIfNeeded(); // Capture the container reference for debugging purposes. container = storageInteractionLayer.getContainerReference(containerName); rootDirectory = container.getDirectoryReference(""); // Can only create container if using account key credentials canCreateOrModifyContainer = credentials instanceof StorageCredentialsAccountAndKey; }
@Test public void testCloudStorageAccountClientUriVerify() throws URISyntaxException, StorageException { StorageCredentialsAccountAndKey cred = new StorageCredentialsAccountAndKey(ACCOUNT_NAME, ACCOUNT_KEY); CloudStorageAccount cloudStorageAccount = new CloudStorageAccount(cred, true); CloudBlobClient blobClient = cloudStorageAccount.createCloudBlobClient(); CloudBlobContainer container = blobClient.getContainerReference("container1"); assertEquals(cloudStorageAccount.getBlobEndpoint().toString() + "/container1", container.getUri().toString()); CloudQueueClient queueClient = cloudStorageAccount.createCloudQueueClient(); CloudQueue queue = queueClient.getQueueReference("queue1"); assertEquals(cloudStorageAccount.getQueueEndpoint().toString() + "/queue1", queue.getUri().toString()); CloudTableClient tableClient = cloudStorageAccount.createCloudTableClient(); CloudTable table = tableClient.getTableReference("table1"); assertEquals(cloudStorageAccount.getTableEndpoint().toString() + "/table1", table.getUri().toString()); CloudFileClient fileClient = cloudStorageAccount.createCloudFileClient(); CloudFileShare share = fileClient.getShareReference("share1"); assertEquals(cloudStorageAccount.getFileEndpoint().toString() + "/share1", share.getUri().toString()); }
CloudStorageAccount accountParse = CloudStorageAccount.parse( "DefaultEndpointsProtocol=http;AccountName=test;" + "AccountKey=abc=;EndpointSuffix=" + mooncake); CloudStorageAccount accountConstruct = new CloudStorageAccount(accountParse.getCredentials(), false, accountParse.getEndpointSuffix()); assertNotNull(accountParse); assertNotNull(accountConstruct); assertNotNull(accountParse.getBlobEndpoint()); assertEquals(accountParse.getBlobEndpoint(), accountConstruct.getBlobEndpoint()); assertTrue(accountParse.getBlobEndpoint().toString().endsWith(mooncake)); accountParse = CloudStorageAccount.parse( "TableEndpoint=http://tables/;DefaultEndpointsProtocol=http;" + "AccountName=test;AccountKey=abc=;EndpointSuffix=" + fairfax); accountConstruct = new CloudStorageAccount(accountParse.getCredentials(), false, accountParse.getEndpointSuffix()); assertNotNull(accountParse); assertNotNull(accountConstruct); assertNotNull(accountParse.getBlobEndpoint()); assertEquals(accountParse.getBlobEndpoint(), accountConstruct.getBlobEndpoint()); assertTrue(accountParse.getBlobEndpoint().toString().endsWith(fairfax)); CloudTableClient tableClientParse = accountParse.createCloudTableClient(); assertNotNull(tableClientParse); assertEquals(accountParse.getTableEndpoint(), tableClientParse.getEndpoint()); assertTrue(tableClientParse.getEndpoint().toString().endsWith("tables/"));
private static CloudStorageAccount getCloudStorageAccount(String blobLink, String saKey) throws MalformedURLException, URISyntaxException, InvalidKeyException { if (blobLink == null || blobLink.isEmpty()) { throw new IllegalArgumentException("Invalid blob link, it's null or empty: " + blobLink); } if (saKey == null || saKey.isEmpty()) { throw new IllegalArgumentException("Invalid storage account key, it's null or empty: " + saKey); } // check the link is valic URI blobUri = new URL(blobLink).toURI(); String host = blobUri.getHost(); if (host == null) { throw new IllegalArgumentException("Invalid blobLink, can't find host: " + blobLink); } String storageAccountName = host.substring(0, host.indexOf(".")); String storageConnectionString = getConnectionString(storageAccountName, saKey); CloudStorageAccount cloudStorageAccount = CloudStorageAccount.parse(storageConnectionString); return cloudStorageAccount; }