| | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | 2 | | // Licensed under the MIT License. |
| | 3 | |
|
| | 4 | | using System; |
| | 5 | | using System.Collections.Generic; |
| | 6 | | using System.Globalization; |
| | 7 | | using System.Linq; |
| | 8 | | using System.Text; |
| | 9 | |
|
| | 10 | | namespace Azure.Data.Tables.Sas |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// A <see cref="TableSasQueryParameters"/> object represents the components |
| | 14 | | /// that make up an Azure Storage Shared Access Signature's query |
| | 15 | | /// parameters. You can construct a new instance using |
| | 16 | | /// <see cref="TableSasBuilder"/>. |
| | 17 | | /// |
| | 18 | | /// For more information, <see href="https://docs.microsoft.com/rest/api/storageservices/create-service-sas">Create |
| | 19 | | /// </summary> |
| | 20 | | public sealed class TableSasQueryParameters : TableAccountSasQueryParameters |
| | 21 | | { |
| 16 | 22 | | internal string TableName { get; set; } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// The start of PartionKey range. |
| | 26 | | /// </summary> |
| 16 | 27 | | public string StartPartitionKey { get; set; } |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// The end of PartionKey range. |
| | 31 | | /// </summary> |
| 16 | 32 | | public string StartRowKey { get; set; } |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// The start of RowKey range. |
| | 36 | | /// </summary> |
| 16 | 37 | | public string EndPartitionKey { get; set; } |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// The end of RowKey range. |
| | 41 | | /// </summary> |
| 16 | 42 | | public string EndRowKey { get; set; } |
| | 43 | |
|
| | 44 | |
|
| 0 | 45 | | public static TableSasQueryParameters Empty => new TableSasQueryParameters(); |
| | 46 | |
|
| | 47 | | internal TableSasQueryParameters() |
| 0 | 48 | | : base() |
| | 49 | | { |
| 0 | 50 | | } |
| | 51 | |
|
| | 52 | | /// <summary> |
| | 53 | | /// Creates a new TableSasQueryParameters instance. |
| | 54 | | /// </summary> |
| | 55 | | internal TableSasQueryParameters( |
| | 56 | | string version, |
| | 57 | | TableAccountSasResourceTypes? resourceTypes, |
| | 58 | | string tableName, |
| | 59 | | string partitionKeyStart, |
| | 60 | | string rowKeyStart, |
| | 61 | | string partitionKeyEnd, |
| | 62 | | string rowKeyEnd, |
| | 63 | | TableSasProtocol protocol, |
| | 64 | | DateTimeOffset startsOn, |
| | 65 | | DateTimeOffset expiresOn, |
| | 66 | | TableSasIPRange ipRange, |
| | 67 | | string identifier, |
| | 68 | | string resource, |
| | 69 | | string permissions, |
| | 70 | | string signature) |
| 8 | 71 | | : base( |
| 8 | 72 | | version, |
| 8 | 73 | | resourceTypes, |
| 8 | 74 | | protocol, |
| 8 | 75 | | startsOn, |
| 8 | 76 | | expiresOn, |
| 8 | 77 | | ipRange, |
| 8 | 78 | | identifier, |
| 8 | 79 | | resource, |
| 8 | 80 | | permissions, |
| 8 | 81 | | signature) |
| | 82 | | { |
| 8 | 83 | | TableName = tableName; |
| 8 | 84 | | StartPartitionKey = partitionKeyStart; |
| 8 | 85 | | EndPartitionKey = partitionKeyEnd; |
| 8 | 86 | | StartRowKey = rowKeyStart; |
| 8 | 87 | | EndRowKey = rowKeyEnd; |
| 8 | 88 | | } |
| | 89 | |
|
| | 90 | | /// <summary> |
| | 91 | | /// Creates a new instance of the <see cref="TableSasQueryParameters"/> |
| | 92 | | /// type based on the supplied query parameters <paramref name="values"/>. |
| | 93 | | /// All SAS-related query parameters will be removed from |
| | 94 | | /// <paramref name="values"/>. |
| | 95 | | /// </summary> |
| | 96 | | /// <param name="values">URI query parameters</param> |
| | 97 | | internal TableSasQueryParameters( |
| | 98 | | IDictionary<string, string> values) |
| 0 | 99 | | : base(values) |
| 0 | 100 | | {} |
| | 101 | |
|
| | 102 | | /// <summary> |
| | 103 | | /// Convert the SAS query parameters into a URL encoded query string. |
| | 104 | | /// </summary> |
| | 105 | | /// <returns> |
| | 106 | | /// A URL encoded query string representing the SAS. |
| | 107 | | /// </returns> |
| | 108 | | public override string ToString() |
| | 109 | | { |
| 8 | 110 | | StringBuilder sb = new StringBuilder(); |
| 8 | 111 | | sb.AppendQueryParameter(TableConstants.Sas.Parameters.TableName, TableName); |
| 8 | 112 | | if (!string.IsNullOrWhiteSpace(StartPartitionKey)) |
| | 113 | | { |
| 0 | 114 | | sb.AppendQueryParameter(TableConstants.Sas.Parameters.StartPartitionKey, StartPartitionKey); |
| | 115 | | } |
| 8 | 116 | | if (!string.IsNullOrWhiteSpace(EndPartitionKey)) |
| | 117 | | { |
| 0 | 118 | | sb.AppendQueryParameter(TableConstants.Sas.Parameters.EndPartitionKey, EndPartitionKey); |
| | 119 | | } |
| 8 | 120 | | if (!string.IsNullOrWhiteSpace(StartRowKey)) |
| | 121 | | { |
| 0 | 122 | | sb.AppendQueryParameter(TableConstants.Sas.Parameters.StartRowKey, StartRowKey); |
| | 123 | | } |
| 8 | 124 | | if (!string.IsNullOrWhiteSpace(EndRowKey)) |
| | 125 | | { |
| 0 | 126 | | sb.AppendQueryParameter(TableConstants.Sas.Parameters.EndRowKey, EndRowKey); |
| | 127 | | } |
| 8 | 128 | | this.AppendProperties(sb); |
| 8 | 129 | | return sb.ToString(); |
| | 130 | | } |
| | 131 | | } |
| | 132 | | } |