public CloudFileDirectory(StorageUri directoryAbsoluteUri, StorageCredentials credentials) #endif { this.Metadata = new Dictionary<string, string>(); this.Properties = new FileDirectoryProperties(); this.ParseQueryAndVerify(directoryAbsoluteUri, credentials); }
public CloudQueue(StorageUri queueAddress, StorageCredentials credentials) #endif { this.ParseQueryAndVerify(queueAddress, credentials); this.Metadata = new Dictionary<string, string>(); this.EncodeMessage = true; }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobContainer"/> class. /// </summary> /// <param name="containerAddress">A <see cref="System.Uri"/> object specifying the absolute URI to the container.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudBlobContainer(StorageUri containerAddress, StorageCredentials credentials) { CommonUtility.AssertNotNull("containerAddress", containerAddress); CommonUtility.AssertNotNull("containerAddress", containerAddress.PrimaryUri); this.ParseQueryAndVerify(containerAddress, credentials); this.Metadata = new Dictionary<string, string>(); this.Properties = new BlobContainerProperties(); }
/// <summary> /// Initializes a new instance of the <see cref="CloudAnalyticsClient"/> class using the specified Blob and Table service endpoints /// and account credentials. /// </summary> /// <param name="blobStorageUri">A <see cref="StorageUri"/> object containing the Blob service endpoint to use to create the client.</param> /// <param name="tableStorageUri">A <see cref="StorageUri"/> object containing the Table service endpoint to use to create the client.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudAnalyticsClient(StorageUri blobStorageUri, StorageUri tableStorageUri, StorageCredentials credentials) { CommonUtility.AssertNotNull("blobStorageUri", blobStorageUri); CommonUtility.AssertNotNull("tableStorageUri", tableStorageUri); this.blobClient = new CloudBlobClient(blobStorageUri, credentials); this.tableClient = new CloudTableClient(tableStorageUri, credentials); this.LogContainer = Constants.AnalyticsConstants.LogsContainer; }
/// <summary> /// Initializes a new instance of the <see cref="CloudFileShare"/> class. /// </summary> /// <param name="shareAddress">The absolute URI to the share.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudFileShare(StorageUri shareAddress, StorageCredentials credentials) { CommonUtility.AssertNotNull("shareAddress", shareAddress); CommonUtility.AssertNotNull("shareAddress", shareAddress.PrimaryUri); this.ParseQueryAndVerify(shareAddress, credentials); this.Metadata = new Dictionary<string, string>(); this.Properties = new FileShareProperties(); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlob"/> class using an absolute URI to the blob. /// </summary> /// <param name="blobAbsoluteUri">A <see cref="StorageUri"/> containing the absolute URI to the blob at both the primary and secondary locations.</param> /// <param name="snapshotTime">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the blob is a snapshot.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> /// <returns>A <see cref="CloudBlob"/> object.</returns> public CloudBlob(StorageUri blobAbsoluteUri, DateTimeOffset? snapshotTime, StorageCredentials credentials) { CommonUtility.AssertNotNull("blobAbsoluteUri", blobAbsoluteUri); CommonUtility.AssertNotNull("blobAbsoluteUri", blobAbsoluteUri.PrimaryUri); this.attributes = new BlobAttributes(); this.SnapshotTime = snapshotTime; this.ParseQueryAndVerify(blobAbsoluteUri, credentials); this.Properties.BlobType = BlobType.Unspecified; }
public CloudQueueClient(StorageUri storageUri, StorageCredentials credentials) #endif { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.DefaultRequestOptions = new QueueRequestOptions(); this.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(); this.DefaultRequestOptions.LocationMode = RetryPolicies.LocationMode.PrimaryOnly; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobDirectory"/> class given an address and a client. /// </summary> /// <param name="uri">The blob directory's Uri.</param> /// <param name="prefix">The blob directory's prefix.</param> /// <param name="container">The container for the virtual directory.</param> internal CloudBlobDirectory(StorageUri uri, string prefix, CloudBlobContainer container) { CommonUtility.AssertNotNull("uri", uri); CommonUtility.AssertNotNull("prefix", prefix); CommonUtility.AssertNotNull("container", container); this.ServiceClient = container.ServiceClient; this.Container = container; this.Prefix = prefix; this.StorageUri = uri; }
public CloudQueueClient(StorageUri storageUri, StorageCredentials credentials) #endif { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.RetryPolicy = new ExponentialRetry(); this.LocationMode = LocationMode.PrimaryOnly; this.ServerTimeout = Constants.DefaultServerSideTimeout; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); }
/// <summary> /// Initializes a new instance of the <see cref="CloudFileDirectory"/> class given an address and a client. /// </summary> /// <param name="uri">The file directory's Uri.</param> /// <param name="directoryName">Name of the directory.</param> /// <param name="share">The share for the directory.</param> internal CloudFileDirectory(StorageUri uri, string directoryName, CloudFileShare share) { CommonUtility.AssertNotNull("uri", uri); CommonUtility.AssertNotNull("directoryName", directoryName); CommonUtility.AssertNotNull("share", share); this.Properties = new FileDirectoryProperties(); this.StorageUri = uri; this.ServiceClient = share.ServiceClient; this.share = share; this.Name = directoryName; }
/// <summary> /// Initializes a new instance of the <see cref="CloudFile"/> class using the specified file name and /// the parent share reference. /// </summary> /// <param name="uri">The file's Uri.</param> /// <param name="fileName">Name of the file.</param> /// <param name="share">The reference to the parent share.</param> internal CloudFile(StorageUri uri, string fileName, CloudFileShare share) { CommonUtility.AssertNotNull("uri", uri); CommonUtility.AssertNotNullOrEmpty("fileName", fileName); CommonUtility.AssertNotNull("share", share); this.attributes = new CloudFileAttributes(); this.attributes.StorageUri = uri; this.ServiceClient = share.ServiceClient; this.share = share; this.Name = fileName; }
/// <summary> /// Initializes a new instance of the <see cref="CloudFileClient"/> class using the specified File service endpoint /// and account credentials. /// </summary> /// <param name="storageUri">The File service endpoint to use to create the client.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudFileClient(StorageUri storageUri, StorageCredentials credentials) { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.DefaultRequestOptions = new FileRequestOptions() { RetryPolicy = new ExponentialRetry(), LocationMode = FileRequestOptions.BaseDefaultRequestOptions.LocationMode, ParallelOperationThreadCount = FileRequestOptions.BaseDefaultRequestOptions.ParallelOperationThreadCount }; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); }
public CloudBlobClient(StorageUri storageUri, StorageCredentials credentials) #endif { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.DefaultRequestOptions = new BlobRequestOptions(); this.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(); this.DefaultRequestOptions.LocationMode = RetryPolicies.LocationMode.PrimaryOnly; this.DefaultRequestOptions.SingleBlobUploadThresholdInBytes = Constants.MaxSingleUploadBlobSize / 2; this.DefaultRequestOptions.ParallelOperationThreadCount = 1; this.DefaultDelimiter = NavigationHelper.Slash; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobClient"/> class using the specified Blob service endpoint /// and account credentials. /// </summary> /// <param name="storageUri">A <see cref="StorageUri"/> object containing the Blob service endpoint to use to create the client.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudBlobClient(StorageUri storageUri, StorageCredentials credentials) { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.DefaultRequestOptions = new BlobRequestOptions() { RetryPolicy = new ExponentialRetry(), LocationMode = BlobRequestOptions.BaseDefaultRequestOptions.LocationMode, SingleBlobUploadThresholdInBytes = BlobRequestOptions.BaseDefaultRequestOptions.SingleBlobUploadThresholdInBytes, ParallelOperationThreadCount = BlobRequestOptions.BaseDefaultRequestOptions.ParallelOperationThreadCount }; this.DefaultDelimiter = NavigationHelper.Slash; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); }
public CloudTableClient(StorageUri storageUri, StorageCredentials credentials) #endif { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.DefaultRequestOptions = new TableRequestOptions(); this.DefaultRequestOptions.RetryPolicy = new ExponentialRetry(); this.DefaultRequestOptions.LocationMode = RetryPolicies.LocationMode.PrimaryOnly; this.DefaultRequestOptions.PayloadFormat = TablePayloadFormat.Json; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); if (!this.Credentials.IsSharedKey) { this.AccountName = NavigationHelper.GetAccountNameFromUri(this.BaseUri, this.UsePathStyleUris); } }
/// <summary> /// Initializes a new instance of the <see cref="CloudTableClient"/> class using the specified Table service endpoint /// and account credentials. /// </summary> /// <param name="storageUri">A <see cref="StorageUri"/> object containing the Table service endpoint to use to create the client.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudTableClient(StorageUri storageUri, StorageCredentials credentials) { this.StorageUri = storageUri; this.Credentials = credentials ?? new StorageCredentials(); this.DefaultRequestOptions = new TableRequestOptions(TableRequestOptions.BaseDefaultRequestOptions) { RetryPolicy = new ExponentialRetry() }; this.AuthenticationScheme = AuthenticationScheme.SharedKey; this.UsePathStyleUris = CommonUtility.UsePathStyleAddressing(this.BaseUri); if (!this.Credentials.IsSharedKey) { this.AccountName = NavigationHelper.GetAccountNameFromUri(this.BaseUri, this.UsePathStyleUris); } }
public void StorageUriWithTwoUris() { Uri primaryClientUri = new Uri("http://" + AccountName + BlobService + EndpointSuffix); Uri primaryContainerUri = new Uri(primaryClientUri, "container"); Uri secondaryClientUri = new Uri("http://" + AccountName + SecondarySuffix + BlobService + EndpointSuffix); Uri dummyClientUri = new Uri("http://" + AccountName + "-dummy" + BlobService + EndpointSuffix); StorageUri singleUri = new StorageUri(primaryClientUri); Assert.IsTrue(primaryClientUri.Equals(singleUri.PrimaryUri)); Assert.IsNull(singleUri.SecondaryUri); StorageUri singleUri2 = new StorageUri(primaryClientUri); Assert.IsTrue(singleUri.Equals(singleUri2)); StorageUri singleUri3 = new StorageUri(secondaryClientUri); Assert.IsFalse(singleUri.Equals(singleUri3)); StorageUri multiUri = new StorageUri(primaryClientUri, secondaryClientUri); Assert.IsTrue(primaryClientUri.Equals(multiUri.PrimaryUri)); Assert.IsTrue(secondaryClientUri.Equals(multiUri.SecondaryUri)); Assert.IsFalse(multiUri.Equals(singleUri)); StorageUri multiUri2 = new StorageUri(primaryClientUri, secondaryClientUri); Assert.IsTrue(multiUri.Equals(multiUri2)); TestHelper.ExpectedException<ArgumentException>( () => new StorageUri(primaryClientUri, primaryContainerUri), "StorageUri constructor should fail if both URIs do not point to the same resource"); StorageUri multiUri3 = new StorageUri(primaryClientUri, dummyClientUri); Assert.IsFalse(multiUri.Equals(multiUri3)); StorageUri multiUri4 = new StorageUri(dummyClientUri, secondaryClientUri); Assert.IsFalse(multiUri.Equals(multiUri4)); StorageUri multiUri5 = new StorageUri(secondaryClientUri, primaryClientUri); Assert.IsFalse(multiUri.Equals(multiUri5)); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlockBlob"/> class using an absolute URI to the blob. /// </summary> /// <param name="blobAbsoluteUri">A <see cref="StorageUri"/> containing the absolute URI to the blob at both the primary and secondary locations.</param> /// <param name="snapshotTime">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the blob is a snapshot.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudBlockBlob(StorageUri blobAbsoluteUri, DateTimeOffset?snapshotTime, StorageCredentials credentials) : base(blobAbsoluteUri, snapshotTime, credentials) { this.Properties.BlobType = BlobType.BlockBlob; }
/// <summary> /// Initializes a new instance of the <see cref="CloudTable"/> class. /// </summary> /// <param name="tableAddress">A <see cref="StorageUri"/> containing the absolute URI to the table at both the primary and secondary locations.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> #if WINDOWS_RT /// <returns>A <see cref="CloudTable"/> object.</returns> public static CloudTable Create(StorageUri tableAddress, StorageCredentials credentials) { return(new CloudTable(tableAddress, credentials)); }
public RESTCommand(StorageCredentials credentials, StorageUri storageUri) : this(credentials, storageUri, null) { }
/// <summary> /// Appends a path to a list of URIs correctly using "/" as separator. /// </summary> /// <param name="uriList">The base URI.</param> /// <param name="relativeUri">The relative or absolute URI.</param> /// <returns>The list of appended URIs.</returns> internal static StorageUri AppendPathToUri(StorageUri uriList, string relativeUri) { return(AppendPathToUri(uriList, relativeUri, NavigationHelper.Slash)); }
public void CloudBlobSASSharedProtocolsQueryParam() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); CloudBlob blob; SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), }; CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb"); blockBlob.PutBlockList(new string[] { }); foreach (SharedAccessProtocol? protocol in new SharedAccessProtocol?[] { null, SharedAccessProtocol.HttpsOrHttp, SharedAccessProtocol.HttpsOnly }) { string blockBlobToken = blockBlob.GetSharedAccessSignature(policy, null, null, protocol, null); StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken); Uri blockBlobSASUri = new Uri(blockBlob.Uri + blockBlobSAS.SASToken); StorageUri blockBlobSASStorageUri = new StorageUri(new Uri(blockBlob.StorageUri.PrimaryUri + blockBlobSAS.SASToken), new Uri(blockBlob.StorageUri.SecondaryUri + blockBlobSAS.SASToken)); int httpPort = blockBlobSASUri.Port; int securePort = 443; if (!string.IsNullOrEmpty(TestBase.TargetTenantConfig.BlobSecurePortOverride)) { securePort = Int32.Parse(TestBase.TargetTenantConfig.BlobSecurePortOverride); } var schemesAndPorts = new[] { new { scheme = Uri.UriSchemeHttp, port = httpPort}, new { scheme = Uri.UriSchemeHttps, port = securePort} }; foreach (var item in schemesAndPorts) { blockBlobSASUri = TransformSchemeAndPort(blockBlobSASUri, item.scheme, item.port); blockBlobSASStorageUri = new StorageUri(TransformSchemeAndPort(blockBlobSASStorageUri.PrimaryUri, item.scheme, item.port), TransformSchemeAndPort(blockBlobSASStorageUri.SecondaryUri, item.scheme, item.port)); if (protocol.HasValue && protocol.Value == SharedAccessProtocol.HttpsOnly && string.CompareOrdinal(item.scheme, Uri.UriSchemeHttp) == 0) { blob = new CloudBlob(blockBlobSASUri); TestHelper.ExpectedException(() => blob.FetchAttributes(), "Access a blob using SAS with a shared protocols that does not match", HttpStatusCode.Unused); blob = new CloudBlob(blockBlobSASStorageUri, null, null); TestHelper.ExpectedException(() => blob.FetchAttributes(), "Access a blob using SAS with a shared protocols that does not match", HttpStatusCode.Unused); } else { blob = new CloudBlob(blockBlobSASUri); blob.FetchAttributes(); Assert.AreEqual(blob.BlobType, BlobType.BlockBlob); blob = new CloudBlob(blockBlobSASStorageUri, null, null); blob.FetchAttributes(); Assert.AreEqual(blob.BlobType, BlobType.BlockBlob); } } } } finally { container.DeleteIfExists(); } }
/// <summary> /// Implements the FetchAttributes method. The attributes are updated immediately. /// </summary> /// <param name="blobUri">The URI of the blob.</param> /// <param name="accessCondition">An <see cref="AccessCondition"/> object that represents the access conditions for the blob. If <c>null</c>, no condition is used.</param> /// <param name="options">A <see cref="BlobRequestOptions"/> object that specifies additional options for the request.</param> /// <returns>A <see cref="RESTCommand"/> that fetches the attributes.</returns> private RESTCommand<ICloudBlob> GetBlobReferenceImpl(StorageUri blobUri, AccessCondition accessCondition, BlobRequestOptions options) { // If the blob Uri contains SAS credentials, we need to use those // credentials instead of this service client's stored credentials. StorageCredentials parsedCredentials; DateTimeOffset? parsedSnapshot; blobUri = NavigationHelper.ParseBlobQueryAndVerify(blobUri, out parsedCredentials, out parsedSnapshot); CloudBlobClient client = parsedCredentials != null ? new CloudBlobClient(this.StorageUri, parsedCredentials) : this; RESTCommand<ICloudBlob> getCmd = new RESTCommand<ICloudBlob>(client.Credentials, blobUri); options.ApplyToStorageCommand(getCmd); getCmd.CommandLocationMode = CommandLocationMode.PrimaryOrSecondary; getCmd.Handler = client.AuthenticationHandler; getCmd.BuildClient = HttpClientFactory.BuildHttpClient; getCmd.BuildRequest = (cmd, uri, builder, cnt, serverTimeout, ctx) => BlobHttpRequestMessageFactory.GetProperties(uri, serverTimeout, parsedSnapshot, accessCondition, cnt, ctx); getCmd.PreProcessResponse = (cmd, resp, ex, ctx) => { HttpResponseParsers.ProcessExpectedStatusCodeNoException(HttpStatusCode.OK, resp, null /* retVal */, cmd, ex); BlobAttributes attributes = new BlobAttributes() { StorageUri = blobUri, SnapshotTime = parsedSnapshot, }; CloudBlob.UpdateAfterFetchAttributes(attributes, resp, false); switch (attributes.Properties.BlobType) { case BlobType.BlockBlob: return new CloudBlockBlob(attributes, client); case BlobType.PageBlob: return new CloudPageBlob(attributes, client); case BlobType.AppendBlob: return new CloudAppendBlob(attributes, client); default: throw new InvalidOperationException(); } }; return getCmd; }
/// <summary> /// Initializes a new instance of the <see cref="CloudFile"/> class using an absolute URI to the file. /// </summary> /// <param name="fileAbsoluteUri">The absolute URI to the file.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudFile(StorageUri fileAbsoluteUri, StorageCredentials credentials) { this.attributes = new CloudFileAttributes(); this.ParseQueryAndVerify(fileAbsoluteUri, credentials); }
public Task <ICloudBlob> GetBlobReferenceFromServerAsync(StorageUri blobUri, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) { return(this.GetBlobReferenceFromServerAsync(blobUri, accessCondition, options, operationContext, CancellationToken.None)); }
public CloudFileDirectory(StorageUri directoryAbsoluteUri, StorageCredentials credentials) { throw new System.NotImplementedException(); }
internal CloudFileDirectory(StorageUri uri, string directoryName, CloudFileShare share) { throw new System.NotImplementedException(); }
/// <summary> /// Retrieve the container address and address. /// </summary> /// <param name="blobAddress">The blob address.</param> /// <param name="usePathStyleUris">True to use path style Uris.</param> /// <param name="containerName">Name of the container.</param> /// <param name="containerUri">The container URI.</param> /// <returns><c>true</c> when the container is an explicit container. <c>false</c>, otherwise.</returns> private static bool GetContainerNameAndAddress(StorageUri blobAddress, bool?usePathStyleUris, out string containerName, out StorageUri containerUri) { string blobName; bool explicitCont = GetContainerNameAndBlobName(blobAddress.PrimaryUri, usePathStyleUris, out containerName, out blobName); containerUri = NavigationHelper.AppendPathToUri(GetServiceClientBaseAddress(blobAddress, usePathStyleUris), containerName); return(explicitCont); }
/// <summary> /// Appends a path to a list of URIs correctly using "/" as separator. /// </summary> /// <param name="uriList">The base URI.</param> /// <param name="relativeUri">The relative or absolute URI.</param> /// <param name="sep">The separator.</param> /// <returns>The list of appended URIs.</returns> internal static StorageUri AppendPathToUri(StorageUri uriList, string relativeUri, string sep) { return(new StorageUri( AppendPathToSingleUri(uriList.PrimaryUri, relativeUri, sep), AppendPathToSingleUri(uriList.SecondaryUri, relativeUri, sep))); }
internal CloudFile(StorageUri fileAbsoluteUri, StorageCredentials credentials)
public Task<ICloudBlob> GetBlobReferenceFromServerAsync(StorageUri blobUri, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext) { return this.GetBlobReferenceFromServerAsync(blobUri, accessCondition, options, operationContext, CancellationToken.None); }
public CloudBlob(StorageUri blobAbsoluteUri, DateTimeOffset?snapshotTime, StorageCredentials credentials) { throw new System.NotImplementedException(); }
internal CloudBlobContainer(StorageUri containerAddress, StorageCredentials credentials)
private void ParseQueryAndVerify(StorageUri address, StorageCredentials credentials) { throw new System.NotImplementedException(); }
/// <summary> /// Parse URI for SAS (Shared Access Signature) information. /// </summary> /// <param name="address">The complete Uri.</param> /// <param name="credentials">The credentials to use.</param> private void ParseQueryAndVerify(StorageUri address, StorageCredentials credentials) { StorageCredentials parsedCredentials; this.StorageUri = NavigationHelper.ParseQueueTableQueryAndVerify(address, out parsedCredentials); if (parsedCredentials != null && credentials != null) { string error = string.Format(CultureInfo.CurrentCulture, SR.MultipleCredentialsProvided); throw new ArgumentException(error); } this.ServiceClient = new CloudQueueClient(NavigationHelper.GetServiceClientBaseAddress(this.StorageUri, null /* usePathStyleUris */), credentials ?? parsedCredentials); this.Name = NavigationHelper.GetQueueNameFromUri(this.Uri, this.ServiceClient.UsePathStyleUris); }
public void CloudBlobSASApiVersionQueryParam() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); CloudBlob blob; SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), }; CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb"); blockBlob.PutBlockList(new string[] { }); CloudPageBlob pageBlob = container.GetPageBlobReference("pb"); pageBlob.Create(0); CloudAppendBlob appendBlob = container.GetAppendBlobReference("ab"); appendBlob.CreateOrReplace(); string blockBlobToken = blockBlob.GetSharedAccessSignature(policy); StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken); Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri); StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri); string pageBlobToken = pageBlob.GetSharedAccessSignature(policy); StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken); Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri); StorageUri pageBlobSASStorageUri = pageBlobSAS.TransformUri(pageBlob.StorageUri); string appendBlobToken = appendBlob.GetSharedAccessSignature(policy); StorageCredentials appendBlobSAS = new StorageCredentials(appendBlobToken); Uri appendBlobSASUri = appendBlobSAS.TransformUri(appendBlob.Uri); StorageUri appendBlobSASStorageUri = appendBlobSAS.TransformUri(appendBlob.StorageUri); OperationContext apiVersionCheckContext = new OperationContext(); apiVersionCheckContext.SendingRequest += (sender, e) => { Assert.IsTrue(e.Request.RequestUri.Query.Contains("api-version")); }; blob = new CloudBlob(blockBlobSASUri); blob.FetchAttributes(operationContext: apiVersionCheckContext); Assert.AreEqual(blob.BlobType, BlobType.BlockBlob); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = new CloudBlob(pageBlobSASUri); blob.FetchAttributes(operationContext: apiVersionCheckContext); Assert.AreEqual(blob.BlobType, BlobType.PageBlob); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = new CloudBlob(blockBlobSASStorageUri, null, null); blob.FetchAttributes(operationContext: apiVersionCheckContext); Assert.AreEqual(blob.BlobType, BlobType.BlockBlob); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); blob = new CloudBlob(pageBlobSASStorageUri, null, null); blob.FetchAttributes(operationContext: apiVersionCheckContext); Assert.AreEqual(blob.BlobType, BlobType.PageBlob); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); } finally { container.DeleteIfExists(); } }
/// <summary> /// Initializes a new instance of the <see cref="CloudFile"/> class using an absolute URI to the file. /// </summary> /// <param name="fileAbsoluteUri">The absolute URI to the file.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> #if WINDOWS_RT /// <returns>A <see cref="CloudFile"/> object.</returns> public static CloudFile Create(StorageUri fileAbsoluteUri, StorageCredentials credentials) { return(new CloudFile(fileAbsoluteUri, credentials)); }
/// <summary> /// Helper function for testing the IPAddressOrRange funcitonality for blobs /// </summary> /// <param name="generateInitialIPAddressOrRange">Function that generates an initial IPAddressOrRange object to use. This is expected to fail on the service.</param> /// <param name="generateFinalIPAddressOrRange">Function that takes in the correct IP address (according to the service) and returns the IPAddressOrRange object /// that should be accepted by the service</param> public void CloudBlobSASIPAddressHelper(Func <IPAddressOrRange> generateInitialIPAddressOrRange, Func <IPAddress, IPAddressOrRange> generateFinalIPAddressOrRange) { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); CloudBlob blob; SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), }; CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb"); byte[] data = new byte[] { 0x1, 0x2, 0x3, 0x4 }; blockBlob.UploadFromByteArray(data, 0, 4); // The plan then is to use an incorrect IP address to make a call to the service // ensure that we get an error message // parse the error message to get my actual IP (as far as the service sees) // then finally test the success case to ensure we can actually make requests IPAddressOrRange ipAddressOrRange = generateInitialIPAddressOrRange(); string blockBlobToken = blockBlob.GetSharedAccessSignature(policy, null, null, null, ipAddressOrRange); StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken); Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri); StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri); blob = new CloudBlob(blockBlobSASUri); byte[] target = new byte[4]; OperationContext opContext = new OperationContext(); IPAddress actualIP = null; bool exceptionThrown = false; try { blob.DownloadRangeToByteArray(target, 0, 0, 4, null, null, opContext); } catch (StorageException) { exceptionThrown = true; //The IP should not be included in the error details for security reasons Assert.IsNull(actualIP); } Assert.IsTrue(exceptionThrown); ipAddressOrRange = null; blockBlobToken = blockBlob.GetSharedAccessSignature(policy, null, null, null, ipAddressOrRange); blockBlobSAS = new StorageCredentials(blockBlobToken); blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri); blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri); blob = new CloudBlob(blockBlobSASUri); blob.DownloadRangeToByteArray(target, 0, 0, 4, null, null, null); for (int i = 0; i < 4; i++) { Assert.AreEqual(data[i], target[i]); } Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = new CloudBlob(blockBlobSASStorageUri, null, null); blob.DownloadRangeToByteArray(target, 0, 0, 4, null, null, null); for (int i = 0; i < 4; i++) { Assert.AreEqual(data[i], target[i]); } Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); } finally { container.DeleteIfExists(); } }
public CloudTable(StorageUri tableAddress, StorageCredentials credentials) #endif { this.ParseQueryAndVerify(tableAddress, credentials); }
public void CloudBlobSASSharedProtocolsQueryParam() { CloudBlobContainer container = GetRandomContainerReference(); try { container.Create(); CloudBlob blob; SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), }; CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb"); blockBlob.PutBlockList(new string[] { }); foreach (SharedAccessProtocol?protocol in new SharedAccessProtocol?[] { null, SharedAccessProtocol.HttpsOrHttp, SharedAccessProtocol.HttpsOnly }) { string blockBlobToken = blockBlob.GetSharedAccessSignature(policy, null, null, protocol, null); StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken); Uri blockBlobSASUri = new Uri(blockBlob.Uri + blockBlobSAS.SASToken); StorageUri blockBlobSASStorageUri = new StorageUri(new Uri(blockBlob.StorageUri.PrimaryUri + blockBlobSAS.SASToken), new Uri(blockBlob.StorageUri.SecondaryUri + blockBlobSAS.SASToken)); int httpPort = blockBlobSASUri.Port; int securePort = 443; if (!string.IsNullOrEmpty(TestBase.TargetTenantConfig.BlobSecurePortOverride)) { securePort = Int32.Parse(TestBase.TargetTenantConfig.BlobSecurePortOverride); } var schemesAndPorts = new[] { new { scheme = Uri.UriSchemeHttp, port = httpPort }, new { scheme = Uri.UriSchemeHttps, port = securePort } }; foreach (var item in schemesAndPorts) { blockBlobSASUri = TransformSchemeAndPort(blockBlobSASUri, item.scheme, item.port); blockBlobSASStorageUri = new StorageUri(TransformSchemeAndPort(blockBlobSASStorageUri.PrimaryUri, item.scheme, item.port), TransformSchemeAndPort(blockBlobSASStorageUri.SecondaryUri, item.scheme, item.port)); if (protocol.HasValue && protocol.Value == SharedAccessProtocol.HttpsOnly && string.CompareOrdinal(item.scheme, Uri.UriSchemeHttp) == 0) { blob = new CloudBlob(blockBlobSASUri); TestHelper.ExpectedException(() => blob.FetchAttributes(), "Access a blob using SAS with a shared protocols that does not match", HttpStatusCode.Unused); blob = new CloudBlob(blockBlobSASStorageUri, null, null); TestHelper.ExpectedException(() => blob.FetchAttributes(), "Access a blob using SAS with a shared protocols that does not match", HttpStatusCode.Unused); } else { blob = new CloudBlob(blockBlobSASUri); blob.FetchAttributes(); Assert.AreEqual(blob.BlobType, BlobType.BlockBlob); blob = new CloudBlob(blockBlobSASStorageUri, null, null); blob.FetchAttributes(); Assert.AreEqual(blob.BlobType, BlobType.BlockBlob); } } } } finally { container.DeleteIfExists(); } }
internal CloudTable(StorageUri tableAddress, StorageCredentials credentials)
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobContainer"/> class. /// </summary> /// <param name="containerAddress">A <see cref="System.Uri"/> object specifying the absolute URI to the container.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> #if WINDOWS_RT /// <returns>A <see cref="CloudBlobContainer"/> object.</returns> public static CloudBlobContainer Create(StorageUri containerAddress, StorageCredentials credentials) { return(new CloudBlobContainer(containerAddress, credentials)); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlockBlob"/> class using an absolute URI to the blob. /// </summary> /// <param name="blobAbsoluteUri">A <see cref="StorageUri"/> containing the absolute URI to the blob at both the primary and secondary locations.</param> /// <param name="snapshotTime">A <see cref="DateTimeOffset"/> specifying the snapshot timestamp, if the blob is a snapshot.</param> /// <param name="client">A <see cref="CloudBlobClient"/> object.</param> public CloudBlockBlob(StorageUri blobAbsoluteUri, DateTimeOffset?snapshotTime, CloudBlobClient client) : base(blobAbsoluteUri, snapshotTime, client) { this.Properties.BlobType = BlobType.BlockBlob; }
internal CloudBlobClient(StorageUri storageUri, StorageCredentials credentials)
internal CloudQueue(StorageUri queueAddress, StorageCredentials credentials)
public CloudFile(StorageUri fileAbsoluteUri, StorageCredentials credentials) #endif { this.attributes = new CloudFileAttributes(); this.ParseQueryAndVerify(fileAbsoluteUri, credentials); }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobClient"/> class using the specified Blob service endpoint /// and account credentials. /// </summary> /// <param name="storageUri">A <see cref="StorageUri"/> object containing the Blob service endpoint to use to create the client.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> #if WINDOWS_RT || ASPNET_K /// <returns>A <see cref="CloudBlobClient"/> object.</returns> public static CloudBlobClient Create(StorageUri storageUri, StorageCredentials credentials) { return(new CloudBlobClient(storageUri, credentials)); }
public Task<ICloudBlob> GetBlobReferenceFromServerAsync(StorageUri blobUri, AccessCondition accessCondition, BlobRequestOptions options, OperationContext operationContext, CancellationToken cancellationToken) { CommonUtility.AssertNotNull("blobUri", blobUri); BlobRequestOptions modifiedOptions = BlobRequestOptions.ApplyDefaults(options, BlobType.Unspecified, this); return Task.Run(async () => await Executor.ExecuteAsync( this.GetBlobReferenceImpl(blobUri, accessCondition, modifiedOptions), modifiedOptions.RetryPolicy, operationContext, cancellationToken), cancellationToken); }
public async Task CloudBlobContainerGetBlobReferenceFromServerAsync() { CloudBlobContainer container = GetRandomContainerReference(); try { await container.CreateAsync(); SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy() { Permissions = SharedAccessBlobPermissions.Read, SharedAccessStartTime = DateTimeOffset.UtcNow.AddMinutes(-5), SharedAccessExpiryTime = DateTimeOffset.UtcNow.AddMinutes(30), }; CloudBlockBlob blockBlob = container.GetBlockBlobReference("bb"); await blockBlob.PutBlockListAsync(new List <string>()); CloudPageBlob pageBlob = container.GetPageBlobReference("pb"); await pageBlob.CreateAsync(0); CloudBlobClient client; ICloudBlob blob; blob = await container.GetBlobReferenceFromServerAsync("bb"); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); CloudBlockBlob blockBlobSnapshot = await((CloudBlockBlob)blob).CreateSnapshotAsync(); await blob.SetPropertiesAsync(); Uri blockBlobSnapshotUri = new Uri(blockBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + blockBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o")); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSnapshotUri); AssertAreEqual(blockBlobSnapshot.Properties, blob.Properties); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlobSnapshot.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.GetBlobReferenceFromServerAsync("pb"); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); CloudPageBlob pageBlobSnapshot = await((CloudPageBlob)blob).CreateSnapshotAsync(); await blob.SetPropertiesAsync(); Uri pageBlobSnapshotUri = new Uri(pageBlobSnapshot.Uri.AbsoluteUri + "?snapshot=" + pageBlobSnapshot.SnapshotTime.Value.UtcDateTime.ToString("o")); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSnapshotUri); AssertAreEqual(pageBlobSnapshot.Properties, blob.Properties); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlobSnapshot.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.Uri); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.Uri); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlob.StorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlob.StorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); string blockBlobToken = blockBlob.GetSharedAccessSignature(policy); StorageCredentials blockBlobSAS = new StorageCredentials(blockBlobToken); Uri blockBlobSASUri = blockBlobSAS.TransformUri(blockBlob.Uri); StorageUri blockBlobSASStorageUri = blockBlobSAS.TransformUri(blockBlob.StorageUri); string pageBlobToken = pageBlob.GetSharedAccessSignature(policy); StorageCredentials pageBlobSAS = new StorageCredentials(pageBlobToken); Uri pageBlobSASUri = pageBlobSAS.TransformUri(pageBlob.Uri); StorageUri pageBlobSASStorageUri = pageBlobSAS.TransformUri(pageBlob.StorageUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(blockBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); blob = await container.ServiceClient.GetBlobReferenceFromServerAsync(pageBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); client = new CloudBlobClient(container.ServiceClient.BaseUri, blockBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(blockBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(blockBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); client = new CloudBlobClient(container.ServiceClient.BaseUri, pageBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(pageBlobSASUri); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.PrimaryUri.Equals(pageBlob.Uri)); Assert.IsNull(blob.StorageUri.SecondaryUri); client = new CloudBlobClient(container.ServiceClient.StorageUri, blockBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(blockBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudBlockBlob)); Assert.IsTrue(blob.StorageUri.Equals(blockBlob.StorageUri)); client = new CloudBlobClient(container.ServiceClient.StorageUri, pageBlobSAS); blob = await client.GetBlobReferenceFromServerAsync(pageBlobSASStorageUri, null, null, null); Assert.IsInstanceOfType(blob, typeof(CloudPageBlob)); Assert.IsTrue(blob.StorageUri.Equals(pageBlob.StorageUri)); } finally { container.DeleteIfExistsAsync().AsTask().Wait(); } }
/// <summary> /// Initializes a new instance of the <see cref="CloudBlobContainer"/> class. /// </summary> /// <param name="containerAddress">A <see cref="System.Uri"/> object specifying the absolute URI to the container.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> #if WINDOWS_RT /// <returns>A <see cref="CloudBlobContainer"/> object.</returns> public static CloudBlobContainer Create(StorageUri containerAddress, StorageCredentials credentials) { return new CloudBlobContainer(containerAddress, credentials); }
public FileUriProvider(CloudStorageAccount account) { _tinyUrl = new TinyUrl(); _blobUri = account.BlobStorageUri; }
/// <summary> /// Transforms a resource URI into a shared access signature URI, by appending a shared access token. /// </summary> /// <param name="resourceUri">A <see cref="StorageUri"/> object that represents the resource URI to be transformed.</param> /// <returns>A <see cref="StorageUri"/> object that represents the signature, including the resource URI and the shared access token.</returns> public StorageUri TransformUri(StorageUri resourceUri) { CommonUtility.AssertNotNull("resourceUri", resourceUri); return new StorageUri( this.TransformUri(resourceUri.PrimaryUri), this.TransformUri(resourceUri.SecondaryUri)); }
internal StorageUri GenerateRequestURI(StorageUri uriList, string tableName) { return(new StorageUri( this.GenerateRequestURI(uriList.PrimaryUri, tableName), this.GenerateRequestURI(uriList.SecondaryUri, tableName))); }
/// <summary> /// Gets the Uri for general message operations. /// </summary> internal StorageUri GetMessageRequestAddress() { if (this.messageRequestAddress == null) { this.messageRequestAddress = NavigationHelper.AppendPathToUri(this.StorageUri, Constants.Messages); } return this.messageRequestAddress; }
/// <summary> /// Initializes a new instance of the <see cref="CloudQueue"/> class. /// </summary> /// <param name="queueAddress">A <see cref="StorageUri"/> containing the absolute URI to the queue at both the primary and secondary locations.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> #if WINDOWS_RT /// <returns>A <see cref="CloudQueue"/> object.</returns> public static CloudQueue Create(StorageUri queueAddress, StorageCredentials credentials) { return new CloudQueue(queueAddress, credentials); }
/// <summary> /// Gets the service client base address. /// </summary> /// <param name="addressUri">The address Uri.</param> /// <param name="usePathStyleUris">The use path style Uris.</param> /// <returns>The base address of the client.</returns> /// <example> /// GetServiceClientBaseAddress("http://testaccount.blob.core.windows.net/testcontainer/blob1") /// returns "http://testaccount.blob.core.windows.net" /// </example> internal static StorageUri GetServiceClientBaseAddress(StorageUri addressUri, bool?usePathStyleUris) { return(new StorageUri( GetServiceClientBaseAddress(addressUri.PrimaryUri, usePathStyleUris), GetServiceClientBaseAddress(addressUri.SecondaryUri, usePathStyleUris))); }
/// <summary> /// Initializes a new instance of the <see cref="CloudFileShare"/> class. /// </summary> /// <param name="shareAddress">The absolute URI to the share.</param> /// <param name="credentials">A <see cref="StorageCredentials"/> object.</param> public CloudFileShare(StorageUri shareAddress, StorageCredentials credentials) : this(shareAddress, null /* snapshotTime */, credentials) { }
public RESTCommand(StorageCredentials credentials, StorageUri storageUri, UriQueryBuilder builder) { this.Credentials = credentials; this.StorageUri = storageUri; this.Builder = builder; }