| | 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.Storage.Sas |
| | 11 | | { |
| | 12 | | internal static class SasQueryParametersExtensions |
| | 13 | | { |
| | 14 | | /// <summary> |
| | 15 | | /// Parses the key properties into the QueryParameters instance. |
| | 16 | | /// </summary> |
| | 17 | | /// <param name="parameters"> |
| | 18 | | /// The BlobSasQueryParameters or DataLakeSasQueryParameters instance. |
| | 19 | | /// </param> |
| | 20 | | /// <param name="values"> |
| | 21 | | /// Dictionary of keys and values. |
| | 22 | | /// </param> |
| | 23 | | internal static void ParseKeyProperties( |
| | 24 | | this |
| | 25 | | #if BlobSDK |
| | 26 | | BlobSasQueryParameters |
| | 27 | | #elif DataLakeSDK |
| | 28 | | DataLakeSasQueryParameters |
| | 29 | | #endif |
| | 30 | | parameters, |
| | 31 | | IDictionary<string, string> values) |
| | 32 | | { |
| | 33 | | // make copy, otherwise we'll get an exception when we remove |
| 148 | 34 | | IEnumerable<KeyValuePair<string, string>> kvps = values.ToArray(); |
| 148 | 35 | | parameters.KeyProperties = new UserDelegationKeyProperties(); |
| 536 | 36 | | foreach (KeyValuePair<string, string> kv in kvps) |
| | 37 | | { |
| 120 | 38 | | var isSasKey = true; |
| | 39 | | // these are already decoded |
| 120 | 40 | | switch (kv.Key.ToUpperInvariant()) |
| | 41 | | { |
| | 42 | | case Constants.Sas.Parameters.KeyObjectIdUpper: |
| 20 | 43 | | parameters.KeyProperties.ObjectId = kv.Value; |
| 20 | 44 | | break; |
| | 45 | | case Constants.Sas.Parameters.KeyTenantIdUpper: |
| 20 | 46 | | parameters.KeyProperties.TenantId = kv.Value; |
| 20 | 47 | | break; |
| | 48 | | case Constants.Sas.Parameters.KeyStartUpper: |
| 20 | 49 | | parameters.KeyProperties.StartsOn = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat, |
| 20 | 50 | | break; |
| | 51 | | case Constants.Sas.Parameters.KeyExpiryUpper: |
| 20 | 52 | | parameters.KeyProperties.ExpiresOn = DateTimeOffset.ParseExact(kv.Value, Constants.SasTimeFormat |
| 20 | 53 | | break; |
| | 54 | | case Constants.Sas.Parameters.KeyServiceUpper: |
| 20 | 55 | | parameters.KeyProperties.Service = kv.Value; |
| 20 | 56 | | break; |
| | 57 | | case Constants.Sas.Parameters.KeyVersionUpper: |
| 20 | 58 | | parameters.KeyProperties.Version = kv.Value; |
| 20 | 59 | | break; |
| | 60 | |
|
| | 61 | | default: |
| 0 | 62 | | isSasKey = false; |
| | 63 | | break; |
| | 64 | | } |
| | 65 | |
|
| | 66 | | // Remove the query parameter if it's part of the SAS |
| 120 | 67 | | if (isSasKey) |
| | 68 | | { |
| 120 | 69 | | values.Remove(kv.Key); |
| | 70 | | } |
| | 71 | | } |
| 148 | 72 | | } |
| | 73 | | } |
| | 74 | | } |