| | 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.Text; |
| | 7 | |
|
| | 8 | | namespace Azure.Storage.Sas |
| | 9 | | { |
| | 10 | | /// <summary> |
| | 11 | | /// A <see cref="BlobSasQueryParameters"/> object represents the components |
| | 12 | | /// that make up an Azure Storage Shared Access Signature's query |
| | 13 | | /// parameters. You can construct a new instance using |
| | 14 | | /// <see cref="BlobSasBuilder"/>. |
| | 15 | | /// |
| | 16 | | /// For more information, |
| | 17 | | /// <see href="https://docs.microsoft.com/rest/api/storageservices/create-service-sas"> |
| | 18 | | /// Create a service SAS</see>. |
| | 19 | | /// </summary> |
| | 20 | | public sealed class BlobSasQueryParameters : SasQueryParameters |
| | 21 | | { |
| 912 | 22 | | internal UserDelegationKeyProperties KeyProperties { get; set; } |
| | 23 | |
|
| | 24 | | /// <summary> |
| | 25 | | /// Gets the Azure Active Directory object ID in GUID format. |
| | 26 | | /// </summary> |
| 24 | 27 | | public string KeyObjectId => KeyProperties?.ObjectId; |
| | 28 | |
|
| | 29 | | /// <summary> |
| | 30 | | /// Gets the Azure Active Directory tenant ID in GUID format |
| | 31 | | /// </summary> |
| 24 | 32 | | public string KeyTenantId => KeyProperties?.TenantId; |
| | 33 | |
|
| | 34 | | /// <summary> |
| | 35 | | /// Gets the time at which the key becomes valid. |
| | 36 | | /// </summary> |
| 24 | 37 | | public DateTimeOffset KeyStartsOn => KeyProperties == null ? default : KeyProperties.StartsOn; |
| | 38 | |
|
| | 39 | | /// <summary> |
| | 40 | | /// Gets the time at which the key becomes expires. |
| | 41 | | /// </summary> |
| 24 | 42 | | public DateTimeOffset KeyExpiresOn => KeyProperties == null ? default : KeyProperties.ExpiresOn; |
| | 43 | |
|
| | 44 | | /// <summary> |
| | 45 | | /// Gets the Storage service that accepts the key. |
| | 46 | | /// </summary> |
| 24 | 47 | | public string KeyService => KeyProperties?.Service; |
| | 48 | |
|
| | 49 | | /// <summary> |
| | 50 | | /// Gets the Storage service version that created the key. |
| | 51 | | /// </summary> |
| 12 | 52 | | public string KeyVersion => KeyProperties?.Version; |
| | 53 | |
|
| | 54 | | /// <summary> |
| | 55 | | /// Gets empty shared access signature query parameters. |
| | 56 | | /// </summary> |
| 0 | 57 | | public static new BlobSasQueryParameters Empty => new BlobSasQueryParameters(); |
| | 58 | |
|
| | 59 | | internal BlobSasQueryParameters() |
| 0 | 60 | | : base() |
| | 61 | | { |
| 0 | 62 | | } |
| | 63 | |
|
| | 64 | | /// <summary> |
| | 65 | | /// Creates a new BlobSasQueryParameters instance. |
| | 66 | | /// </summary> |
| | 67 | | internal BlobSasQueryParameters ( |
| | 68 | | string version, |
| | 69 | | AccountSasServices? services, |
| | 70 | | AccountSasResourceTypes? resourceTypes, |
| | 71 | | SasProtocol protocol, |
| | 72 | | DateTimeOffset startsOn, |
| | 73 | | DateTimeOffset expiresOn, |
| | 74 | | SasIPRange ipRange, |
| | 75 | | string identifier, |
| | 76 | | string resource, |
| | 77 | | string permissions, |
| | 78 | | string signature, |
| | 79 | | string keyOid = default, |
| | 80 | | string keyTid = default, |
| | 81 | | DateTimeOffset keyStart = default, |
| | 82 | | DateTimeOffset keyExpiry = default, |
| | 83 | | string keyService = default, |
| | 84 | | string keyVersion = default, |
| | 85 | | string cacheControl = default, |
| | 86 | | string contentDisposition = default, |
| | 87 | | string contentEncoding = default, |
| | 88 | | string contentLanguage = default, |
| | 89 | | string contentType = default) |
| 188 | 90 | | : base( |
| 188 | 91 | | version, |
| 188 | 92 | | services, |
| 188 | 93 | | resourceTypes, |
| 188 | 94 | | protocol, |
| 188 | 95 | | startsOn, |
| 188 | 96 | | expiresOn, |
| 188 | 97 | | ipRange, |
| 188 | 98 | | identifier, |
| 188 | 99 | | resource, |
| 188 | 100 | | permissions, |
| 188 | 101 | | signature, |
| 188 | 102 | | cacheControl, |
| 188 | 103 | | contentDisposition, |
| 188 | 104 | | contentEncoding, |
| 188 | 105 | | contentLanguage, |
| 188 | 106 | | contentType) |
| | 107 | | { |
| 188 | 108 | | KeyProperties = new UserDelegationKeyProperties |
| 188 | 109 | | { |
| 188 | 110 | | ObjectId = keyOid, |
| 188 | 111 | | TenantId = keyTid, |
| 188 | 112 | | StartsOn = keyStart, |
| 188 | 113 | | ExpiresOn = keyExpiry, |
| 188 | 114 | | Service = keyService, |
| 188 | 115 | | Version = keyVersion |
| 188 | 116 | | }; |
| 188 | 117 | | } |
| | 118 | |
|
| | 119 | | /// <summary> |
| | 120 | | /// Creates a new instance of the <see cref="BlobSasQueryParameters"/> |
| | 121 | | /// type based on the supplied query parameters <paramref name="values"/>. |
| | 122 | | /// All SAS-related query parameters will be removed from |
| | 123 | | /// <paramref name="values"/>. |
| | 124 | | /// </summary> |
| | 125 | | /// <param name="values">URI query parameters</param> |
| | 126 | | internal BlobSasQueryParameters ( |
| | 127 | | IDictionary<string, string> values) |
| 148 | 128 | | : base(values) |
| | 129 | | { |
| 148 | 130 | | this.ParseKeyProperties(values); |
| 148 | 131 | | } |
| | 132 | |
|
| | 133 | | /// <summary> |
| | 134 | | /// Convert the SAS query parameters into a URL encoded query string. |
| | 135 | | /// </summary> |
| | 136 | | /// <returns> |
| | 137 | | /// A URL encoded query string representing the SAS. |
| | 138 | | /// </returns> |
| | 139 | | public override string ToString() |
| | 140 | | { |
| 276 | 141 | | StringBuilder sb = new StringBuilder(); |
| 276 | 142 | | KeyProperties.AppendProperties(sb); |
| 276 | 143 | | this.AppendProperties(sb); |
| 276 | 144 | | return sb.ToString(); |
| | 145 | | } |
| | 146 | | } |
| | 147 | | } |