-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from svrooij/feature/list-updates
Feature/list updates
- Loading branch information
Showing
18 changed files
with
1,040 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": ".NET Core Launch (console)", | ||
"type": "coreclr", | ||
"request": "launch", | ||
"preLaunchTask": "dotnet: build-cli", | ||
// If you have changed target frameworks, make sure to update the program path. | ||
"program": "${workspaceFolder}/src/WingetIntune.Cli/bin/Debug/net7.0/WingetIntune.Cli.dll", | ||
"args": [ | ||
"update", | ||
"list", | ||
"--username", "[email protected]" | ||
], | ||
"cwd": "${workspaceFolder}", | ||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console | ||
"console": "internalConsole", | ||
"stopAtEntry": false | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "2.0.0", | ||
"tasks": [ | ||
{ | ||
"type": "shell", | ||
"label": "dotnet: build-cli", | ||
"command": "dotnet build ${workspaceFolder}/src/WingetIntune.Cli/WingetIntune.Cli.csproj", | ||
"group": { | ||
"kind": "build", | ||
"isDefault": true | ||
}, | ||
"problemMatcher": "$msCompile" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.CommandLine; | ||
using WingetIntune.Models; | ||
|
||
namespace WingetIntune.Commands; | ||
|
||
internal class UpdateCommand : Command | ||
{ | ||
private const string name = "update"; | ||
private const string description = "Update a published app in Intune (cross platform)"; | ||
|
||
public UpdateCommand() : base(name, description) | ||
{ | ||
AddCommand(new UpdateListCommand()); | ||
} | ||
} | ||
|
||
internal class UpdateCommandOptions : WinGetRootCommand.DefaultOptions | ||
{ | ||
public string? PackageFolder { get; set; } | ||
public string? Tenant { get; set; } | ||
public string? Username { get; set; } | ||
public string? Token { get; set; } | ||
|
||
internal Intune.IntunePublishOptions GetPublishOptions() | ||
{ | ||
return new Intune.IntunePublishOptions | ||
{ | ||
Tenant = Tenant, | ||
Username = Username, | ||
Token = Token | ||
}; | ||
} | ||
} | ||
|
||
internal class UpdateAbleIntuneApp : IntuneApp | ||
{ | ||
public string? LatestVersion { get; set; } | ||
public bool IsUpdateAvailable => LatestVersion != null && LatestVersion != Version; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Hosting; | ||
using System.CommandLine.Invocation; | ||
using System.CommandLine.NamingConventionBinder; | ||
using System.Text.Json; | ||
using ConsoleTables; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Logging; | ||
using WingetIntune.Models; | ||
|
||
namespace WingetIntune.Commands; | ||
|
||
internal class UpdateListCommand : Command | ||
{ | ||
private const string name = "list"; | ||
private const string description = "Show the list of published apps in Intune (cross platform)"; | ||
|
||
public UpdateListCommand() : base(name, description) | ||
{ | ||
AddOption(PublishCommand.TenantOption); | ||
AddOption(PublishCommand.UsernameOption); | ||
AddOption(PublishCommand.TokenOption); | ||
this.Handler = CommandHandler.Create(HandleCommandAsync); | ||
} | ||
|
||
private async Task<int> HandleCommandAsync(UpdateCommandOptions options, InvocationContext context) | ||
{ | ||
var cancellationToken = context.GetCancellationToken(); | ||
|
||
var host = context.GetHost(); | ||
options.AdjustLogging(host); | ||
|
||
var logger = host.Services.GetRequiredService<ILogger<UpdateListCommand>>(); | ||
logger.LogInformation("Getting list of published apps"); | ||
var repo = host.Services.GetRequiredService<Winget.CommunityRepository.WingetRepository>(); | ||
var intuneManager = host.Services.GetRequiredService<IntuneManager>(); | ||
|
||
var apps = await intuneManager.GetPublishedAppsAsync(options.GetPublishOptions(), cancellationToken); | ||
|
||
var result = await GetUpdateAbleAppsAsync(apps, repo, cancellationToken); | ||
if (options.Json) | ||
{ | ||
Console.WriteLine(JsonSerializer.Serialize(result!)); | ||
return 0; | ||
} | ||
var table = new ConsoleTable("PackageId", "Version", "LatestVersion", "UpdateAvailable"); | ||
foreach (var app in result.OrderByDescending(a => a.IsUpdateAvailable).ThenBy(a => a.PackageId)) | ||
{ | ||
table.AddRow(app.PackageId, app.Version, app.LatestVersion, app.IsUpdateAvailable); | ||
} | ||
table.Write(Format.Minimal); | ||
return 0; | ||
} | ||
|
||
private static async Task<IEnumerable<UpdateAbleIntuneApp>> GetUpdateAbleAppsAsync(IEnumerable<IntuneApp> apps, Winget.CommunityRepository.WingetRepository repo, CancellationToken cancellationToken) | ||
{ | ||
var result = new List<UpdateAbleIntuneApp>(); | ||
foreach (var app in apps) | ||
{ | ||
var latestVersion = await repo.GetLatestVersion(app.PackageId, cancellationToken); | ||
result.Add(new UpdateAbleIntuneApp | ||
{ | ||
GraphId = app.GraphId, | ||
PackageId = app.PackageId, | ||
Name = app.Name, | ||
Version = app.Version, | ||
LatestVersion = latestVersion, | ||
}); | ||
} | ||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.