forked from microsoftgraph/msgraph-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsersRequestBuilder.cs
More file actions
444 lines (444 loc) · 25.1 KB
/
Copy pathUsersRequestBuilder.cs
File metadata and controls
444 lines (444 loc) · 25.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
// <auto-generated/>
using ApiSdk.Models.ODataErrors;
using ApiSdk.Models;
using ApiSdk.Users.Count;
using ApiSdk.Users.Delta;
using ApiSdk.Users.GetAvailableExtensionProperties;
using ApiSdk.Users.GetByIds;
using ApiSdk.Users.Item;
using ApiSdk.Users.ValidateProperties;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Cli.Commons.Extensions;
using Microsoft.Kiota.Cli.Commons.IO;
using Microsoft.Kiota.Cli.Commons;
using System.Collections.Generic;
using System.CommandLine;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using System;
namespace ApiSdk.Users {
/// <summary>
/// Provides operations to manage the collection of user entities.
/// </summary>
public class UsersRequestBuilder : BaseCliRequestBuilder {
/// <summary>
/// Provides operations to manage the collection of user entities.
/// </summary>
/// <returns>A <cref="Tuple<List<Command>, List<Command>>"></returns>
public Tuple<List<Command>, List<Command>> BuildCommand() {
var executables = new List<Command>();
var commands = new List<Command>();
var builder = new UserItemRequestBuilder(PathParameters);
commands.Add(builder.BuildActivitiesNavCommand());
commands.Add(builder.BuildAgreementAcceptancesNavCommand());
commands.Add(builder.BuildAppRoleAssignmentsNavCommand());
commands.Add(builder.BuildAssignLicenseNavCommand());
commands.Add(builder.BuildAuthenticationNavCommand());
commands.Add(builder.BuildCalendarGroupsNavCommand());
commands.Add(builder.BuildCalendarNavCommand());
commands.Add(builder.BuildCalendarsNavCommand());
commands.Add(builder.BuildCalendarViewNavCommand());
commands.Add(builder.BuildChangePasswordNavCommand());
commands.Add(builder.BuildChatsNavCommand());
commands.Add(builder.BuildCheckMemberGroupsNavCommand());
commands.Add(builder.BuildCheckMemberObjectsNavCommand());
commands.Add(builder.BuildContactFoldersNavCommand());
commands.Add(builder.BuildContactsNavCommand());
commands.Add(builder.BuildCreatedObjectsNavCommand());
executables.Add(builder.BuildDeleteCommand());
commands.Add(builder.BuildDeviceManagementTroubleshootingEventsNavCommand());
commands.Add(builder.BuildDirectReportsNavCommand());
commands.Add(builder.BuildDriveNavCommand());
commands.Add(builder.BuildDrivesNavCommand());
commands.Add(builder.BuildEmployeeExperienceNavCommand());
commands.Add(builder.BuildEventsNavCommand());
commands.Add(builder.BuildExportDeviceAndAppManagementDataNavCommand());
commands.Add(builder.BuildExportDeviceAndAppManagementDataWithSkipWithTopRbCommand());
commands.Add(builder.BuildExportPersonalDataNavCommand());
commands.Add(builder.BuildExtensionsNavCommand());
commands.Add(builder.BuildFindMeetingTimesNavCommand());
commands.Add(builder.BuildFollowedSitesNavCommand());
executables.Add(builder.BuildGetCommand());
commands.Add(builder.BuildGetMailTipsNavCommand());
commands.Add(builder.BuildGetManagedAppDiagnosticStatusesNavCommand());
commands.Add(builder.BuildGetManagedAppPoliciesNavCommand());
commands.Add(builder.BuildGetManagedDevicesWithAppFailuresNavCommand());
commands.Add(builder.BuildGetMemberGroupsNavCommand());
commands.Add(builder.BuildGetMemberObjectsNavCommand());
commands.Add(builder.BuildInferenceClassificationNavCommand());
commands.Add(builder.BuildInsightsNavCommand());
commands.Add(builder.BuildJoinedTeamsNavCommand());
commands.Add(builder.BuildLicenseDetailsNavCommand());
commands.Add(builder.BuildMailboxSettingsNavCommand());
commands.Add(builder.BuildMailFoldersNavCommand());
commands.Add(builder.BuildManagedAppRegistrationsNavCommand());
commands.Add(builder.BuildManagedDevicesNavCommand());
commands.Add(builder.BuildManagerNavCommand());
commands.Add(builder.BuildMemberOfNavCommand());
commands.Add(builder.BuildMessagesNavCommand());
commands.Add(builder.BuildOauth2PermissionGrantsNavCommand());
commands.Add(builder.BuildOnenoteNavCommand());
commands.Add(builder.BuildOnlineMeetingsNavCommand());
commands.Add(builder.BuildOutlookNavCommand());
commands.Add(builder.BuildOwnedDevicesNavCommand());
commands.Add(builder.BuildOwnedObjectsNavCommand());
executables.Add(builder.BuildPatchCommand());
commands.Add(builder.BuildPeopleNavCommand());
commands.Add(builder.BuildPermissionGrantsNavCommand());
commands.Add(builder.BuildPhotoNavCommand());
commands.Add(builder.BuildPhotosNavCommand());
commands.Add(builder.BuildPlannerNavCommand());
commands.Add(builder.BuildPresenceNavCommand());
commands.Add(builder.BuildRegisteredDevicesNavCommand());
commands.Add(builder.BuildReminderViewWithStartDateTimeWithEndDateTimeRbCommand());
commands.Add(builder.BuildRemoveAllDevicesFromManagementNavCommand());
commands.Add(builder.BuildReprocessLicenseAssignmentNavCommand());
commands.Add(builder.BuildRestoreNavCommand());
commands.Add(builder.BuildRetryServiceProvisioningNavCommand());
commands.Add(builder.BuildRevokeSignInSessionsNavCommand());
commands.Add(builder.BuildScopedRoleMemberOfNavCommand());
commands.Add(builder.BuildSendMailNavCommand());
commands.Add(builder.BuildServiceProvisioningErrorsNavCommand());
commands.Add(builder.BuildSettingsNavCommand());
commands.Add(builder.BuildTeamworkNavCommand());
commands.Add(builder.BuildTodoNavCommand());
commands.Add(builder.BuildTransitiveMemberOfNavCommand());
commands.Add(builder.BuildTranslateExchangeIdsNavCommand());
commands.Add(builder.BuildWipeManagedAppRegistrationsByDeviceTagNavCommand());
return new(executables, commands);
}
/// <summary>
/// Provides operations to count the resources in the collection.
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildCountNavCommand() {
var command = new Command("count");
command.Description = "Provides operations to count the resources in the collection.";
var builder = new CountRequestBuilder(PathParameters);
var execCommands = new List<Command>();
execCommands.Add(builder.BuildGetCommand());
foreach (var cmd in execCommands)
{
command.AddCommand(cmd);
}
return command;
}
/// <summary>
/// Create a new user.The request body contains the user to create. At a minimum, you must specify the required properties for the user. You can optionally specify any other writable properties.
/// Find more info here <see href="https://learn.microsoft.com/graph/api/user-post-users?view=graph-rest-1.0" />
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildCreateCommand() {
var command = new Command("create");
command.Description = "Create a new user.The request body contains the user to create. At a minimum, you must specify the required properties for the user. You can optionally specify any other writable properties.\n\nFind more info here:\n https://learn.microsoft.com/graph/api/user-post-users?view=graph-rest-1.0";
var bodyOption = new Option<string>("--body", description: "The request body") {
};
bodyOption.IsRequired = true;
command.AddOption(bodyOption);
var outputOption = new Option<FormatterType>("--output", () => FormatterType.JSON);
command.AddOption(outputOption);
var queryOption = new Option<string>("--query");
command.AddOption(queryOption);
command.SetHandler(async (invocationContext) => {
var body = invocationContext.ParseResult.GetValueForOption(bodyOption) ?? string.Empty;
var output = invocationContext.ParseResult.GetValueForOption(outputOption);
var query = invocationContext.ParseResult.GetValueForOption(queryOption);
IOutputFilter outputFilter = invocationContext.BindingContext.GetService(typeof(IOutputFilter)) as IOutputFilter ?? throw new ArgumentNullException("outputFilter");
IOutputFormatterFactory outputFormatterFactory = invocationContext.BindingContext.GetService(typeof(IOutputFormatterFactory)) as IOutputFormatterFactory ?? throw new ArgumentNullException("outputFormatterFactory");
var cancellationToken = invocationContext.GetCancellationToken();
var reqAdapter = invocationContext.GetRequestAdapter();
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(body));
var parseNode = ParseNodeFactoryRegistry.DefaultInstance.GetRootParseNode("application/json", stream);
var model = parseNode.GetObjectValue<ApiSdk.Models.User>(ApiSdk.Models.User.CreateFromDiscriminatorValue);
if (model is null) {
Console.Error.WriteLine("No model data to send.");
return;
}
var requestInfo = ToPostRequestInformation(model, q => {
});
requestInfo.SetContentFromParsable(reqAdapter, "application/json", model);
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
{"4XX", ODataError.CreateFromDiscriminatorValue},
{"5XX", ODataError.CreateFromDiscriminatorValue},
};
var response = await reqAdapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping: errorMapping, cancellationToken: cancellationToken) ?? Stream.Null;
response = (response != Stream.Null) ? await outputFilter.FilterOutputAsync(response, query, cancellationToken) : response;
var formatter = outputFormatterFactory.GetFormatter(output);
await formatter.WriteOutputAsync(response, cancellationToken);
});
return command;
}
/// <summary>
/// Provides operations to call the delta method.
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildDeltaNavCommand() {
var command = new Command("delta");
command.Description = "Provides operations to call the delta method.";
var builder = new DeltaRequestBuilder(PathParameters);
var execCommands = new List<Command>();
execCommands.Add(builder.BuildGetCommand());
foreach (var cmd in execCommands)
{
command.AddCommand(cmd);
}
return command;
}
/// <summary>
/// Provides operations to call the getAvailableExtensionProperties method.
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildGetAvailableExtensionPropertiesNavCommand() {
var command = new Command("get-available-extension-properties");
command.Description = "Provides operations to call the getAvailableExtensionProperties method.";
var builder = new GetAvailableExtensionPropertiesRequestBuilder(PathParameters);
var execCommands = new List<Command>();
execCommands.Add(builder.BuildPostCommand());
foreach (var cmd in execCommands)
{
command.AddCommand(cmd);
}
return command;
}
/// <summary>
/// Provides operations to call the getByIds method.
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildGetByIdsNavCommand() {
var command = new Command("get-by-ids");
command.Description = "Provides operations to call the getByIds method.";
var builder = new GetByIdsRequestBuilder(PathParameters);
var execCommands = new List<Command>();
execCommands.Add(builder.BuildPostCommand());
foreach (var cmd in execCommands)
{
command.AddCommand(cmd);
}
return command;
}
/// <summary>
/// List properties and relationships of the user objects.
/// Find more info here <see href="https://learn.microsoft.com/graph/api/intune-mam-user-list?view=graph-rest-1.0" />
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildListCommand() {
var command = new Command("list");
command.Description = "List properties and relationships of the user objects.\n\nFind more info here:\n https://learn.microsoft.com/graph/api/intune-mam-user-list?view=graph-rest-1.0";
var consistencyLevelOption = new Option<string[]>("--consistency-level", description: "Indicates the requested consistency level. Documentation URL: https://docs.microsoft.com/graph/aad-advanced-queries") {
Arity = ArgumentArity.ZeroOrMore
};
consistencyLevelOption.IsRequired = false;
command.AddOption(consistencyLevelOption);
var topOption = new Option<int?>("--top", description: "Show only the first n items") {
};
topOption.IsRequired = false;
command.AddOption(topOption);
var searchOption = new Option<string>("--search", description: "Search items by search phrases") {
};
searchOption.IsRequired = false;
command.AddOption(searchOption);
var filterOption = new Option<string>("--filter", description: "Filter items by property values") {
};
filterOption.IsRequired = false;
command.AddOption(filterOption);
var countOption = new Option<bool?>("--count", description: "Include count of items") {
};
countOption.IsRequired = false;
command.AddOption(countOption);
var orderbyOption = new Option<string[]>("--orderby", description: "Order items by property values") {
Arity = ArgumentArity.ZeroOrMore
};
orderbyOption.IsRequired = false;
command.AddOption(orderbyOption);
var selectOption = new Option<string[]>("--select", description: "Select properties to be returned") {
Arity = ArgumentArity.ZeroOrMore
};
selectOption.IsRequired = false;
command.AddOption(selectOption);
var expandOption = new Option<string[]>("--expand", description: "Expand related entities") {
Arity = ArgumentArity.ZeroOrMore
};
expandOption.IsRequired = false;
command.AddOption(expandOption);
var outputOption = new Option<FormatterType>("--output", () => FormatterType.JSON);
command.AddOption(outputOption);
var queryOption = new Option<string>("--query");
command.AddOption(queryOption);
var allOption = new Option<bool>("--all");
command.AddOption(allOption);
command.SetHandler(async (invocationContext) => {
var consistencyLevel = invocationContext.ParseResult.GetValueForOption(consistencyLevelOption);
var top = invocationContext.ParseResult.GetValueForOption(topOption);
var search = invocationContext.ParseResult.GetValueForOption(searchOption);
var filter = invocationContext.ParseResult.GetValueForOption(filterOption);
var count = invocationContext.ParseResult.GetValueForOption(countOption);
var orderby = invocationContext.ParseResult.GetValueForOption(orderbyOption);
var select = invocationContext.ParseResult.GetValueForOption(selectOption);
var expand = invocationContext.ParseResult.GetValueForOption(expandOption);
var output = invocationContext.ParseResult.GetValueForOption(outputOption);
var query = invocationContext.ParseResult.GetValueForOption(queryOption);
var all = invocationContext.ParseResult.GetValueForOption(allOption);
IOutputFilter outputFilter = invocationContext.BindingContext.GetService(typeof(IOutputFilter)) as IOutputFilter ?? throw new ArgumentNullException("outputFilter");
IOutputFormatterFactory outputFormatterFactory = invocationContext.BindingContext.GetService(typeof(IOutputFormatterFactory)) as IOutputFormatterFactory ?? throw new ArgumentNullException("outputFormatterFactory");
IPagingService pagingService = invocationContext.BindingContext.GetService(typeof(IPagingService)) as IPagingService ?? throw new ArgumentNullException("pagingService");
var cancellationToken = invocationContext.GetCancellationToken();
var reqAdapter = invocationContext.GetRequestAdapter();
var requestInfo = ToGetRequestInformation(q => {
q.QueryParameters.Top = top;
if (!string.IsNullOrEmpty(search)) q.QueryParameters.Search = search;
if (!string.IsNullOrEmpty(filter)) q.QueryParameters.Filter = filter;
q.QueryParameters.Count = count;
q.QueryParameters.Orderby = orderby;
q.QueryParameters.Select = select;
q.QueryParameters.Expand = expand;
});
if (consistencyLevel is not null) requestInfo.Headers.Add("ConsistencyLevel", consistencyLevel);
var errorMapping = new Dictionary<string, ParsableFactory<IParsable>> {
{"4XX", ODataError.CreateFromDiscriminatorValue},
{"5XX", ODataError.CreateFromDiscriminatorValue},
};
var pagingData = new PageLinkData(requestInfo, null, itemName: "value", nextLinkName: "@odata.nextLink");
var pageResponse = await pagingService.GetPagedDataAsync((info, token) => reqAdapter.SendNoContentAsync(info, cancellationToken: token), pagingData, all, cancellationToken);
var response = pageResponse?.Response;
IOutputFormatter? formatter = null;
if (pageResponse?.StatusCode >= 200 && pageResponse?.StatusCode < 300) {
formatter = outputFormatterFactory.GetFormatter(output);
response = (response != Stream.Null) ? await outputFilter.FilterOutputAsync(response, query, cancellationToken) : response;
} else {
formatter = outputFormatterFactory.GetFormatter(FormatterType.TEXT);
}
await formatter.WriteOutputAsync(response, cancellationToken);
});
return command;
}
/// <summary>
/// Provides operations to call the validateProperties method.
/// </summary>
/// <returns>A <cref="Command"></returns>
public Command BuildValidatePropertiesNavCommand() {
var command = new Command("validate-properties");
command.Description = "Provides operations to call the validateProperties method.";
var builder = new ValidatePropertiesRequestBuilder(PathParameters);
var execCommands = new List<Command>();
execCommands.Add(builder.BuildPostCommand());
foreach (var cmd in execCommands)
{
command.AddCommand(cmd);
}
return command;
}
/// <summary>
/// Instantiates a new <see cref="UsersRequestBuilder"/> and sets the default values.
/// </summary>
/// <param name="pathParameters">Path parameters for the request</param>
public UsersRequestBuilder(Dictionary<string, object> pathParameters) : base("{+baseurl}/users{?%24count,%24expand,%24filter,%24orderby,%24search,%24select,%24top}", pathParameters) {
}
/// <summary>
/// Instantiates a new <see cref="UsersRequestBuilder"/> and sets the default values.
/// </summary>
/// <param name="rawUrl">The raw URL to use for the request builder.</param>
public UsersRequestBuilder(string rawUrl) : base("{+baseurl}/users{?%24count,%24expand,%24filter,%24orderby,%24search,%24select,%24top}", rawUrl) {
}
/// <summary>
/// List properties and relationships of the user objects.
/// </summary>
/// <returns>A <cref="RequestInformation"></returns>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<UsersRequestBuilderGetQueryParameters>>? requestConfiguration = default) {
#nullable restore
#else
public RequestInformation ToGetRequestInformation(Action<RequestConfiguration<UsersRequestBuilderGetQueryParameters>> requestConfiguration = default) {
#endif
var requestInfo = new RequestInformation(Method.GET, UrlTemplate, PathParameters);
requestInfo.Configure(requestConfiguration);
requestInfo.Headers.TryAdd("Accept", "application/json");
return requestInfo;
}
/// <summary>
/// Create a new user.The request body contains the user to create. At a minimum, you must specify the required properties for the user. You can optionally specify any other writable properties.
/// </summary>
/// <returns>A <cref="RequestInformation"></returns>
/// <param name="body">The request body</param>
/// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
public RequestInformation ToPostRequestInformation(ApiSdk.Models.User body, Action<RequestConfiguration<DefaultQueryParameters>>? requestConfiguration = default) {
#nullable restore
#else
public RequestInformation ToPostRequestInformation(ApiSdk.Models.User body, Action<RequestConfiguration<DefaultQueryParameters>> requestConfiguration = default) {
#endif
_ = body ?? throw new ArgumentNullException(nameof(body));
var requestInfo = new RequestInformation(Method.POST, "{+baseurl}/users", PathParameters);
requestInfo.Configure(requestConfiguration);
requestInfo.Headers.TryAdd("Accept", "application/json");
return requestInfo;
}
/// <summary>
/// List properties and relationships of the user objects.
/// </summary>
public class UsersRequestBuilderGetQueryParameters {
/// <summary>Include count of items</summary>
[QueryParameter("%24count")]
public bool? Count { get; set; }
/// <summary>Expand related entities</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("%24expand")]
public string[]? Expand { get; set; }
#nullable restore
#else
[QueryParameter("%24expand")]
public string[] Expand { get; set; }
#endif
/// <summary>Filter items by property values</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("%24filter")]
public string? Filter { get; set; }
#nullable restore
#else
[QueryParameter("%24filter")]
public string Filter { get; set; }
#endif
/// <summary>Order items by property values</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("%24orderby")]
public string[]? Orderby { get; set; }
#nullable restore
#else
[QueryParameter("%24orderby")]
public string[] Orderby { get; set; }
#endif
/// <summary>Search items by search phrases</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("%24search")]
public string? Search { get; set; }
#nullable restore
#else
[QueryParameter("%24search")]
public string Search { get; set; }
#endif
/// <summary>Select properties to be returned</summary>
#if NETSTANDARD2_1_OR_GREATER || NETCOREAPP3_1_OR_GREATER
#nullable enable
[QueryParameter("%24select")]
public string[]? Select { get; set; }
#nullable restore
#else
[QueryParameter("%24select")]
public string[] Select { get; set; }
#endif
/// <summary>Show only the first n items</summary>
[QueryParameter("%24top")]
public int? Top { get; set; }
}
}
}