Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update generated code #22

Merged
merged 15 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/bin/Debug/net6.0/mgc.dll",
"args": ["me", "get"],
"args": ["me", "get", "--output", "TABLE"],
"cwd": "${workspaceFolder}/src",
"envFile": "${workspaceFolder}/src/.env",
"console": "internalConsole",
Expand Down
18 changes: 12 additions & 6 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Microsoft.Graph.Cli.Core.Configuration;
using Microsoft.Graph.Cli.Core.IO;
using Microsoft.Graph.Cli.Core.Utils;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Authentication.Azure;
using Microsoft.Kiota.Cli.Commons.IO;
using Microsoft.Kiota.Http.HttpClientLibrary;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware;
using Microsoft.Kiota.Http.HttpClientLibrary.Middleware.Options;
Expand Down Expand Up @@ -43,7 +45,7 @@ static async Task<int> Main(string[] args)
var authStrategy = AuthenticationStrategy.DeviceCode;

var credential = await authServiceFactory.GetTokenCredentialAsync(authStrategy, authSettings?.TenantId, authSettings?.ClientId);
var authProvider = new AzureIdentityAuthenticationProvider(credential);
var authProvider = new AzureIdentityAuthenticationProvider(credential, new string[] {"graph.microsoft.com"});
var defaultHandlers = KiotaClientFactory.CreateDefaultHandlers();

var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version;
Expand All @@ -67,8 +69,6 @@ static async Task<int> Main(string[] args)
using var httpClient = KiotaClientFactory.Create(finalHandler);
var core = new HttpClientRequestAdapter(authProvider, httpClient: httpClient);
var client = new GraphClient(core);
var rootCommand = client.BuildCommand();
rootCommand.Description = "Microsoft Graph CLI";

var commands = new List<Command>();
var loginCommand = new LoginCommand(authServiceFactory);
Expand All @@ -77,7 +77,12 @@ static async Task<int> Main(string[] args)
var logoutCommand = new LogoutCommand(new LogoutService());
commands.Add(logoutCommand.Build());

var builder = BuildCommandLine(client, commands).UseDefaults();
var builder = BuildCommandLine(client, commands).UseDefaults().UseHost(CreateHostBuilder);
builder.AddMiddleware((invocation) => {
var host = invocation.GetHost();
var outputFormatterFactory = host.Services.GetRequiredService<IOutputFormatterFactory>();
invocation.BindingContext.AddService<IOutputFormatterFactory>(_ => outputFormatterFactory);
});
builder.UseExceptionHandler((ex, context) => {
if (ex is AuthenticationRequiredException) {
Console.ResetColor();
Expand All @@ -87,14 +92,14 @@ static async Task<int> Main(string[] args)
}
});

var parser = builder.UseHost(CreateHostBuilder).Build();
var parser = builder.Build();

return await parser.InvokeAsync(args);
}

static CommandLineBuilder BuildCommandLine(GraphClient client, IEnumerable<Command> commands)
{
var rootCommand = client.BuildCommand();
var rootCommand = client.BuildRootCommand();
rootCommand.Description = "Microsoft Graph CLI";

foreach (var command in commands) {
Expand All @@ -113,6 +118,7 @@ static IHostBuilder CreateHostBuilder(string[] args) =>
var authSection = ctx.Configuration.GetSection(Constants.AuthenticationSection);
services.Configure<AuthenticationOptions>(authSection);
services.AddSingleton<IPathUtility, PathUtility>();
services.AddSingleton<IOutputFormatterFactory, OutputFormatterFactory>();
});

static void ConfigureAppConfiguration(IConfigurationBuilder builder) {
Expand Down
51 changes: 12 additions & 39 deletions src/generated/Admin/AdminRequestBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using ApiSdk.Models.Microsoft.Graph;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Cli.Commons.IO;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -37,20 +37,19 @@ public Command BuildGetCommand() {
};
expandOption.IsRequired = false;
command.AddOption(expandOption);
command.SetHandler(async (string[] select, string[] expand) => {
var outputOption = new Option<FormatterType>("--output", () => FormatterType.JSON){
IsRequired = true
};
command.AddOption(outputOption);
command.SetHandler(async (string[] select, string[] expand, FormatterType output, IOutputFormatterFactory outputFormatterFactory, CancellationToken cancellationToken) => {
var requestInfo = CreateGetRequestInformation(q => {
q.Select = select;
q.Expand = expand;
});
var result = await RequestAdapter.SendAsync<ApiSdk.Models.Microsoft.Graph.Admin>(requestInfo);
// Print request output. What if the request has no return?
using var serializer = RequestAdapter.SerializationWriterFactory.GetSerializationWriter("application/json");
serializer.WriteObjectValue(null, result);
using var content = serializer.GetSerializedContent();
using var reader = new StreamReader(content);
var strContent = await reader.ReadToEndAsync();
Console.Write(strContent + "\n");
}, selectOption, expandOption);
var response = await RequestAdapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping: default, cancellationToken: cancellationToken);
var formatter = outputFormatterFactory.GetFormatter(output);
formatter.WriteOutput(response);
}, selectOption, expandOption, outputOption);
return command;
}
/// <summary>
Expand All @@ -64,14 +63,13 @@ public Command BuildPatchCommand() {
};
bodyOption.IsRequired = true;
command.AddOption(bodyOption);
command.SetHandler(async (string body) => {
command.SetHandler(async (string body, IOutputFormatterFactory outputFormatterFactory, CancellationToken cancellationToken) => {
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(body));
var parseNode = ParseNodeFactoryRegistry.DefaultInstance.GetRootParseNode("application/json", stream);
var model = parseNode.GetObjectValue<ApiSdk.Models.Microsoft.Graph.Admin>();
var requestInfo = CreatePatchRequestInformation(model, q => {
});
await RequestAdapter.SendNoContentAsync(requestInfo);
// Print request output. What if the request has no return?
await RequestAdapter.SendNoContentAsync(requestInfo, errorMapping: default, cancellationToken: cancellationToken);
Console.WriteLine("Success");
}, bodyOption);
return command;
Expand Down Expand Up @@ -139,31 +137,6 @@ public RequestInformation CreatePatchRequestInformation(ApiSdk.Models.Microsoft.
requestInfo.AddRequestOptions(o?.ToArray());
return requestInfo;
}
/// <summary>
/// Get admin
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
/// <param name="h">Request headers</param>
/// <param name="o">Request options</param>
/// <param name="q">Request query parameters</param>
/// <param name="responseHandler">Response handler to use in place of the default response handling provided by the core service</param>
/// </summary>
public async Task<ApiSdk.Models.Microsoft.Graph.Admin> GetAsync(Action<GetQueryParameters> q = default, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
var requestInfo = CreateGetRequestInformation(q, h, o);
return await RequestAdapter.SendAsync<ApiSdk.Models.Microsoft.Graph.Admin>(requestInfo, responseHandler, cancellationToken);
}
/// <summary>
/// Update admin
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
/// <param name="h">Request headers</param>
/// <param name="model"></param>
/// <param name="o">Request options</param>
/// <param name="responseHandler">Response handler to use in place of the default response handling provided by the core service</param>
/// </summary>
public async Task PatchAsync(ApiSdk.Models.Microsoft.Graph.Admin model, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
_ = model ?? throw new ArgumentNullException(nameof(model));
var requestInfo = CreatePatchRequestInformation(model, h, o);
await RequestAdapter.SendNoContentAsync(requestInfo, responseHandler, cancellationToken);
}
/// <summary>Get admin</summary>
public class GetQueryParameters : QueryParametersBase {
/// <summary>Expand related entities</summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
using ApiSdk.Models.Microsoft.Graph;
using Microsoft.Kiota.Abstractions;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Cli.Commons.IO;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
using System.Linq;
using System.Text;
Expand All @@ -22,12 +22,11 @@ public class HealthOverviewsRequestBuilder {
private string UrlTemplate { get; set; }
public List<Command> BuildCommand() {
var builder = new ServiceHealthRequestBuilder(PathParameters, RequestAdapter);
var commands = new List<Command> {
builder.BuildDeleteCommand(),
builder.BuildGetCommand(),
builder.BuildIssuesCommand(),
builder.BuildPatchCommand(),
};
var commands = new List<Command>();
commands.Add(builder.BuildDeleteCommand());
commands.Add(builder.BuildGetCommand());
commands.Add(builder.BuildIssuesCommand());
commands.Add(builder.BuildPatchCommand());
return commands;
}
/// <summary>
Expand All @@ -41,21 +40,20 @@ public Command BuildCreateCommand() {
};
bodyOption.IsRequired = true;
command.AddOption(bodyOption);
command.SetHandler(async (string body) => {
var outputOption = new Option<FormatterType>("--output", () => FormatterType.JSON){
IsRequired = true
};
command.AddOption(outputOption);
command.SetHandler(async (string body, FormatterType output, IOutputFormatterFactory outputFormatterFactory, CancellationToken cancellationToken) => {
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(body));
var parseNode = ParseNodeFactoryRegistry.DefaultInstance.GetRootParseNode("application/json", stream);
var model = parseNode.GetObjectValue<ServiceHealth>();
var requestInfo = CreatePostRequestInformation(model, q => {
});
var result = await RequestAdapter.SendAsync<ServiceHealth>(requestInfo);
// Print request output. What if the request has no return?
using var serializer = RequestAdapter.SerializationWriterFactory.GetSerializationWriter("application/json");
serializer.WriteObjectValue(null, result);
using var content = serializer.GetSerializedContent();
using var reader = new StreamReader(content);
var strContent = await reader.ReadToEndAsync();
Console.Write(strContent + "\n");
}, bodyOption);
var response = await RequestAdapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping: default, cancellationToken: cancellationToken);
var formatter = outputFormatterFactory.GetFormatter(output);
formatter.WriteOutput(response);
}, bodyOption, outputOption);
return command;
}
/// <summary>
Expand Down Expand Up @@ -100,7 +98,11 @@ public Command BuildListCommand() {
};
expandOption.IsRequired = false;
command.AddOption(expandOption);
command.SetHandler(async (int? top, int? skip, string search, string filter, bool? count, string[] orderby, string[] select, string[] expand) => {
var outputOption = new Option<FormatterType>("--output", () => FormatterType.JSON){
IsRequired = true
};
command.AddOption(outputOption);
command.SetHandler(async (int? top, int? skip, string search, string filter, bool? count, string[] orderby, string[] select, string[] expand, FormatterType output, IOutputFormatterFactory outputFormatterFactory, CancellationToken cancellationToken) => {
var requestInfo = CreateGetRequestInformation(q => {
q.Top = top;
q.Skip = skip;
Expand All @@ -111,15 +113,10 @@ public Command BuildListCommand() {
q.Select = select;
q.Expand = expand;
});
var result = await RequestAdapter.SendAsync<HealthOverviewsResponse>(requestInfo);
// Print request output. What if the request has no return?
using var serializer = RequestAdapter.SerializationWriterFactory.GetSerializationWriter("application/json");
serializer.WriteObjectValue(null, result);
using var content = serializer.GetSerializedContent();
using var reader = new StreamReader(content);
var strContent = await reader.ReadToEndAsync();
Console.Write(strContent + "\n");
}, topOption, skipOption, searchOption, filterOption, countOption, orderbyOption, selectOption, expandOption);
var response = await RequestAdapter.SendPrimitiveAsync<Stream>(requestInfo, errorMapping: default, cancellationToken: cancellationToken);
var formatter = outputFormatterFactory.GetFormatter(output);
formatter.WriteOutput(response);
}, topOption, skipOption, searchOption, filterOption, countOption, orderbyOption, selectOption, expandOption, outputOption);
return command;
}
/// <summary>
Expand Down Expand Up @@ -174,31 +171,6 @@ public RequestInformation CreatePostRequestInformation(ServiceHealth body, Actio
requestInfo.AddRequestOptions(o?.ToArray());
return requestInfo;
}
/// <summary>
/// A collection of service health information for tenant. This property is a contained navigation property, it is nullable and readonly.
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
/// <param name="h">Request headers</param>
/// <param name="o">Request options</param>
/// <param name="q">Request query parameters</param>
/// <param name="responseHandler">Response handler to use in place of the default response handling provided by the core service</param>
/// </summary>
public async Task<HealthOverviewsResponse> GetAsync(Action<GetQueryParameters> q = default, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
var requestInfo = CreateGetRequestInformation(q, h, o);
return await RequestAdapter.SendAsync<HealthOverviewsResponse>(requestInfo, responseHandler, cancellationToken);
}
/// <summary>
/// A collection of service health information for tenant. This property is a contained navigation property, it is nullable and readonly.
/// <param name="cancellationToken">Cancellation token to use when cancelling requests</param>
/// <param name="h">Request headers</param>
/// <param name="model"></param>
/// <param name="o">Request options</param>
/// <param name="responseHandler">Response handler to use in place of the default response handling provided by the core service</param>
/// </summary>
public async Task<ServiceHealth> PostAsync(ServiceHealth model, Action<IDictionary<string, string>> h = default, IEnumerable<IRequestOption> o = default, IResponseHandler responseHandler = default, CancellationToken cancellationToken = default) {
_ = model ?? throw new ArgumentNullException(nameof(model));
var requestInfo = CreatePostRequestInformation(model, h, o);
return await RequestAdapter.SendAsync<ServiceHealth>(requestInfo, responseHandler, cancellationToken);
}
/// <summary>A collection of service health information for tenant. This property is a contained navigation property, it is nullable and readonly.</summary>
public class GetQueryParameters : QueryParametersBase {
/// <summary>Include count of items</summary>
Expand Down
Loading