Skip to content

Migrate FirmwareAnalysis from generation to vidai/secrets-detection-autorest #24464

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

Merged
merged 2 commits into from
Mar 23, 2024
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -47,37 +47,41 @@

# Ask for the shared functionality table
$VTable = Register-AzModule

# Tweaks the pipeline on module load
$instance.OnModuleLoad = $VTable.OnModuleLoad

# Following two delegates are added for telemetry
$instance.GetTelemetryId = $VTable.GetTelemetryId
$instance.Telemetry = $VTable.Telemetry


# Delegate to sanitize the output object
$instance.SanitizeOutput = $VTable.SanitizerHandler

# Delegate to get the telemetry info
$instance.GetTelemetryInfo = $VTable.GetTelemetryInfo

# Tweaks the pipeline per call
$instance.OnNewRequest = $VTable.OnNewRequest

# Gets shared parameter values
$instance.GetParameterValue = $VTable.GetParameterValue

# Allows shared module to listen to events from this module
$instance.EventListener = $VTable.EventListener

# Gets shared argument completers
$instance.ArgumentCompleter = $VTable.ArgumentCompleter

# The name of the currently selected Azure profile
$instance.ProfileName = $VTable.ProfileName


# Load the custom module
$customModulePath = Join-Path $PSScriptRoot './custom/Az.FirmwareAnalysis.custom.psm1'
if(Test-Path $customModulePath) {
$null = Import-Module -Name $customModulePath
}

# Export nothing to clear implicit exports
Export-ModuleMember

Expand All @@ -97,12 +101,12 @@
# Load the last folder if no profile is selected
$profileDirectory = $directories | Select-Object -Last 1
}

if($profileDirectory) {
Write-Information "Loaded Azure profile '$($profileDirectory.Name)' for module '$($instance.Name)'"
$exportsPath = $profileDirectory.FullName
}

if($exportsPath) {
Get-ChildItem -Path $exportsPath -Recurse -Include '*.ps1' -File | ForEach-Object { . $_.FullName }
$cmdletNames = Get-ScriptCmdlet -ScriptFolder $exportsPath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis
using SignalDelegate = global::System.Func<string, global::System.Threading.CancellationToken, global::System.Func<global::System.EventArgs>, global::System.Threading.Tasks.Task>;
using EventListenerDelegate = global::System.Func<string, global::System.Threading.CancellationToken, global::System.Func<global::System.EventArgs>, global::System.Func<string, global::System.Threading.CancellationToken, global::System.Func<global::System.EventArgs>, global::System.Threading.Tasks.Task>, global::System.Management.Automation.InvocationInfo, string, string, string, global::System.Exception, global::System.Threading.Tasks.Task>;
using NextDelegate = global::System.Func<global::System.Net.Http.HttpRequestMessage, global::System.Threading.CancellationToken, global::System.Action, global::System.Func<string, global::System.Threading.CancellationToken, global::System.Func<global::System.EventArgs>, global::System.Threading.Tasks.Task>, global::System.Threading.Tasks.Task<global::System.Net.Http.HttpResponseMessage>>;
using SanitizerDelegate = global::System.Action<object, string>;
using GetTelemetryInfoDelegate = global::System.Func<string, global::System.Collections.Generic.Dictionary<global::System.String,global::System.String>>;

/// <summary>A class that contains the module-common code and data.</summary>
public partial class Module
Expand Down Expand Up @@ -59,6 +61,9 @@ public partial class Module
/// <summary>The delegate to get the telemetry Id.</summary>
public GetTelemetryIdDelegate GetTelemetryId { get; set; }

/// <summary>The delegate to get the telemetry info.</summary>
public GetTelemetryInfoDelegate GetTelemetryInfo { get; set; }

/// <summary>the singleton of this module class</summary>
public static Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module Instance { get { if (_instance == null) { lock (_singletonLock) { if (_instance == null) { _instance = new Module(); }}} return _instance; } }

Expand All @@ -77,6 +82,9 @@ public partial class Module
/// <summary>The ResourceID for this module (azure arm).</summary>
public string ResourceId => @"Az.FirmwareAnalysis";

/// <summary>The delegate to call in WriteObject to sanitize the output object.</summary>
public SanitizerDelegate SanitizeOutput { get; set; }

/// <summary>The delegate for creating a telemetry.</summary>
public TelemetryDelegate Telemetry { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -407,6 +417,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -407,6 +417,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -407,6 +417,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -407,6 +417,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -402,6 +412,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -369,6 +379,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ protected override void EndProcessing()
// Flush buffer
WriteObject(_firstResponse);
}
var telemetryInfo = Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.GetTelemetryInfo?.Invoke(__correlationId);
if (telemetryInfo != null)
{
telemetryInfo.TryGetValue("SanitizedProperties", out var sanitizedProperties);
telemetryInfo.TryGetValue("InvocationName", out var invocationName);
if (!string.IsNullOrEmpty(sanitizedProperties))
{
WriteWarning($"The output of cmdlet {invocationName ?? "Unknown"} may compromise security by showing the following secrets: {sanitizedProperties}. Learn more at https://go.microsoft.com/fwlink/?linkid=2258844");
}
}
}

/// <summary>
Expand Down Expand Up @@ -381,6 +391,21 @@ protected override void StopProcessing()
base.StopProcessing();
}

/// <param name="sendToPipeline"></param>
new protected void WriteObject(object sendToPipeline)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline);
}

/// <param name="sendToPipeline"></param>
/// <param name="enumerateCollection"></param>
new protected void WriteObject(object sendToPipeline, bool enumerateCollection)
{
Microsoft.Azure.PowerShell.Cmdlets.FirmwareAnalysis.Module.Instance.SanitizeOutput?.Invoke(sendToPipeline, __correlationId);
base.WriteObject(sendToPipeline, enumerateCollection);
}

/// <summary>
/// a delegate that is called when the remote service returns default (any response code not handled elsewhere).
/// </summary>
Expand Down
Loading