From 2effebd1fd999e7cfc4f6bb4760a1207996c59ef Mon Sep 17 00:00:00 2001 From: Santiago Squarzon Date: Mon, 16 Dec 2024 16:58:23 -0300 Subject: [PATCH] done with connectkusto --- docs/en-US/Connect-Kusto.md | 339 +++++++++++++++++++++ module/PowerShellKusto.psd1 | 4 +- src/PowerShellKusto/ConnectKustoCommand.cs | 70 ++++- src/PowerShellKusto/PowerShellKusto.csproj | 5 +- 4 files changed, 403 insertions(+), 15 deletions(-) create mode 100644 docs/en-US/Connect-Kusto.md diff --git a/docs/en-US/Connect-Kusto.md b/docs/en-US/Connect-Kusto.md new file mode 100644 index 0000000..81d9b1f --- /dev/null +++ b/docs/en-US/Connect-Kusto.md @@ -0,0 +1,339 @@ +--- +external help file: PowerShellKusto.dll-Help.xml +Module Name: PowerShellKusto +online version: +schema: 2.0.0 +--- + +# Connect-Kusto + +## SYNOPSIS + +{{ Fill in the Synopsis }} + +## SYNTAX + +### Credential + +```powershell +Connect-Kusto + [-ClusterUri] + [[-Database] ] + -Authority + -Credential + [-RequestProperties ] + [-ServerTimeout ] + [-NoTruncation] + [] +``` + +### UserPrompt + +```powershell +Connect-Kusto + [-ClusterUri] + [[-Database] ] + [-Authority ] + [-UserPrompt] + [-RequestProperties ] + [-ServerTimeout ] + [-NoTruncation] + [] +``` + +### Certificate + +```powershell +Connect-Kusto + [-ClusterUri] + [[-Database] ] + -Authority + -AppId + -Certificate + [-UseTrustedIssuer] + [-RequestProperties ] + [-ServerTimeout ] + [-NoTruncation] + [] +``` + +### CertificateThumbprint + +```powershell +Connect-Kusto + [-ClusterUri] + [[-Database] ] + -Authority + -AppId + -Thumbprint + [-RequestProperties ] + [-ServerTimeout ] + [-NoTruncation] + [] +``` + +### Identity + +```powershell +Connect-Kusto + [-ClusterUri] + [[-Database] ] + [-Identity] + [-RequestProperties ] + [-ServerTimeout ] + [-NoTruncation] + [] +``` + +## DESCRIPTION + +{{ Fill in the Description }} + +## EXAMPLES + +### Example 1 + +```powershell +PS C:\> {{ Add example code here }} +``` + +{{ Add example description here }} + +## PARAMETERS + +### -AppId + +{{ Fill AppId Description }} + +```yaml +Type: String +Parameter Sets: Certificate, CertificateThumbprint +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Authority + +{{ Fill Authority Description }} + +```yaml +Type: String +Parameter Sets: Credential, Certificate, CertificateThumbprint +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +```yaml +Type: String +Parameter Sets: UserPrompt +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Certificate + +{{ Fill Certificate Description }} + +```yaml +Type: X509Certificate2 +Parameter Sets: Certificate +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ClusterUri + +{{ Fill ClusterUri Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: True +Position: 0 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Credential + +{{ Fill Credential Description }} + +```yaml +Type: PSCredential +Parameter Sets: Credential +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Database + +{{ Fill Database Description }} + +```yaml +Type: String +Parameter Sets: (All) +Aliases: + +Required: False +Position: 1 +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Identity + +{{ Fill Identity Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: Identity +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -NoTruncation + +{{ Fill NoTruncation Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -RequestProperties + +{{ Fill RequestProperties Description }} + +```yaml +Type: ClientRequestProperties +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -ServerTimeout + +{{ Fill ServerTimeout Description }} + +```yaml +Type: TimeSpan +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -Thumbprint + +{{ Fill Thumbprint Description }} + +```yaml +Type: String +Parameter Sets: CertificateThumbprint +Aliases: + +Required: True +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UseTrustedIssuer + +{{ Fill UseTrustedIssuer Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: Certificate +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### -UserPrompt + +{{ Fill UserPrompt Description }} + +```yaml +Type: SwitchParameter +Parameter Sets: UserPrompt +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + +### CommonParameters + +This cmdlet supports the common parameters. +For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). + +## INPUTS + +### None + +## OUTPUTS + +### System.Object + +## NOTES + +## RELATED LINKS diff --git a/module/PowerShellKusto.psd1 b/module/PowerShellKusto.psd1 index 9d72aed..c4cfaea 100644 --- a/module/PowerShellKusto.psd1 +++ b/module/PowerShellKusto.psd1 @@ -8,7 +8,7 @@ @{ # Script module or binary module file associated with this manifest. - RootModule = 'bin/netstandard2.0/PowerShellKusto.dll' + RootModule = 'bin/net6/PowerShellKusto.dll' # Version number of this module. ModuleVersion = '1.0.0' @@ -32,7 +32,7 @@ Description = 'PowerShell Module that wraps Microsoft.Azure.Kusto.Data & Microsoft.Azure.Kusto.Ingest' # Minimum version of the PowerShell engine required by this module - PowerShellVersion = '5.1' + PowerShellVersion = '7.2.0' # Name of the PowerShell host required by this module # PowerShellHostName = '' diff --git a/src/PowerShellKusto/ConnectKustoCommand.cs b/src/PowerShellKusto/ConnectKustoCommand.cs index a13d123..0573162 100644 --- a/src/PowerShellKusto/ConnectKustoCommand.cs +++ b/src/PowerShellKusto/ConnectKustoCommand.cs @@ -1,6 +1,7 @@ using System; using System.Management.Automation; using System.Security.Authentication; +using System.Security.Cryptography.X509Certificates; using Kusto.Data; using Kusto.Data.Common; @@ -13,25 +14,51 @@ public sealed class ConnectKustoCommand : PSCmdlet private const string IdentitySet = "Identity"; - private static KustoConnectionDetails? s_connectionDetails; + private const string UserPromptSet = "UserPrompt"; + + private const string CertificateSet = "Certificate"; + private const string CertificateThumbprintSet = "CertificateThumbprint"; + + [ThreadStatic] + private static KustoConnectionDetails? s_connectionDetails; [Parameter(Mandatory = true, Position = 0)] - public string Cluster { get; set; } = null!; + public string ClusterUri { get; set; } = null!; - [Parameter(Mandatory = true, Position = 1)] - public string Database { get; set; } = null!; + [Parameter(Position = 1)] + [ValidateNotNullOrEmpty] + public string? Database { get; set; } [Parameter(Mandatory = true, ParameterSetName = CredentialSet)] - [Credential] - public PSCredential Credential { get; set; } = null!; + [Parameter(ParameterSetName = UserPromptSet)] + [Parameter(Mandatory = true, ParameterSetName = CertificateSet)] + [Parameter(Mandatory = true, ParameterSetName = CertificateThumbprintSet)] + public string? Authority { get; set; } [Parameter(Mandatory = true, ParameterSetName = CredentialSet)] - public string Authority { get; set; } = null!; + [Credential] + public PSCredential Credential { get; set; } = null!; [Parameter(ParameterSetName = IdentitySet)] public SwitchParameter Identity { get; set; } + [Parameter(ParameterSetName = UserPromptSet)] + public SwitchParameter UserPrompt { get; set; } + + [Parameter(Mandatory = true, ParameterSetName = CertificateSet)] + [Parameter(Mandatory = true, ParameterSetName = CertificateThumbprintSet)] + public string AppId { get; set; } = null!; + + [Parameter(Mandatory = true, ParameterSetName = CertificateSet)] + public X509Certificate2 Certificate { get; set; } = null!; + + [Parameter(ParameterSetName = CertificateSet)] + public SwitchParameter UseTrustedIssuer { get; set; } + + [Parameter(Mandatory = true, ParameterSetName = CertificateThumbprintSet)] + public string Thumbprint { get; set; } = null!; + [Parameter] public ClientRequestProperties? RequestProperties { get; set; } @@ -48,7 +75,9 @@ protected override void EndProcessing() new(ClientRequestProperties.OptionNoTruncation, NoTruncation.IsPresent)], null); - KustoConnectionStringBuilder builder = new(Cluster, Database); + KustoConnectionStringBuilder builder = Database is not null + ? new(ClusterUri, Database) + : new(ClusterUri); try { @@ -60,9 +89,28 @@ protected override void EndProcessing() CredentialSet => new KustoConnectionDetails( builder.WithAadApplicationKeyAuthentication( - Credential.UserName, - Credential.GetNetworkCredential().Password, - Authority), + applicationClientId: Credential.UserName, + applicationKey: Credential.GetNetworkCredential().Password, + authority: Authority), + RequestProperties), + + UserPromptSet => new KustoConnectionDetails( + builder.WithAadUserPromptAuthentication(authority: Authority), + RequestProperties), + + CertificateSet => new KustoConnectionDetails( + builder.WithAadApplicationCertificateAuthentication( + applicationClientId: AppId, + applicationCertificate: Certificate, + authority: Authority, + sendX5c: UseTrustedIssuer), + RequestProperties), + + CertificateThumbprintSet => new KustoConnectionDetails( + builder.WithAadApplicationThumbprintAuthentication( + applicationClientId: AppId, + applicationCertificateThumbprint: Thumbprint, + authority: Authority), RequestProperties), _ => null diff --git a/src/PowerShellKusto/PowerShellKusto.csproj b/src/PowerShellKusto/PowerShellKusto.csproj index 4fe74b3..88ca7be 100644 --- a/src/PowerShellKusto/PowerShellKusto.csproj +++ b/src/PowerShellKusto/PowerShellKusto.csproj @@ -1,16 +1,17 @@  - netstandard2.0 + net6 enable PowerShellKusto latest + NU1903 - +