PageRenderTime 63ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/ServiceManagement/RemoteApp/Commands.RemoteApp/Common/RemoteAppRegEx.cs

https://gitlab.com/jslee1/azure-powershell
C# | 123 lines | 28 code | 23 blank | 72 comment | 0 complexity | 2115a9e52fc14045059c61e5e5c5b4fd MD5 | raw file
  1. // ----------------------------------------------------------------------------------
  2. //
  3. // Copyright Microsoft Corporation
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. // ----------------------------------------------------------------------------------
  14. namespace Microsoft.WindowsAzure.Management.RemoteApp.Cmdlets
  15. {
  16. public abstract partial class RdsCmdlet
  17. {
  18. protected const string NameValidatorStringWithWildCards = @"^[?*A-Za-z0-9\u007F-\uFFFF]{1,13}$";
  19. protected const string NameValidatorString = @"^[A-Za-z][A-Za-z0-9\u007F-\uFFFF]{2,12}$";
  20. protected const string VNetNameValidatorStringWithWildCards = @"^[?*A-Za-z][?*-A-Za-z0-9]{3,49}(?<!-)$";
  21. protected const string VNetNameValidatorString = @"^[A-Za-z][-A-Za-z0-9]{3,49}(?<!-)$";
  22. protected const string DomainNameValidatorString = @"[^,~:@#$%\^&'.(){}_\s]+([.][^,~:@#$%\^&'.(){}_\s]+)+";
  23. protected const string UserNameValidatorString = @"[^@\""/\[\]:;|=,+*?<>\s]+";
  24. protected const string UserPrincipalValdatorString = UserNameValidatorString + "@" + DomainNameValidatorString;
  25. protected const string ListTemplateImageNameValidatorString = @"^[()A-Za-z][() ._\-A-Za-z0-9]{1,61}[A-Z-a-z0-9()]$";
  26. protected const string TemplateImageNameValidatorString = @"^[A-Za-z][ ._\-A-Za-z0-9]{1,61}[A-Z-a-z0-9]$";
  27. protected const string IPv4ValidatorString = @"^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])$";
  28. protected const string IPv6ValidatorString = @"(?<![:.\w])(?:[A-F0-9]{1,4}:){7}[A-F0-9]{1,4}(?![:.\w])";
  29. protected const string IPv4CIDR = @"^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(\d|[1-2]\d|3[0-2]))$";
  30. protected const string IPv6CIDR = @"^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))\s*(\/(1[01][0-9]|12[0-8]|[0-9]{1,2}))$";
  31. // uppercase key code, must begin with a letter, then letters, numbers, and hyphens, for e.g. STREET or DC-9
  32. protected const string keyRegexPattern = @"[A-Z][A-Z0-9\-]*";
  33. // explicit key name for OU element
  34. protected const string ouKeyRegexPattern = @"OU";
  35. // used to separate entities, , or + followed by 0 or more spaces
  36. protected const string delimiterRegexPattern = @"[\+,]\s*";
  37. // an entity value, consists of characters other than , <CR> < > " # ; + =
  38. protected const string entityRegexPattern = @"([^,<>""#;+=\r\n])+";
  39. // a key/entity pair, e.g DC=foo-bar.com
  40. protected const string keyEntityRegexPattern = @"(" + keyRegexPattern + @"=" + entityRegexPattern + @")";
  41. // an OU key/entity pair, e.g OU=MyOu, but only matches an OU entity
  42. protected const string ouKeyEntityRegexPattern = @"(" + ouKeyRegexPattern + @"=" + entityRegexPattern + @")";
  43. protected const string OrgIDValidatorString = @"^(" + keyEntityRegexPattern + @"[\+,]\s*)*" + ouKeyEntityRegexPattern + @"([\+,]\s*" + keyEntityRegexPattern + @")*$";
  44. /* OrganizationalUnit in DN format: OU=MyOu, CN=MyDomain, CN=Com
  45. *
  46. * The following pattern is designed to accept an RFC 4514 compliant distinguished name wich contains at least 1 OU element
  47. * e.g OU=MyOu, CN=MyDomain, CN=Com
  48. *
  49. * The pattern can be broken down into 3 main components
  50. *
  51. * The first component is 0 or more entities that are not OU entities, followed by a + or + delimiter
  52. * ^(
  53. * (
  54. * The entity begins with a key which must begin with a letter and contains letters, digits, or hyphens
  55. * [A-Z][A-Z0-9\-]*=
  56. * (
  57. * The entity value contains one or more characters except for the special chars , \ <CR> = < > " # ; or +
  58. * [^,<>""#;\+=\r\n]
  59. * There will be 1 or more characters matching this pattern
  60. * )+
  61. * Followed by a delimeter, either , or +
  62. * [\+,]\s*
  63. * There may be 0 or more entities matching this pattern
  64. * )*
  65. *
  66. * The second part or the pattern must match an OU entity
  67. * This is identical to the first part, except it must only match the OU entity key
  68. * and does not include a delimiter. If present, a trailing delimiter is matched by the preceding part of the pattern
  69. * (
  70. * The entity key must match OU exactly. This guarantees the overall pattern contains at least oen OU element
  71. * OU=
  72. * (
  73. * The entity value contains one or more characters except for the special chars , \ <CR> = < > " # ; or +
  74. * [^,<>""#;\+=\r\n]
  75. * There will be 1 or more characters matching this pattern
  76. * )+
  77. * )
  78. *
  79. * The final component of the pattern matches 0 or more additional elements, almost identical to the
  80. * first component of the pattern, except the delimeters are now leading
  81. * (
  82. * This compoennt of the pattern begins with a , or + delimiter
  83. * [\+,]\s*
  84. * (
  85. * The entity begins with a key which must begin with a letter and contains letters, digits, or hyphens
  86. * [A-Z][A-Z0-9\-]*=
  87. * (
  88. * The entity value contains one or more characters except for the special chars , \ <CR> = < > " # ; or +
  89. * [^,<>""#;\+=\r\n]
  90. * There will be 1 or more characters matching this pattern
  91. * )+
  92. * )
  93. * There may be 0 or more entities matching this pattern, and then the end of the string
  94. * )*$
  95. *
  96. */
  97. protected const string FullYearPattern = @"^(19|20)\d\d$";
  98. protected const string TwoDigitMonthPattern = @"^(0[1-9]|1[0-2])$";
  99. }
  100. }