@autorest/powershell 4.0.0-dev.8 → 4.0.617

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (316) hide show
  1. package/.rush/temp/operation/build/state.json +3 -0
  2. package/.rush/temp/package-deps_build.json +106 -103
  3. package/.rush/temp/shrinkwrap-deps.json +182 -234
  4. package/dist/cmdlets/class.d.ts +12 -1
  5. package/dist/cmdlets/class.d.ts.map +1 -1
  6. package/dist/cmdlets/class.js +693 -532
  7. package/dist/cmdlets/class.js.map +1 -1
  8. package/dist/cmdlets/namespace.d.ts.map +1 -1
  9. package/dist/cmdlets/namespace.js +38 -5
  10. package/dist/cmdlets/namespace.js.map +1 -1
  11. package/dist/enums/namespace.js +5 -5
  12. package/dist/enums/namespace.js.map +1 -1
  13. package/dist/generators/psm1.custom.js +2 -2
  14. package/dist/generators/psm1.custom.js.map +1 -1
  15. package/dist/generators/psm1.internal.js +2 -2
  16. package/dist/generators/psm1.internal.js.map +1 -1
  17. package/dist/generators/psm1.js +1 -1
  18. package/dist/generators/psm1.js.map +1 -1
  19. package/dist/generators/script-cmdlet.js +18 -18
  20. package/dist/generators/script-cmdlet.js.map +1 -1
  21. package/dist/internal/name-inferrer.d.ts +1 -1
  22. package/dist/internal/name-inferrer.d.ts.map +1 -1
  23. package/dist/internal/name-inferrer.js +12 -12
  24. package/dist/internal/name-inferrer.js.map +1 -1
  25. package/dist/internal/powershell-declarations.d.ts +2 -0
  26. package/dist/internal/powershell-declarations.d.ts.map +1 -1
  27. package/dist/internal/powershell-declarations.js +4 -2
  28. package/dist/internal/powershell-declarations.js.map +1 -1
  29. package/dist/internal/project.d.ts +3 -5
  30. package/dist/internal/project.d.ts.map +1 -1
  31. package/dist/internal/project.js +14 -18
  32. package/dist/internal/project.js.map +1 -1
  33. package/dist/internal/state.d.ts +1 -1
  34. package/dist/internal/state.d.ts.map +1 -1
  35. package/dist/llcsharp/clientruntime.d.ts +1 -0
  36. package/dist/llcsharp/clientruntime.d.ts.map +1 -1
  37. package/dist/llcsharp/clientruntime.js +12 -11
  38. package/dist/llcsharp/clientruntime.js.map +1 -1
  39. package/dist/llcsharp/code-model.d.ts +7 -7
  40. package/dist/llcsharp/code-model.d.ts.map +1 -1
  41. package/dist/llcsharp/enums/enum.d.ts +1 -1
  42. package/dist/llcsharp/enums/enum.d.ts.map +1 -1
  43. package/dist/llcsharp/enums/enum.js +42 -42
  44. package/dist/llcsharp/enums/enum.js.map +1 -1
  45. package/dist/llcsharp/exports.js +5 -1
  46. package/dist/llcsharp/exports.js.map +1 -1
  47. package/dist/llcsharp/generator.d.ts +1 -1
  48. package/dist/llcsharp/generator.d.ts.map +1 -1
  49. package/dist/llcsharp/model/idictionary.js +16 -16
  50. package/dist/llcsharp/model/idictionary.js.map +1 -1
  51. package/dist/llcsharp/model/interface.d.ts +1 -1
  52. package/dist/llcsharp/model/interface.d.ts.map +1 -1
  53. package/dist/llcsharp/model/interface.js +25 -11
  54. package/dist/llcsharp/model/interface.js.map +1 -1
  55. package/dist/llcsharp/model/model-class-dictionary.js +18 -18
  56. package/dist/llcsharp/model/model-class-dictionary.js.map +1 -1
  57. package/dist/llcsharp/model/model-class-json.js +19 -19
  58. package/dist/llcsharp/model/model-class-json.js.map +1 -1
  59. package/dist/llcsharp/model/model-class-serializer.d.ts +1 -1
  60. package/dist/llcsharp/model/model-class-serializer.d.ts.map +1 -1
  61. package/dist/llcsharp/model/model-class-serializer.js +6 -6
  62. package/dist/llcsharp/model/model-class-serializer.js.map +1 -1
  63. package/dist/llcsharp/model/model-class.d.ts +1 -1
  64. package/dist/llcsharp/model/model-class.d.ts.map +1 -1
  65. package/dist/llcsharp/model/model-class.js +97 -89
  66. package/dist/llcsharp/model/model-class.js.map +1 -1
  67. package/dist/llcsharp/model/namespace.d.ts +1 -1
  68. package/dist/llcsharp/model/namespace.d.ts.map +1 -1
  69. package/dist/llcsharp/model/namespace.js +4 -12
  70. package/dist/llcsharp/model/namespace.js.map +1 -1
  71. package/dist/llcsharp/model/property.d.ts +1 -1
  72. package/dist/llcsharp/model/property.d.ts.map +1 -1
  73. package/dist/llcsharp/model/property.js +20 -20
  74. package/dist/llcsharp/model/property.js.map +1 -1
  75. package/dist/llcsharp/operation/api-class.d.ts.map +1 -1
  76. package/dist/llcsharp/operation/api-class.js +26 -1
  77. package/dist/llcsharp/operation/api-class.js.map +1 -1
  78. package/dist/llcsharp/operation/method.d.ts +10 -5
  79. package/dist/llcsharp/operation/method.d.ts.map +1 -1
  80. package/dist/llcsharp/operation/method.js +276 -134
  81. package/dist/llcsharp/operation/method.js.map +1 -1
  82. package/dist/llcsharp/operation/parameter.d.ts +1 -1
  83. package/dist/llcsharp/operation/parameter.d.ts.map +1 -1
  84. package/dist/llcsharp/operation/parameter.js +10 -10
  85. package/dist/llcsharp/operation/parameter.js.map +1 -1
  86. package/dist/llcsharp/project.d.ts +4 -2
  87. package/dist/llcsharp/project.d.ts.map +1 -1
  88. package/dist/llcsharp/project.js +11 -3
  89. package/dist/llcsharp/project.js.map +1 -1
  90. package/dist/llcsharp/schema/Uuid.d.ts +1 -1
  91. package/dist/llcsharp/schema/Uuid.d.ts.map +1 -1
  92. package/dist/llcsharp/schema/Uuid.js +2 -2
  93. package/dist/llcsharp/schema/Uuid.js.map +1 -1
  94. package/dist/llcsharp/schema/array.d.ts +1 -1
  95. package/dist/llcsharp/schema/array.d.ts.map +1 -1
  96. package/dist/llcsharp/schema/array.js +45 -43
  97. package/dist/llcsharp/schema/array.js.map +1 -1
  98. package/dist/llcsharp/schema/binary.d.ts +1 -1
  99. package/dist/llcsharp/schema/binary.d.ts.map +1 -1
  100. package/dist/llcsharp/schema/binary.js +9 -9
  101. package/dist/llcsharp/schema/binary.js.map +1 -1
  102. package/dist/llcsharp/schema/boolean.d.ts +1 -1
  103. package/dist/llcsharp/schema/boolean.d.ts.map +1 -1
  104. package/dist/llcsharp/schema/byte-array.d.ts +1 -1
  105. package/dist/llcsharp/schema/byte-array.d.ts.map +1 -1
  106. package/dist/llcsharp/schema/byte-array.js +24 -24
  107. package/dist/llcsharp/schema/byte-array.js.map +1 -1
  108. package/dist/llcsharp/schema/char.d.ts +1 -1
  109. package/dist/llcsharp/schema/char.d.ts.map +1 -1
  110. package/dist/llcsharp/schema/char.js +1 -1
  111. package/dist/llcsharp/schema/char.js.map +1 -1
  112. package/dist/llcsharp/schema/date-time.d.ts +1 -1
  113. package/dist/llcsharp/schema/date-time.d.ts.map +1 -1
  114. package/dist/llcsharp/schema/date-time.js +45 -41
  115. package/dist/llcsharp/schema/date-time.js.map +1 -1
  116. package/dist/llcsharp/schema/date.d.ts +1 -1
  117. package/dist/llcsharp/schema/date.d.ts.map +1 -1
  118. package/dist/llcsharp/schema/duration.d.ts +1 -1
  119. package/dist/llcsharp/schema/duration.d.ts.map +1 -1
  120. package/dist/llcsharp/schema/duration.js +9 -7
  121. package/dist/llcsharp/schema/duration.js.map +1 -1
  122. package/dist/llcsharp/schema/enum.d.ts +6 -2
  123. package/dist/llcsharp/schema/enum.d.ts.map +1 -1
  124. package/dist/llcsharp/schema/enum.js +13 -4
  125. package/dist/llcsharp/schema/enum.js.map +1 -1
  126. package/dist/llcsharp/schema/extended-type-declaration.d.ts +1 -1
  127. package/dist/llcsharp/schema/extended-type-declaration.d.ts.map +1 -1
  128. package/dist/llcsharp/schema/fixed-array.d.ts +1 -1
  129. package/dist/llcsharp/schema/fixed-array.d.ts.map +1 -1
  130. package/dist/llcsharp/schema/fixed-array.js +44 -42
  131. package/dist/llcsharp/schema/fixed-array.js.map +1 -1
  132. package/dist/llcsharp/schema/integer.d.ts +1 -1
  133. package/dist/llcsharp/schema/integer.d.ts.map +1 -1
  134. package/dist/llcsharp/schema/integer.js +5 -5
  135. package/dist/llcsharp/schema/integer.js.map +1 -1
  136. package/dist/llcsharp/schema/object.d.ts +1 -1
  137. package/dist/llcsharp/schema/object.d.ts.map +1 -1
  138. package/dist/llcsharp/schema/object.js +28 -28
  139. package/dist/llcsharp/schema/object.js.map +1 -1
  140. package/dist/llcsharp/schema/password.d.ts +1 -1
  141. package/dist/llcsharp/schema/password.d.ts.map +1 -1
  142. package/dist/llcsharp/schema/password.js +13 -13
  143. package/dist/llcsharp/schema/password.js.map +1 -1
  144. package/dist/llcsharp/schema/primitive.d.ts +1 -1
  145. package/dist/llcsharp/schema/primitive.d.ts.map +1 -1
  146. package/dist/llcsharp/schema/primitive.js +40 -37
  147. package/dist/llcsharp/schema/primitive.js.map +1 -1
  148. package/dist/llcsharp/schema/schema-resolver.d.ts +1 -1
  149. package/dist/llcsharp/schema/schema-resolver.d.ts.map +1 -1
  150. package/dist/llcsharp/schema/schema-resolver.js +4 -9
  151. package/dist/llcsharp/schema/schema-resolver.js.map +1 -1
  152. package/dist/llcsharp/schema/string.d.ts +1 -1
  153. package/dist/llcsharp/schema/string.d.ts.map +1 -1
  154. package/dist/llcsharp/schema/string.js +48 -44
  155. package/dist/llcsharp/schema/string.js.map +1 -1
  156. package/dist/llcsharp/schema/uri.d.ts +1 -1
  157. package/dist/llcsharp/schema/uri.d.ts.map +1 -1
  158. package/dist/llcsharp/schema/uri.js +2 -2
  159. package/dist/llcsharp/schema/uri.js.map +1 -1
  160. package/dist/llcsharp/validations.js +2 -2
  161. package/dist/llcsharp/validations.js.map +1 -1
  162. package/dist/main.js +2 -2
  163. package/dist/main.js.map +1 -1
  164. package/dist/models/model-extensions.d.ts +1 -1
  165. package/dist/models/model-extensions.d.ts.map +1 -1
  166. package/dist/models/model-extensions.js +39 -39
  167. package/dist/models/model-extensions.js.map +1 -1
  168. package/dist/module/module-class.js +8 -8
  169. package/dist/module/module-class.js.map +1 -1
  170. package/dist/module/module-namespace.js +3 -3
  171. package/dist/module/module-namespace.js.map +1 -1
  172. package/dist/plugins/add-azure-completers-v2.d.ts +1 -1
  173. package/dist/plugins/add-azure-completers-v2.d.ts.map +1 -1
  174. package/dist/plugins/add-azure-completers-v2.js +3 -3
  175. package/dist/plugins/add-azure-completers-v2.js.map +1 -1
  176. package/dist/plugins/create-commands-v2.d.ts +9 -7
  177. package/dist/plugins/create-commands-v2.d.ts.map +1 -1
  178. package/dist/plugins/create-commands-v2.js +233 -62
  179. package/dist/plugins/create-commands-v2.js.map +1 -1
  180. package/dist/plugins/cs-namer-v2.d.ts +1 -1
  181. package/dist/plugins/cs-namer-v2.d.ts.map +1 -1
  182. package/dist/plugins/cs-namer-v2.js +40 -40
  183. package/dist/plugins/cs-namer-v2.js.map +1 -1
  184. package/dist/plugins/llcsharp-v2.d.ts +1 -1
  185. package/dist/plugins/llcsharp-v2.d.ts.map +1 -1
  186. package/dist/plugins/llcsharp-v2.js +12 -7
  187. package/dist/plugins/llcsharp-v2.js.map +1 -1
  188. package/dist/plugins/modifiers-v2.d.ts +1 -1
  189. package/dist/plugins/modifiers-v2.d.ts.map +1 -1
  190. package/dist/plugins/modifiers-v2.js +109 -78
  191. package/dist/plugins/modifiers-v2.js.map +1 -1
  192. package/dist/plugins/plugin-create-inline-properties.d.ts +1 -1
  193. package/dist/plugins/plugin-create-inline-properties.d.ts.map +1 -1
  194. package/dist/plugins/plugin-create-inline-properties.js +42 -31
  195. package/dist/plugins/plugin-create-inline-properties.js.map +1 -1
  196. package/dist/plugins/plugin-tweak-m4-model.d.ts +1 -1
  197. package/dist/plugins/plugin-tweak-m4-model.d.ts.map +1 -1
  198. package/dist/plugins/plugin-tweak-m4-model.js +19 -7
  199. package/dist/plugins/plugin-tweak-m4-model.js.map +1 -1
  200. package/dist/plugins/plugin-tweak-model-azure-v2.d.ts +1 -1
  201. package/dist/plugins/plugin-tweak-model-azure-v2.d.ts.map +1 -1
  202. package/dist/plugins/plugin-tweak-model-azure-v2.js +17 -17
  203. package/dist/plugins/plugin-tweak-model-azure-v2.js.map +1 -1
  204. package/dist/plugins/plugin-tweak-model.d.ts +1 -1
  205. package/dist/plugins/plugin-tweak-model.d.ts.map +1 -1
  206. package/dist/plugins/plugin-tweak-model.js +31 -31
  207. package/dist/plugins/plugin-tweak-model.js.map +1 -1
  208. package/dist/plugins/powershell-v2.d.ts +1 -1
  209. package/dist/plugins/powershell-v2.d.ts.map +1 -1
  210. package/dist/plugins/powershell-v2.js +26 -26
  211. package/dist/plugins/powershell-v2.js.map +1 -1
  212. package/dist/plugins/ps-namer-v2.d.ts +1 -1
  213. package/dist/plugins/ps-namer-v2.d.ts.map +1 -1
  214. package/dist/plugins/ps-namer-v2.js +31 -31
  215. package/dist/plugins/ps-namer-v2.js.map +1 -1
  216. package/dist/plugins/sdk-create-inline-properties.d.ts +1 -1
  217. package/dist/plugins/sdk-create-inline-properties.d.ts.map +1 -1
  218. package/dist/plugins/sdk-create-inline-properties.js +37 -37
  219. package/dist/plugins/sdk-create-inline-properties.js.map +1 -1
  220. package/dist/plugins/sdk-cs-namer.d.ts +1 -1
  221. package/dist/plugins/sdk-cs-namer.d.ts.map +1 -1
  222. package/dist/plugins/sdk-cs-namer.js +21 -21
  223. package/dist/plugins/sdk-cs-namer.js.map +1 -1
  224. package/dist/plugins/sdk-cs-simplifier.d.ts +1 -1
  225. package/dist/plugins/sdk-cs-simplifier.d.ts.map +1 -1
  226. package/dist/plugins/sdk-cs-simplifier.js +3 -3
  227. package/dist/plugins/sdk-cs-simplifier.js.map +1 -1
  228. package/dist/plugins/sdk-generate.d.ts +1 -1
  229. package/dist/plugins/sdk-generate.d.ts.map +1 -1
  230. package/dist/plugins/sdk-generate.js +14 -14
  231. package/dist/plugins/sdk-generate.js.map +1 -1
  232. package/dist/plugins/sdk-tweak-model.d.ts +1 -1
  233. package/dist/plugins/sdk-tweak-model.d.ts.map +1 -1
  234. package/dist/plugins/sdk-tweak-model.js +23 -23
  235. package/dist/plugins/sdk-tweak-model.js.map +1 -1
  236. package/dist/sdk/project.d.ts +2 -2
  237. package/dist/sdk/project.d.ts.map +1 -1
  238. package/dist/sdk/project.js +8 -8
  239. package/dist/sdk/project.js.map +1 -1
  240. package/dist/sdk/state.d.ts +2 -2
  241. package/dist/sdk/state.d.ts.map +1 -1
  242. package/dist/sdk/utility.d.ts +1 -1
  243. package/dist/sdk/utility.d.ts.map +1 -1
  244. package/dist/sdk/utility.js +17 -16
  245. package/dist/sdk/utility.js.map +1 -1
  246. package/dist/utils/PwshModel.d.ts +1 -1
  247. package/dist/utils/PwshModel.d.ts.map +1 -1
  248. package/dist/utils/PwshModel.js +1 -1
  249. package/dist/utils/PwshModel.js.map +1 -1
  250. package/dist/utils/SdkModel.d.ts +1 -1
  251. package/dist/utils/SdkModel.d.ts.map +1 -1
  252. package/dist/utils/SdkModel.js +1 -1
  253. package/dist/utils/SdkModel.js.map +1 -1
  254. package/dist/utils/command-operation.d.ts +9 -3
  255. package/dist/utils/command-operation.d.ts.map +1 -1
  256. package/dist/utils/command-operation.js +24 -4
  257. package/dist/utils/command-operation.js.map +1 -1
  258. package/dist/utils/components.d.ts +1 -1
  259. package/dist/utils/components.d.ts.map +1 -1
  260. package/dist/utils/components.js +2 -2
  261. package/dist/utils/components.js.map +1 -1
  262. package/dist/utils/http-operation.d.ts +2 -0
  263. package/dist/utils/http-operation.d.ts.map +1 -1
  264. package/dist/utils/http-operation.js +16 -12
  265. package/dist/utils/http-operation.js.map +1 -1
  266. package/dist/utils/model-state.d.ts +1 -1
  267. package/dist/utils/model-state.d.ts.map +1 -1
  268. package/dist/utils/model-state.js +20 -20
  269. package/dist/utils/model-state.js.map +1 -1
  270. package/dist/utils/programatic-operation.d.ts +1 -1
  271. package/dist/utils/programatic-operation.d.ts.map +1 -1
  272. package/dist/utils/programatic-operation.js +1 -1
  273. package/dist/utils/programatic-operation.js.map +1 -1
  274. package/dist/utils/resolve-conflicts.js +8 -8
  275. package/dist/utils/resolve-conflicts.js.map +1 -1
  276. package/dist/utils/resourceName.d.ts +3 -0
  277. package/dist/utils/resourceName.d.ts.map +1 -0
  278. package/dist/utils/resourceName.js +29 -0
  279. package/dist/utils/resourceName.js.map +1 -0
  280. package/dist/utils/schema.d.ts +1 -1
  281. package/dist/utils/schema.d.ts.map +1 -1
  282. package/dist/utils/schema.js +11 -11
  283. package/dist/utils/schema.js.map +1 -1
  284. package/dist/utils/security-scheme.d.ts +2 -2
  285. package/dist/utils/security-scheme.d.ts.map +1 -1
  286. package/dist/utils/security-scheme.js +2 -2
  287. package/dist/utils/security-scheme.js.map +1 -1
  288. package/dist/utils/sort-parameters.d.ts +3 -0
  289. package/dist/utils/sort-parameters.d.ts.map +1 -0
  290. package/dist/utils/sort-parameters.js +33 -0
  291. package/dist/utils/sort-parameters.js.map +1 -0
  292. package/package.json +7 -7
  293. package/resources/assets/build-module.ps1 +9 -4
  294. package/resources/assets/check-dependencies.ps1 +3 -3
  295. package/resources/assets/create-model-cmdlets.ps1 +33 -5
  296. package/resources/assets/export-surface.ps1 +3 -3
  297. package/resources/assets/generate-help.ps1 +5 -5
  298. package/resources/assets/generate-portal-ux.ps1 +3 -3
  299. package/resources/assets/run-module.ps1 +4 -4
  300. package/resources/assets/test-module.ps1 +5 -5
  301. package/resources/assets/tools/Resources/custom/New-AzDeployment.ps1 +2 -2
  302. package/resources/psruntime/Attributes/PSArgumentCompleterAttribute.cs +52 -0
  303. package/resources/psruntime/BuildTime/Cmdlets/ExportHelpMarkdown.cs +4 -1
  304. package/resources/psruntime/BuildTime/Cmdlets/ExportProxyCmdlet.cs +4 -1
  305. package/resources/psruntime/BuildTime/Cmdlets/ExportPsd1.cs +6 -4
  306. package/resources/psruntime/BuildTime/MarkdownRenderer.cs +16 -8
  307. package/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs +20 -3
  308. package/resources/psruntime/BuildTime/Models/PsProxyTypes.cs +28 -2
  309. package/resources/psruntime/BuildTime/PsAttributes.cs +5 -0
  310. package/resources/psruntime/BuildTime/PsHelpers.cs +4 -3
  311. package/resources/psruntime/MessageAttribute.cs +23 -52
  312. package/resources/psruntime/MessageAttributeHelper.cs +5 -1
  313. package/resources/psruntime/Properties/Resources.Designer.cs +15 -2
  314. package/resources/psruntime/Properties/Resources.resx +4 -1
  315. package/resources/runtime/csharp/pipeline/ISendAsync.cs +113 -0
  316. package/resources/runtime/csharp/pipeline/PipelineMocking.cs +1 -1
@@ -101,12 +101,23 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
101
101
  if (String.IsNullOrEmpty(defaultParameterSet))
102
102
  {
103
103
  var variantParamCountGroups = Variants
104
+ .Where(v => !v.IsNotSuggestDefaultParameterSet)
104
105
  .Select(v => (
105
106
  variant: v.VariantName,
106
107
  paramCount: v.CmdletOnlyParameters.Count(p => p.IsMandatory),
107
108
  isSimple: v.CmdletOnlyParameters.Where(p => p.IsMandatory).All(p => p.ParameterType.IsPsSimple())))
108
109
  .GroupBy(vpc => vpc.isSimple)
109
110
  .ToArray();
111
+ if (variantParamCountGroups.Length == 0)
112
+ {
113
+ variantParamCountGroups = Variants
114
+ .Select(v => (
115
+ variant: v.VariantName,
116
+ paramCount: v.CmdletOnlyParameters.Count(p => p.IsMandatory),
117
+ isSimple: v.CmdletOnlyParameters.Where(p => p.IsMandatory).All(p => p.ParameterType.IsPsSimple())))
118
+ .GroupBy(vpc => vpc.isSimple)
119
+ .ToArray();
120
+ }
110
121
  var variantParameterCounts = (variantParamCountGroups.Any(g => g.Key) ? variantParamCountGroups.Where(g => g.Key) : variantParamCountGroups).SelectMany(g => g).ToArray();
111
122
  var smallestParameterCount = variantParameterCounts.Min(vpc => vpc.paramCount);
112
123
  defaultParameterSet = variantParameterCounts.First(vpc => vpc.paramCount == smallestParameterCount).variant;
@@ -135,6 +146,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
135
146
  public Parameter[] CmdletOnlyParameters { get; }
136
147
  public bool IsInternal { get; }
137
148
  public bool IsDoNotExport { get; }
149
+ public bool IsNotSuggestDefaultParameterSet { get; }
138
150
  public string[] Profiles { get; }
139
151
 
140
152
  public Variant(string cmdletName, string variantName, CommandInfo info, CommandMetadata metadata, bool hasParameterSets = false, PsHelpInfo helpInfo = null)
@@ -155,6 +167,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
155
167
  Parameters = this.ToParameters().OrderBy(p => p.OrderCategory).ThenByDescending(p => p.IsMandatory).ToArray();
156
168
  IsInternal = Attributes.OfType<InternalExportAttribute>().Any();
157
169
  IsDoNotExport = Attributes.OfType<DoNotExportAttribute>().Any();
170
+ IsNotSuggestDefaultParameterSet = Attributes.OfType<NotSuggestDefaultParameterSetAttribute>().Any();
158
171
  CmdletOnlyParameters = Parameters.Where(p => !p.Categories.Any(c => c == ParameterCategory.Azure || c == ParameterCategory.Runtime)).ToArray();
159
172
  Profiles = Attributes.OfType<ProfileAttribute>().SelectMany(pa => pa.Profiles).ToArray();
160
173
  }
@@ -210,6 +223,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
210
223
  HasValidateNotNull = Parameters.SelectMany(p => p.Attributes.OfType<ValidateNotNullAttribute>()).Any();
211
224
  HasAllowEmptyArray = Parameters.SelectMany(p => p.Attributes.OfType<AllowEmptyCollectionAttribute>()).Any();
212
225
  CompleterInfo = Parameters.Select(p => p.CompleterInfoAttribute).FirstOrDefault()?.ToCompleterInfo()
226
+ ?? Parameters.Select(p => p.PSArgumentCompleterAttribute).FirstOrDefault()?.ToPSArgumentCompleterInfo()
213
227
  ?? Parameters.Select(p => p.ArgumentCompleterAttribute).FirstOrDefault()?.ToCompleterInfo();
214
228
  DefaultInfo = Parameters.Select(p => p.DefaultInfoAttribute).FirstOrDefault()?.ToDefaultInfo(this)
215
229
  ?? Parameters.Select(p => p.DefaultValueAttribute).FirstOrDefault(dv => dv != null)?.ToDefaultInfo(this);
@@ -254,6 +268,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
254
268
  public bool SupportsWildcards { get; }
255
269
  public CompleterInfoAttribute CompleterInfoAttribute { get; }
256
270
  public ArgumentCompleterAttribute ArgumentCompleterAttribute { get; }
271
+ public PSArgumentCompleterAttribute PSArgumentCompleterAttribute { get; }
257
272
 
258
273
  public bool ValueFromPipeline { get; }
259
274
  public bool ValueFromPipelineByPropertyName { get; }
@@ -286,7 +301,8 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
286
301
  }
287
302
  SupportsWildcards = Attributes.OfType<SupportsWildcardsAttribute>().Any();
288
303
  CompleterInfoAttribute = Attributes.OfType<CompleterInfoAttribute>().FirstOrDefault();
289
- ArgumentCompleterAttribute = Attributes.OfType<ArgumentCompleterAttribute>().FirstOrDefault();
304
+ PSArgumentCompleterAttribute = Attributes.OfType<PSArgumentCompleterAttribute>().FirstOrDefault();
305
+ ArgumentCompleterAttribute = Attributes.OfType<ArgumentCompleterAttribute>().FirstOrDefault(attr => !attr.GetType().Equals(typeof(PSArgumentCompleterAttribute)));
290
306
 
291
307
  ValueFromPipeline = ParameterAttribute.ValueFromPipeline;
292
308
  ValueFromPipelineByPropertyName = ParameterAttribute.ValueFromPipelineByPropertyName;
@@ -424,6 +440,16 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
424
440
  }
425
441
  }
426
442
 
443
+ internal class PSArgumentCompleterInfo: CompleterInfo
444
+ {
445
+ public string[] ResourceTypes { get; }
446
+
447
+ public PSArgumentCompleterInfo(PSArgumentCompleterAttribute completerAttribute) : base(completerAttribute)
448
+ {
449
+ ResourceTypes = completerAttribute.ResourceTypes;
450
+ }
451
+ }
452
+
427
453
  internal class DefaultInfo
428
454
  {
429
455
  public string Name { get; }
@@ -513,7 +539,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
513
539
 
514
540
  public static CompleterInfo ToCompleterInfo(this CompleterInfoAttribute infoAttribute) => new CompleterInfo(infoAttribute);
515
541
  public static CompleterInfo ToCompleterInfo(this ArgumentCompleterAttribute completerAttribute) => new CompleterInfo(completerAttribute);
516
-
542
+ public static PSArgumentCompleterInfo ToPSArgumentCompleterInfo(this PSArgumentCompleterAttribute completerAttribute) => new PSArgumentCompleterInfo(completerAttribute);
517
543
  public static DefaultInfo ToDefaultInfo(this DefaultInfoAttribute infoAttribute, ParameterGroup parameterGroup) => new DefaultInfo(infoAttribute, parameterGroup);
518
544
  public static DefaultInfo ToDefaultInfo(this PSDefaultValueAttribute defaultValueAttribute, ParameterGroup parameterGroup) => new DefaultInfo(defaultValueAttribute, parameterGroup);
519
545
  }
@@ -55,6 +55,11 @@ namespace Microsoft.Rest
55
55
  public string ApiVersion { get; set; }
56
56
  }
57
57
 
58
+ [AttributeUsage(AttributeTargets.Class)]
59
+ public class NotSuggestDefaultParameterSetAttribute : Attribute
60
+ {
61
+ }
62
+
58
63
  [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
59
64
  public class CategoryAttribute : Attribute
60
65
  {
@@ -39,9 +39,10 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
39
39
  public static IEnumerable<FunctionInfo> GetScriptCmdlets(PSCmdlet cmdlet, string scriptFolder)
40
40
  {
41
41
  // https://stackoverflow.com/a/40969712/294804
42
+ var wrappedFolder = scriptFolder.Contains("'") ? $@"""{scriptFolder}""" : $@"'{scriptFolder}'";
42
43
  var getCmdletsCommand = $@"
43
44
  $currentFunctions = Get-ChildItem function:
44
- Get-ChildItem -Path '{scriptFolder}' -Recurse -Include '*.ps1' -File | ForEach-Object {{ . $_.FullName }}
45
+ Get-ChildItem -Path {wrappedFolder} -Recurse -Include '*.ps1' -File | ForEach-Object {{ . $_.FullName }}
45
46
  Get-ChildItem function: | Where-Object {{ ($currentFunctions -notcontains $_) -and $_.CmdletBinding }}
46
47
  ";
47
48
  return cmdlet?.RunScript<FunctionInfo>(getCmdletsCommand) ?? RunScript<FunctionInfo>(getCmdletsCommand);
@@ -66,7 +67,7 @@ Get-ChildItem function: | Where-Object {{ ($currentFunctions -notcontains $_) -a
66
67
 
67
68
  public static IEnumerable<CmdletAndHelpInfo> GetModuleCmdletsAndHelpInfo(PSCmdlet cmdlet, params string[] modulePaths)
68
69
  {
69
- var getCmdletAndHelp = String.Join(" + ", modulePaths.Select(mp =>
70
+ var getCmdletAndHelp = String.Join(" + ", modulePaths.Select(mp =>
70
71
  $@"(Get-Command -Module (Import-Module '{mp}' -PassThru) | Where-Object {{ $_.CommandType -ne 'Alias' }} | ForEach-Object {{ @{{ CommandInfo = $_; HelpInfo = ( invoke-command {{ try {{ Get-Help -Name $_.Name -Full }} catch{{ '' }} }} ) }} }})"
71
72
  ));
72
73
  return (cmdlet?.RunScript<Hashtable>(getCmdletAndHelp) ?? RunScript<Hashtable>(getCmdletAndHelp))
@@ -87,7 +88,7 @@ Get-ChildItem function: | Where-Object {{ ($currentFunctions -notcontains $_) -a
87
88
  if (File.Exists(psd1Path))
88
89
  {
89
90
  var currentGuid = File.ReadAllLines(psd1Path)
90
- .FirstOrDefault(l => l.StartsWith(GuidStart))?.Split(new[] { " = " }, StringSplitOptions.RemoveEmptyEntries)
91
+ .FirstOrDefault(l => l.TrimStart().StartsWith(GuidStart.TrimStart()))?.Split(new[] { " = " }, StringSplitOptions.RemoveEmptyEntries)
91
92
  .LastOrDefault()?.Replace("'", String.Empty);
92
93
  guid = currentGuid != null ? Guid.Parse(currentGuid) : guid;
93
94
  }
@@ -21,7 +21,7 @@ namespace Microsoft.Message.ClientRuntime
21
21
 
22
22
  //The version the change is effective from, non mandatory
23
23
  public string DeprecateByVersion { get; }
24
- public bool DeprecateByVersionSet { get; } = false;
24
+ public string DeprecateByAzVersion { get; }
25
25
 
26
26
  //The date on which the change comes in effect
27
27
  public DateTime ChangeInEfectByDate { get; }
@@ -32,23 +32,18 @@ namespace Microsoft.Message.ClientRuntime
32
32
  //New way fo calling the cmdlet
33
33
  public string NewWay { get; set; }
34
34
 
35
- public GenericBreakingChangeAttribute(string message)
36
- {
37
- _message = message;
38
- }
39
-
40
- public GenericBreakingChangeAttribute(string message, string deprecateByVersion)
35
+ public GenericBreakingChangeAttribute(string message, string deprecateByAzVersion, string deprecateByVersion)
41
36
  {
42
37
  _message = message;
38
+ this.DeprecateByAzVersion = deprecateByAzVersion;
43
39
  this.DeprecateByVersion = deprecateByVersion;
44
- this.DeprecateByVersionSet = true;
45
40
  }
46
41
 
47
- public GenericBreakingChangeAttribute(string message, string deprecateByVersion, string changeInEfectByDate)
42
+ public GenericBreakingChangeAttribute(string message, string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate)
48
43
  {
49
44
  _message = message;
50
45
  this.DeprecateByVersion = deprecateByVersion;
51
- this.DeprecateByVersionSet = true;
46
+ this.DeprecateByAzVersion = deprecateByAzVersion;
52
47
 
53
48
  if (DateTime.TryParse(changeInEfectByDate, new CultureInfo("en-US"), DateTimeStyles.None, out DateTime result))
54
49
  {
@@ -86,10 +81,8 @@ namespace Microsoft.Message.ClientRuntime
86
81
  writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByDateMessage, this.ChangeInEfectByDate.ToString("d")));
87
82
  }
88
83
 
89
- if (DeprecateByVersionSet)
90
- {
91
- writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByVersion, this.DeprecateByVersion));
92
- }
84
+ writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByAzVersion, this.DeprecateByAzVersion));
85
+ writeOutput(string.Format(Resources.BreakingChangesAttributesInEffectByVersion, this.DeprecateByVersion));
93
86
 
94
87
  if (OldWay != null && NewWay != null)
95
88
  {
@@ -114,18 +107,13 @@ namespace Microsoft.Message.ClientRuntime
114
107
 
115
108
  public string ReplacementCmdletName { get; set; }
116
109
 
117
- public CmdletBreakingChangeAttribute() :
118
- base(string.Empty)
110
+ public CmdletBreakingChangeAttribute(string deprecateByAzVersion, string deprecateByVersion) :
111
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion)
119
112
  {
120
113
  }
121
114
 
122
- public CmdletBreakingChangeAttribute(string deprecateByVersione) :
123
- base(string.Empty, deprecateByVersione)
124
- {
125
- }
126
-
127
- public CmdletBreakingChangeAttribute(string deprecateByVersion, string changeInEfectByDate) :
128
- base(string.Empty, deprecateByVersion, changeInEfectByDate)
115
+ public CmdletBreakingChangeAttribute(string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate) :
116
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEfectByDate)
129
117
  {
130
118
  }
131
119
 
@@ -146,20 +134,15 @@ namespace Microsoft.Message.ClientRuntime
146
134
  public class ParameterSetBreakingChangeAttribute : GenericBreakingChangeAttribute
147
135
  {
148
136
  public string[] ChangedParameterSet { set; get; }
149
- public ParameterSetBreakingChangeAttribute(string[] changedParameterSet) :
150
- base(string.Empty)
151
- {
152
- ChangedParameterSet = changedParameterSet;
153
- }
154
137
 
155
- public ParameterSetBreakingChangeAttribute(string[] changedParameterSet, string deprecateByVersione) :
156
- base(string.Empty, deprecateByVersione)
138
+ public ParameterSetBreakingChangeAttribute(string[] changedParameterSet, string deprecateByAzVersion, string deprecateByVersion) :
139
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion)
157
140
  {
158
141
  ChangedParameterSet = changedParameterSet;
159
142
  }
160
143
 
161
- public ParameterSetBreakingChangeAttribute(string[] changedParameterSet, string deprecateByVersion, string changeInEfectByDate) :
162
- base(string.Empty, deprecateByVersion, changeInEfectByDate)
144
+ public ParameterSetBreakingChangeAttribute(string[] changedParameterSet, string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate) :
145
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEfectByDate)
163
146
  {
164
147
  ChangedParameterSet = changedParameterSet;
165
148
  }
@@ -219,20 +202,14 @@ namespace Microsoft.Message.ClientRuntime
219
202
 
220
203
  public String NewParameterType { get; set; }
221
204
 
222
- public ParameterBreakingChangeAttribute(string nameOfParameterChanging) :
223
- base(string.Empty)
224
- {
225
- this.NameOfParameterChanging = nameOfParameterChanging;
226
- }
227
-
228
- public ParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByVersion) :
229
- base(string.Empty, deprecateByVersion)
205
+ public ParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByAzVersion, string deprecateByVersion) :
206
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion)
230
207
  {
231
208
  this.NameOfParameterChanging = nameOfParameterChanging;
232
209
  }
233
210
 
234
- public ParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByVersion, string changeInEfectByDate) :
235
- base(string.Empty, deprecateByVersion, changeInEfectByDate)
211
+ public ParameterBreakingChangeAttribute(string nameOfParameterChanging, string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate) :
212
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEfectByDate)
236
213
  {
237
214
  this.NameOfParameterChanging = nameOfParameterChanging;
238
215
  }
@@ -298,20 +275,14 @@ namespace Microsoft.Message.ClientRuntime
298
275
 
299
276
  public string[] NewOutputProperties { get; set; }
300
277
 
301
- public OutputBreakingChangeAttribute(string deprecatedCmdletOutputType) :
302
- base(string.Empty)
303
- {
304
- this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputType;
305
- }
306
-
307
- public OutputBreakingChangeAttribute(string deprecatedCmdletOutputType, string deprecateByVersion) :
308
- base(string.Empty, deprecateByVersion)
278
+ public OutputBreakingChangeAttribute(string deprecatedCmdletOutputType, string deprecateByAzVersion, string deprecateByVersion) :
279
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion)
309
280
  {
310
281
  this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputType;
311
282
  }
312
283
 
313
- public OutputBreakingChangeAttribute(string deprecatedCmdletOutputType, string deprecateByVersion, string changeInEfectByDate) :
314
- base(string.Empty, deprecateByVersion, changeInEfectByDate)
284
+ public OutputBreakingChangeAttribute(string deprecatedCmdletOutputType, string deprecateByAzVersion, string deprecateByVersion, string changeInEfectByDate) :
285
+ base(string.Empty, deprecateByAzVersion, deprecateByVersion, changeInEfectByDate)
315
286
  {
316
287
  this.DeprecatedCmdLetOutputType = deprecatedCmdletOutputType;
317
288
  }
@@ -23,6 +23,7 @@ namespace Microsoft.Message.ClientRuntime
23
23
  using System.Threading.Tasks;
24
24
  public class MessageAttributeHelper
25
25
  {
26
+ private static readonly bool IsAzure = Convert.ToBoolean(@"${$project.azure}");
26
27
  public const string BREAKING_CHANGE_ATTRIBUTE_INFORMATION_LINK = "https://aka.ms/azps-changewarnings";
27
28
  public const string SUPPRESS_ERROR_OR_WARNING_MESSAGE_ENV_VARIABLE_NAME = "SuppressAzurePowerShellBreakingChangeWarnings";
28
29
 
@@ -52,7 +53,10 @@ namespace Microsoft.Message.ClientRuntime
52
53
  //Do not process the attributes at runtime... The env variable to override the warning messages is set
53
54
  return;
54
55
  }
55
-
56
+ if (IsAzure && invocationInfo.BoundParameters.ContainsKey("DefaultProfile"))
57
+ {
58
+ psCmdlet.WriteWarning("The DefaultProfile parameter is not functional. Use the SubscriptionId parameter when available if executing the cmdlet against a different subscription.");
59
+ }
56
60
  List<GenericBreakingChangeAttribute> attributes = new List<GenericBreakingChangeAttribute>(GetAllBreakingChangeAttributesInType(commandInfo, invocationInfo, parameterSet));
57
61
  StringBuilder sb = new StringBuilder();
58
62
  Action<string> appendBreakingChangeInfo = (string s) => sb.Append(s);
@@ -734,7 +734,7 @@ namespace Microsoft.generated.runtime.Properties
734
734
  }
735
735
 
736
736
  /// <summary>
737
- /// Looks up a localized string similar to Note :The change is expected to take effect from the version : &apos;{0}&apos;
737
+ /// Looks up a localized string similar to Note :The change is expected to take effect from version : &apos;{0}&apos;
738
738
  ///
739
739
  ///.
740
740
  /// </summary>
@@ -746,6 +746,19 @@ namespace Microsoft.generated.runtime.Properties
746
746
  }
747
747
  }
748
748
 
749
+ /// <summary>
750
+ /// Looks up a localized string similar to Note :The change is expected to take effect from az version : &apos;{0}&apos;
751
+ ///
752
+ ///.
753
+ /// </summary>
754
+ public static string BreakingChangesAttributesInEffectByAzVersion
755
+ {
756
+ get
757
+ {
758
+ return ResourceManager.GetString("BreakingChangesAttributesInEffectByAzVersion", resourceCulture);
759
+ }
760
+ }
761
+
749
762
  /// <summary>
750
763
  /// Looks up a localized string similar to ```powershell
751
764
  ///# Old
@@ -5630,4 +5643,4 @@ namespace Microsoft.generated.runtime.Properties
5630
5643
  }
5631
5644
  }
5632
5645
  }
5633
- }
5646
+ }
@@ -1705,7 +1705,7 @@ Use the Enable-AzureDataCollection cmdlet to turn the feature On. The cmdlet can
1705
1705
  </data>
1706
1706
  <data name="BreakingChangesAttributesInEffectByVersion" xml:space="preserve">
1707
1707
  <value>
1708
- - The change is expected to take effect from the version : '{0}'</value>
1708
+ - The change is expected to take effect from version : '{0}'</value>
1709
1709
  </data>
1710
1710
  <data name="BreakingChangesAttributesUsageChangeMessage" xml:space="preserve">
1711
1711
  <value>```powershell
@@ -1738,4 +1738,7 @@ Note : Go to {0} for steps to suppress this breaking change warning, and other i
1738
1738
  <data name="PreviewCmdletMessage" xml:space="preserve">
1739
1739
  <value>This cmdlet is in preview. The functionality may not be available in the selected subscription.</value>
1740
1740
  </data>
1741
+ <data name="BreakingChangesAttributesInEffectByAzVersion" xml:space="preserve">
1742
+ <value>- The change is expected to take effect from Az version : '{0}'</value>
1743
+ </data>
1741
1744
  </root>
@@ -11,6 +11,8 @@ namespace Microsoft.Rest.ClientRuntime
11
11
  using System.Threading.Tasks;
12
12
  using System.Collections;
13
13
  using System.Linq;
14
+ using System;
15
+
14
16
 
15
17
  /// <summary>
16
18
  /// The interface for sending an HTTP request across the wire.
@@ -70,6 +72,7 @@ namespace Microsoft.Rest.ClientRuntime
70
72
 
71
73
  public partial class HttpPipeline : ISendAsync
72
74
  {
75
+ private const int DefaultMaxRetry = 3;
73
76
  private ISendAsync pipeline;
74
77
  private ISendAsyncTerminalFactory terminal;
75
78
  private List<ISendAsyncFactory> steps = new List<ISendAsyncFactory>();
@@ -92,6 +95,111 @@ namespace Microsoft.Rest.ClientRuntime
92
95
  /// </summary>
93
96
  public HttpPipeline Clone() => new HttpPipeline(terminal) { steps = this.steps.ToList(), pipeline = this.pipeline };
94
97
 
98
+ private bool shouldRetry429(HttpResponseMessage response)
99
+ {
100
+ if (response.StatusCode == (System.Net.HttpStatusCode)429)
101
+ {
102
+ var retryAfter = response.Headers.RetryAfter;
103
+ if (retryAfter != null && retryAfter.Delta.HasValue)
104
+ {
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }
110
+ /// <summary>
111
+ /// The step to handle 429 response with retry-after header.
112
+ /// </summary>
113
+ public async Task<HttpResponseMessage> Retry429(HttpRequestMessage request, IEventListener callback, ISendAsync next)
114
+ {
115
+ int retryCount = int.MaxValue;
116
+
117
+ try
118
+ {
119
+ try
120
+ {
121
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("PS_HTTP_MAX_RETRIES_FOR_429"));
122
+ }
123
+ finally
124
+ {
125
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("AZURE_PS_HTTP_MAX_RETRIES_FOR_429"));
126
+ }
127
+ }
128
+ catch (System.Exception)
129
+ {
130
+ //no action
131
+ }
132
+ var cloneRequest = await request.CloneWithContent();
133
+ var response = await next.SendAsync(request, callback);
134
+ int count = 0;
135
+ while (shouldRetry429(response) && count++ < retryCount)
136
+ {
137
+ request = await cloneRequest.CloneWithContent();
138
+ var retryAfter = response.Headers.RetryAfter;
139
+ await Task.Delay(retryAfter.Delta.Value, callback.Token);
140
+ await callback.Signal("Debug", $"Start to retry {count} time(s) on status code 429 after waiting {retryAfter.Delta.Value.TotalSeconds} seconds.");
141
+ response = await next.SendAsync(request, callback);
142
+ }
143
+ return response;
144
+ }
145
+
146
+ private bool shouldRetryError(HttpResponseMessage response)
147
+ {
148
+ if (response.StatusCode >= System.Net.HttpStatusCode.InternalServerError)
149
+ {
150
+ if (response.StatusCode != System.Net.HttpStatusCode.NotImplemented &&
151
+ response.StatusCode != System.Net.HttpStatusCode.HttpVersionNotSupported)
152
+ {
153
+ return true;
154
+ }
155
+ }
156
+ else if (response.StatusCode == System.Net.HttpStatusCode.RequestTimeout)
157
+ {
158
+ return true;
159
+ }
160
+ else if (response.StatusCode == (System.Net.HttpStatusCode)429 && response.Headers.RetryAfter == null)
161
+ {
162
+ return true;
163
+ }
164
+ return false;
165
+ }
166
+
167
+ /// <summary>
168
+ /// Returns true if status code in HttpRequestExceptionWithStatus exception is greater
169
+ /// than or equal to 500 and not NotImplemented (501) or HttpVersionNotSupported (505).
170
+ /// Or it's 429 (TOO MANY REQUESTS) without Retry-After header.
171
+ /// </summary>
172
+ public async Task<HttpResponseMessage> RetryError(HttpRequestMessage request, IEventListener callback, ISendAsync next)
173
+ {
174
+ int retryCount = DefaultMaxRetry;
175
+
176
+ try
177
+ {
178
+ try
179
+ {
180
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("PS_HTTP_MAX_RETRIES"));
181
+ }
182
+ finally
183
+ {
184
+ retryCount = int.Parse(System.Environment.GetEnvironmentVariable("AZURE_PS_HTTP_MAX_RETRIES"));
185
+ }
186
+ }
187
+ catch (System.Exception)
188
+ {
189
+ //no action
190
+ }
191
+ var cloneRequest = await request.CloneWithContent();
192
+ var response = await next.SendAsync(request, callback);
193
+ int count = 0;
194
+ while (shouldRetryError(response) && count++ < retryCount)
195
+ {
196
+ await callback.Signal("Debug", $"Start to retry {count} time(s) on status code {response.StatusCode}");
197
+ request = await cloneRequest.CloneWithContent();
198
+ response = await next.SendAsync(request, callback);
199
+ }
200
+ return response;
201
+ }
202
+
95
203
  public ISendAsyncTerminalFactory TerminalFactory
96
204
  {
97
205
  get => terminal;
@@ -117,6 +225,11 @@ namespace Microsoft.Rest.ClientRuntime
117
225
 
118
226
  // create the pipeline from scratch.
119
227
  var next = terminal.Create();
228
+ if (Convert.ToBoolean(@"${$project.enableApiRetry}"))
229
+ {
230
+ next = (new SendAsyncFactory(Retry429)).Create(next) ?? next;
231
+ next = (new SendAsyncFactory(RetryError)).Create(next) ?? next;
232
+ }
120
233
  foreach (var factory in steps)
121
234
  {
122
235
  // skip factories that return null.
@@ -259,4 +259,4 @@ namespace Microsoft.Rest.ClientRuntime
259
259
  }
260
260
  }
261
261
  }
262
- }
262
+ }