| | | 1 | | // Copyright (c) Microsoft Corporation. All rights reserved. |
| | | 2 | | // Licensed under the MIT License. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Globalization; |
| | | 6 | | |
| | | 7 | | namespace Azure.Security.KeyVault.Secrets |
| | | 8 | | { |
| | | 9 | | internal struct ObjectId |
| | | 10 | | { |
| | 33556 | 11 | | public Uri Id { get; set; } |
| | | 12 | | |
| | 1544 | 13 | | public Uri VaultUri { get; set; } |
| | | 14 | | |
| | 46100 | 15 | | public string Name { get; set; } |
| | | 16 | | |
| | 1596 | 17 | | public string Version { get; set; } |
| | | 18 | | |
| | 1544 | 19 | | public void ParseId(string collection, string id) => ParseId(collection, new Uri(id, UriKind.Absolute)); |
| | | 20 | | |
| | | 21 | | public void ParseId(string collection, Uri id) |
| | | 22 | | { |
| | 1544 | 23 | | Id = id; |
| | | 24 | | |
| | | 25 | | // We expect an identifier with either 3 or 4 segments: host + collection + name [+ version] |
| | 1544 | 26 | | if (Id.Segments.Length != 3 && Id.Segments.Length != 4) |
| | 0 | 27 | | throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ObjectIdentifier: {0}. |
| | | 28 | | |
| | 1544 | 29 | | if (!string.Equals(Id.Segments[1], collection + "/", StringComparison.OrdinalIgnoreCase)) |
| | 0 | 30 | | throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid ObjectIdentifier: {0}. |
| | | 31 | | |
| | 1544 | 32 | | VaultUri = new Uri($"{Id.Scheme}://{Id.Authority}"); |
| | 1544 | 33 | | Name = Id.Segments[2].Trim('/'); |
| | 1544 | 34 | | Version = (Id.Segments.Length == 4) ? Id.Segments[3].TrimEnd('/') : null; |
| | 1544 | 35 | | } |
| | | 36 | | } |
| | | 37 | | } |