Skip to content

Commit

Permalink
Use Kiota serialization (#108)
Browse files Browse the repository at this point in the history
* Start using native files with new kiota version
* Add support for Scope tags

Fixed #109
  • Loading branch information
svrooij authored Sep 2, 2024
1 parent 2f1c256 commit 99ae8df
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 6 deletions.
38 changes: 32 additions & 6 deletions src/Svrooij.WinTuner.CmdLets/Commands/DeployWtWin32App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
using WingetIntune.Intune;
using GraphModels = Microsoft.Graph.Beta.Models;
using System.Linq;
using Microsoft.Kiota.Abstractions.Serialization;
using Microsoft.Kiota.Abstractions.Extensions;

namespace Svrooij.WinTuner.CmdLets.Commands;
/// <summary>
Expand Down Expand Up @@ -175,6 +177,12 @@ public class DeployWtWin32App : BaseIntuneCmdlet
HelpMessage = "Groups that the app should be uninstalled for, Group Object ID or `AllUsers` / `AllDevices`")]
public string[]? UninstallFor { get; set; }

/// <summary>
/// <para type="description">The role scope tags for this app</para>
/// </summary>
[Parameter(Mandatory = false, Position = 15, HelpMessage = "The role scope tags for this app")]
public string[]? RoleScopeTags { get; set; }

[ServiceDependency]
private ILogger<DeployWtWin32App>? logger;

Expand All @@ -196,16 +204,28 @@ protected override async Task ProcessAuthenticatedAsync(IAuthenticationProvider
{
logger?.LogDebug("Loading package details from RootPackageFolder {RootPackageFolder}, PackageId {PackageId}, Version {Version}", RootPackageFolder, PackageId, Version);
PackageFolder = Path.Combine(RootPackageFolder!, PackageId!, Version!);
logger?.LogDebug("Loading package details from folder {packageFolder}", PackageFolder);
logger?.LogDebug("Loading package details from folder {PackageFolder}", PackageFolder);
}

if (PackageFolder is not null)
{
logger?.LogInformation("Loading package details from folder {packageFolder}", PackageFolder);
var packageInfo = await metadataManager!.LoadPackageInfoFromFolderAsync(PackageFolder, cancellationToken);
App = metadataManager.ConvertPackageInfoToWin32App(packageInfo);
LogoPath = Path.Combine(PackageFolder, "..", "logo.png");
IntuneWinFile = metadataManager.GetIntuneWinFileName(PackageFolder, packageInfo);
logger?.LogInformation("Loading package details from folder {PackageFolder}", PackageFolder);
var win32LobAppFile = Path.Combine(PackageFolder, "win32LobApp.json");
if (File.Exists(win32LobAppFile))
{
logger?.LogDebug("Loading Win32LobApp from file {Win32LobAppFile}", win32LobAppFile);
var json = await File.ReadAllTextAsync(win32LobAppFile, cancellationToken);
App = await KiotaSerializer.DeserializeAsync<GraphModels.Win32LobApp>("application/json", json, cancellationToken);
IntuneWinFile = Path.Combine(PackageFolder, App!.FileName!);
}
else
{
logger?.LogDebug("Loading package info from folder {PackageFolder}", PackageFolder);
var packageInfo = await metadataManager!.LoadPackageInfoFromFolderAsync(PackageFolder, cancellationToken);
App = metadataManager.ConvertPackageInfoToWin32App(packageInfo);
LogoPath = Path.Combine(PackageFolder, "..", "logo.png");
IntuneWinFile = metadataManager.GetIntuneWinFileName(PackageFolder, packageInfo);
}
}
else
{
Expand All @@ -215,6 +235,12 @@ protected override async Task ProcessAuthenticatedAsync(IAuthenticationProvider
}
}

if (RoleScopeTags is not null && RoleScopeTags.Any())
{
logger?.LogInformation("Adding role scope tags to app");
App.RoleScopeTagIds = RoleScopeTags.AsList();
}

if (!string.IsNullOrEmpty(OverrideAppName))
{
App.DisplayName = OverrideAppName;
Expand Down
44 changes: 44 additions & 0 deletions src/Svrooij.WinTuner.CmdLets/Svrooij.WinTuner.CmdLets.dll-Help.xml
Original file line number Diff line number Diff line change
Expand Up @@ -690,6 +690,17 @@ Connect-WtWinTuner -UseDefaultCredentials</dev:code>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="15" aliases="none">
<maml:name>RoleScopeTags</maml:name>
<maml:description>
<maml:para>The role scope tags for this app</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="true">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="30" aliases="none">
<maml:name>GraphId</maml:name>
<maml:description>
Expand Down Expand Up @@ -792,6 +803,17 @@ Connect-WtWinTuner -UseDefaultCredentials</dev:code>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="15" aliases="none">
<maml:name>RoleScopeTags</maml:name>
<maml:description>
<maml:para>The role scope tags for this app</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="true">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="30" aliases="none">
<maml:name>GraphId</maml:name>
<maml:description>
Expand Down Expand Up @@ -872,6 +894,17 @@ Connect-WtWinTuner -UseDefaultCredentials</dev:code>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="15" aliases="none">
<maml:name>RoleScopeTags</maml:name>
<maml:description>
<maml:para>The role scope tags for this app</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="true">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="30" aliases="none">
<maml:name>GraphId</maml:name>
<maml:description>
Expand Down Expand Up @@ -1040,6 +1073,17 @@ Connect-WtWinTuner -UseDefaultCredentials</dev:code>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
<command:parameter required="false" variableLength="true" globbing="false" pipelineInput="False" position="15" aliases="none">
<maml:name>RoleScopeTags</maml:name>
<maml:description>
<maml:para>The role scope tags for this app</maml:para>
</maml:description>
<command:parameterValue required="false" variableLength="true">String[]</command:parameterValue>
<dev:type>
<maml:name>String[]</maml:name>
</dev:type>
<dev:defaultValue>None</dev:defaultValue>
</command:parameter>
</command:parameters>
<command:returnValues>
<command:returnValue>
Expand Down
22 changes: 22 additions & 0 deletions src/WingetIntune/Intune/IntuneManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Microsoft.Graph.Beta.Models;
using Microsoft.Graph.Beta.Models.ODataErrors;
using Microsoft.Kiota.Abstractions.Authentication;
using Microsoft.Kiota.Abstractions.Serialization;
using System.Text;
using System.Text.Json;
using WingetIntune.Graph;
Expand Down Expand Up @@ -677,6 +678,27 @@ private async Task WritePackageInfo(string packageFolder, PackageInfo packageInf
var json = JsonSerializer.SerializeToUtf8Bytes(packageInfo, MyJsonContext.Default.PackageInfo);
var jsonFile = Path.Combine(packageFolder, "app.json");
await fileManager.WriteAllBytesAsync(jsonFile, json, cancellationToken);

var win32File = Path.Combine(packageFolder, "win32LobApp.json");

var win32App = mapper.ToWin32LobApp(packageInfo);
var logoPath = Path.Combine(packageFolder, "..", "logo.png");
var logoBytes = await fileManager.ReadAllBytesAsync(logoPath, cancellationToken);
if (logoBytes.Length > 0)
{
win32App.LargeIcon = new MimeContent
{
Type = "image/png",
Value = logoBytes
};
}

using var stream = new MemoryStream();
using var jsonStream = KiotaSerializer.SerializeAsStream("application/json", win32App, false);
await jsonStream.CopyToAsync(stream, cancellationToken);
await stream.FlushAsync(cancellationToken);
stream.Seek(0, SeekOrigin.Begin);
await fileManager.WriteAllBytesAsync(win32File, stream.ToArray(), cancellationToken);
}

private GraphServiceClient CreateGraphClientFromOptions(IntunePublishOptions options)
Expand Down

0 comments on commit 99ae8df

Please sign in to comment.