@autorest/powershell 4.0.0-dev.8 → 4.0.0-dev.9
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.
- package/.rush/temp/package-deps_build.json +26 -23
- package/dist/cmdlets/class.d.ts +4 -0
- package/dist/cmdlets/class.d.ts.map +1 -1
- package/dist/cmdlets/class.js +152 -73
- package/dist/cmdlets/class.js.map +1 -1
- package/dist/internal/powershell-declarations.d.ts +1 -0
- package/dist/internal/powershell-declarations.d.ts.map +1 -1
- package/dist/internal/powershell-declarations.js +2 -1
- package/dist/internal/powershell-declarations.js.map +1 -1
- package/dist/internal/project.d.ts +0 -2
- package/dist/internal/project.d.ts.map +1 -1
- package/dist/internal/project.js +3 -7
- package/dist/internal/project.js.map +1 -1
- package/dist/llcsharp/model/interface.d.ts.map +1 -1
- package/dist/llcsharp/model/interface.js +14 -0
- package/dist/llcsharp/model/interface.js.map +1 -1
- package/dist/llcsharp/model/namespace.d.ts.map +1 -1
- package/dist/llcsharp/model/namespace.js +3 -11
- package/dist/llcsharp/model/namespace.js.map +1 -1
- package/dist/llcsharp/project.d.ts +2 -1
- package/dist/llcsharp/project.d.ts.map +1 -1
- package/dist/llcsharp/project.js +5 -3
- package/dist/llcsharp/project.js.map +1 -1
- package/dist/llcsharp/schema/schema-resolver.d.ts.map +1 -1
- package/dist/llcsharp/schema/schema-resolver.js +3 -8
- package/dist/llcsharp/schema/schema-resolver.js.map +1 -1
- package/dist/plugins/create-commands-v2.d.ts +1 -0
- package/dist/plugins/create-commands-v2.d.ts.map +1 -1
- package/dist/plugins/create-commands-v2.js +39 -6
- package/dist/plugins/create-commands-v2.js.map +1 -1
- package/dist/plugins/llcsharp-v2.d.ts.map +1 -1
- package/dist/plugins/llcsharp-v2.js +4 -1
- package/dist/plugins/llcsharp-v2.js.map +1 -1
- package/dist/plugins/modifiers-v2.d.ts.map +1 -1
- package/dist/plugins/modifiers-v2.js +21 -2
- package/dist/plugins/modifiers-v2.js.map +1 -1
- package/dist/plugins/plugin-tweak-m4-model.d.ts.map +1 -1
- package/dist/plugins/plugin-tweak-m4-model.js +12 -0
- package/dist/plugins/plugin-tweak-m4-model.js.map +1 -1
- package/dist/utils/resourceName.d.ts +3 -0
- package/dist/utils/resourceName.d.ts.map +1 -0
- package/dist/utils/resourceName.js +29 -0
- package/dist/utils/resourceName.js.map +1 -0
- package/dist/utils/sort-parameters.d.ts +3 -0
- package/dist/utils/sort-parameters.d.ts.map +1 -0
- package/dist/utils/sort-parameters.js +33 -0
- package/dist/utils/sort-parameters.js.map +1 -0
- package/package.json +1 -1
- package/resources/assets/build-module.ps1 +3 -3
- package/resources/assets/check-dependencies.ps1 +3 -3
- package/resources/assets/create-model-cmdlets.ps1 +33 -5
- package/resources/assets/export-surface.ps1 +3 -3
- package/resources/assets/generate-help.ps1 +3 -3
- package/resources/assets/generate-portal-ux.ps1 +3 -3
- package/resources/assets/run-module.ps1 +4 -4
- package/resources/assets/test-module.ps1 +6 -6
- package/resources/psruntime/Attributes/PSArgumentCompleterAttribute.cs +52 -0
- package/resources/psruntime/BuildTime/Models/PsProxyOutputs.cs +18 -1
- package/resources/psruntime/BuildTime/Models/PsProxyTypes.cs +15 -2
- package/resources/runtime/csharp/pipeline/ISendAsync.cs +113 -0
|
@@ -121,6 +121,21 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
121
121
|
: String.Empty;
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
+
internal class PSArgumentCompleterOutput: ArgumentCompleterOutput
|
|
125
|
+
{
|
|
126
|
+
public PSArgumentCompleterInfo PSArgumentCompleterInfo { get; }
|
|
127
|
+
|
|
128
|
+
public PSArgumentCompleterOutput(PSArgumentCompleterInfo completerInfo) : base(completerInfo)
|
|
129
|
+
{
|
|
130
|
+
PSArgumentCompleterInfo = completerInfo;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
public override string ToString() => PSArgumentCompleterInfo != null
|
|
135
|
+
? $"{Indent}[{typeof(PSArgumentCompleterAttribute)}({(PSArgumentCompleterInfo.IsTypeCompleter ? $"[{PSArgumentCompleterInfo.Type.Unwrap().ToPsType()}]" : $"{PSArgumentCompleterInfo.ResourceTypes?.Select(r => $"\"{r}\"")?.JoinIgnoreEmpty(", ")}")})]{Environment.NewLine}"
|
|
136
|
+
: String.Empty;
|
|
137
|
+
}
|
|
138
|
+
|
|
124
139
|
internal class DefaultInfoOutput
|
|
125
140
|
{
|
|
126
141
|
public bool HasDefaultInfo { get; }
|
|
@@ -569,7 +584,9 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
569
584
|
|
|
570
585
|
public static AllowEmptyArrayOutput ToAllowEmptyArray(this bool hasAllowEmptyArray) => new AllowEmptyArrayOutput(hasAllowEmptyArray);
|
|
571
586
|
|
|
572
|
-
public static ArgumentCompleterOutput ToArgumentCompleterOutput(this CompleterInfo completerInfo) => new ArgumentCompleterOutput(completerInfo);
|
|
587
|
+
public static ArgumentCompleterOutput ToArgumentCompleterOutput(this CompleterInfo completerInfo) => (completerInfo is PSArgumentCompleterInfo psArgumentCompleterInfo) ? psArgumentCompleterInfo.ToArgumentCompleterOutput() : new ArgumentCompleterOutput(completerInfo);
|
|
588
|
+
|
|
589
|
+
public static PSArgumentCompleterOutput ToArgumentCompleterOutput(this PSArgumentCompleterInfo completerInfo) => new PSArgumentCompleterOutput(completerInfo);
|
|
573
590
|
|
|
574
591
|
public static DefaultInfoOutput ToDefaultInfoOutput(this ParameterGroup parameterGroup) => new DefaultInfoOutput(parameterGroup);
|
|
575
592
|
|
|
@@ -210,6 +210,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
210
210
|
HasValidateNotNull = Parameters.SelectMany(p => p.Attributes.OfType<ValidateNotNullAttribute>()).Any();
|
|
211
211
|
HasAllowEmptyArray = Parameters.SelectMany(p => p.Attributes.OfType<AllowEmptyCollectionAttribute>()).Any();
|
|
212
212
|
CompleterInfo = Parameters.Select(p => p.CompleterInfoAttribute).FirstOrDefault()?.ToCompleterInfo()
|
|
213
|
+
?? Parameters.Select(p => p.PSArgumentCompleterAttribute).FirstOrDefault()?.ToPSArgumentCompleterInfo()
|
|
213
214
|
?? Parameters.Select(p => p.ArgumentCompleterAttribute).FirstOrDefault()?.ToCompleterInfo();
|
|
214
215
|
DefaultInfo = Parameters.Select(p => p.DefaultInfoAttribute).FirstOrDefault()?.ToDefaultInfo(this)
|
|
215
216
|
?? Parameters.Select(p => p.DefaultValueAttribute).FirstOrDefault(dv => dv != null)?.ToDefaultInfo(this);
|
|
@@ -254,6 +255,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
254
255
|
public bool SupportsWildcards { get; }
|
|
255
256
|
public CompleterInfoAttribute CompleterInfoAttribute { get; }
|
|
256
257
|
public ArgumentCompleterAttribute ArgumentCompleterAttribute { get; }
|
|
258
|
+
public PSArgumentCompleterAttribute PSArgumentCompleterAttribute { get; }
|
|
257
259
|
|
|
258
260
|
public bool ValueFromPipeline { get; }
|
|
259
261
|
public bool ValueFromPipelineByPropertyName { get; }
|
|
@@ -286,7 +288,8 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
286
288
|
}
|
|
287
289
|
SupportsWildcards = Attributes.OfType<SupportsWildcardsAttribute>().Any();
|
|
288
290
|
CompleterInfoAttribute = Attributes.OfType<CompleterInfoAttribute>().FirstOrDefault();
|
|
289
|
-
|
|
291
|
+
PSArgumentCompleterAttribute = Attributes.OfType<PSArgumentCompleterAttribute>().FirstOrDefault();
|
|
292
|
+
ArgumentCompleterAttribute = Attributes.OfType<ArgumentCompleterAttribute>().FirstOrDefault(attr => !attr.GetType().Equals(typeof(PSArgumentCompleterAttribute)));
|
|
290
293
|
|
|
291
294
|
ValueFromPipeline = ParameterAttribute.ValueFromPipeline;
|
|
292
295
|
ValueFromPipelineByPropertyName = ParameterAttribute.ValueFromPipelineByPropertyName;
|
|
@@ -424,6 +427,16 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
424
427
|
}
|
|
425
428
|
}
|
|
426
429
|
|
|
430
|
+
internal class PSArgumentCompleterInfo: CompleterInfo
|
|
431
|
+
{
|
|
432
|
+
public string[] ResourceTypes { get; }
|
|
433
|
+
|
|
434
|
+
public PSArgumentCompleterInfo(PSArgumentCompleterAttribute completerAttribute) : base(completerAttribute)
|
|
435
|
+
{
|
|
436
|
+
ResourceTypes = completerAttribute.ResourceTypes;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
427
440
|
internal class DefaultInfo
|
|
428
441
|
{
|
|
429
442
|
public string Name { get; }
|
|
@@ -513,7 +526,7 @@ namespace Microsoft.Rest.ClientRuntime.PowerShell
|
|
|
513
526
|
|
|
514
527
|
public static CompleterInfo ToCompleterInfo(this CompleterInfoAttribute infoAttribute) => new CompleterInfo(infoAttribute);
|
|
515
528
|
public static CompleterInfo ToCompleterInfo(this ArgumentCompleterAttribute completerAttribute) => new CompleterInfo(completerAttribute);
|
|
516
|
-
|
|
529
|
+
public static PSArgumentCompleterInfo ToPSArgumentCompleterInfo(this PSArgumentCompleterAttribute completerAttribute) => new PSArgumentCompleterInfo(completerAttribute);
|
|
517
530
|
public static DefaultInfo ToDefaultInfo(this DefaultInfoAttribute infoAttribute, ParameterGroup parameterGroup) => new DefaultInfo(infoAttribute, parameterGroup);
|
|
518
531
|
public static DefaultInfo ToDefaultInfo(this PSDefaultValueAttribute defaultValueAttribute, ParameterGroup parameterGroup) => new DefaultInfo(defaultValueAttribute, parameterGroup);
|
|
519
532
|
}
|
|
@@ -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.
|