Skip to content
Open
Show file tree
Hide file tree
Changes from 4 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
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@
//-------- Editor configuration --------
"editor.insertSpaces": true,
"editor.tabSize": 4,

//-------- Files configuration --------
"files.autoGuessEncoding": false,
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"search.exclude": {
"**/Tests/Data*": true
},

//-------- PowerShell configuration --------
"powershell.codeFormatting.alignPropertyValuePairs": true,
"powershell.codeFormatting.preset": "Allman",
"powershell.scriptAnalysis.settingsPath": "./ScriptAnalyzerSettings.psd1",

//-------- Language configuration --------
"[json]": {
"editor.tabSize": 2
},

"[xml]": {
"editor.tabSize": 2
},
Expand Down
2 changes: 1 addition & 1 deletion BuildTasks/SetVersion.Task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ task SetVersion {
"Checking for published version"
$publishedModule = Find-Module -Name $ModuleName -ErrorAction 'Ignore' |
Sort-Object -Property {[version]$_.Version} -Descending |
Select -First 1
Select-Object -First 1

if($null -ne $publishedModule)
{
Expand Down
24 changes: 20 additions & 4 deletions Docs/en-US/Invoke-SnowSql.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ Invokes a Snowflake SQL statement

### QueryConnection (Default)
```
Invoke-SnowSql [-Connection <Object>] [-Query <String[]>] [-WhatIf] [-Confirm] [<CommonParameters>]
Invoke-SnowSql [-Connection <Object>] [-Query <String[]>] [-Timeout <Int32>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

### PathCred
Expand All @@ -25,8 +26,8 @@ Invoke-SnowSql -Endpoint <String> -Credential <PSCredential> [-Path <String>] [-

### QueryCred
```
Invoke-SnowSql -Endpoint <String> -Credential <PSCredential> [-Query <String[]>] [-WhatIf] [-Confirm]
[<CommonParameters>]
Invoke-SnowSql -Endpoint <String> -Credential <PSCredential> [-Query <String[]>] [-Timeout <Int32>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

### PathConnection
Expand All @@ -39,7 +40,7 @@ Invokes a Snowflake SQL statement

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Open-SnowSqlConnection
```
Expand Down Expand Up @@ -123,6 +124,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Timeout
Login timeout in seconds

```yaml
Type: Int32
Parameter Sets: QueryConnection, QueryCred
Aliases:

Required: False
Position: Named
Default value: 10
Accept pipeline input: False
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

Expand Down
24 changes: 20 additions & 4 deletions Docs/en-US/Open-SnowSqlConnection.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Opens a connection to Snowflake
## SYNTAX

```
Open-SnowSqlConnection [-Endpoint] <String> [-Credential] <PSCredential> [-WhatIf] [-Confirm]
[<CommonParameters>]
Open-SnowSqlConnection [-Endpoint] <String> [-Credential] <PSCredential> [[-Timeout] <Int32>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

## DESCRIPTION
Establishes a few important environment values for connecting to snowflake

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Open-SnowSqlConnection -Endpoint contoso.east-us-2.azure -Credential (Get-Credential)
```
Expand Down Expand Up @@ -59,6 +59,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -Timeout
Login timeout in seconds

```yaml
Type: Int32
Parameter Sets: (All)
Aliases:

Required: False
Position: 3
Default value: 10
Accept pipeline input: False
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

Expand All @@ -75,7 +90,8 @@ Accept wildcard characters: False
```

### -WhatIf
Shows what would happen if the cmdlet runs. The cmdlet is not run.
Shows what would happen if the cmdlet runs.
The cmdlet is not run.

```yaml
Type: SwitchParameter
Expand Down
4 changes: 2 additions & 2 deletions Module.build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ task Publish Build, PublishVersion, Helpify, Test, PublishModule
task TFS Clean, Build, PublishVersion, Helpify, Test
task DevTest ImportDevModule, Pester

Write-Host 'Import common tasks'
Write-Information 'Import common tasks'
Get-ChildItem -Path $buildroot\BuildTasks\*.Task.ps1 |
ForEach-Object {Write-Host $_.FullName;. $_.FullName}
ForEach-Object {Write-Information $_.FullName;. $_.FullName}
2 changes: 1 addition & 1 deletion SnowSQL/SnowSQL.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ foreach($file in $classFiles)
}
}

$importOrder = $classes.GetEnumerator() |
$importOrder = $classes.GetEnumerator() |
Resolve-DependencyOrder -Key {$_.Name} -DependsOn {$_.Value.Base}

foreach( $class in $importOrder )
Expand Down
27 changes: 22 additions & 5 deletions SnowSQL/public/Invoke-SnowSql.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ function Invoke-SnowSql
[string[]]
$Query = '!help',

# Login timeout in seconds
[Parameter(ParameterSetName = 'QueryCred')]
[Parameter(ParameterSetName = 'QueryConnection')]
Comment thread
aikiox marked this conversation as resolved.
[int]
$Timeout = 10,

# SnowSql script file to execute
[Parameter(ParameterSetName = 'PathCred')]
[Parameter(ParameterSetName = 'PathConnection')]
Expand All @@ -56,16 +62,16 @@ function Invoke-SnowSql
try
{
$snowSql = Get-Command snowsql -ErrorAction Stop |
Select-Object -First 1 -ExpandProperty Source
Select-Object -First 1 -ExpandProperty Source
Comment thread
aikiox marked this conversation as resolved.
Outdated
}
catch
{
Write-Error "Could not find [snowsql.exe] on local system. Install snowsql.exe and make it available in the %path%. Install instructions can be found here [https://docs.snowflake.net/manuals/user-guide/snowsql-install-config.html]" -ErrorAction Stop
}

if($PSCmdlet.ParameterSetName -match 'Connection$')
if ($PSCmdlet.ParameterSetName -match 'Connection$')
{
if( -not $Connection )
if ( -not $Connection )
{
$Connection = Get-SnowSqlConnection
}
Expand Down Expand Up @@ -100,6 +106,10 @@ function Invoke-SnowSql
{
'--option', 'log_level=DEBUG'
}
if ($timeout)
{
'--option', $('login_timeout=' + $timeout)
}
if ($Path)
{
'--filename', $Path
Expand All @@ -113,8 +123,15 @@ function Invoke-SnowSql
Write-Debug ("Executing [& '$snowsql' $snowSqlParam]" -f $snowsql)
if ($PSCmdlet.ShouldProcess("Execute SnowSql on [$Endpoint] as [$($Credential.UserName)]. Use -Debug to see full command"))
{
$env:SNOWSQL_PWD = $Credential.GetNetworkCredential().password
$results = & $snowsql @snowSqlParam | ConvertFrom-Csv
$env:SNOWSQL_PWD = $Credential.GetNetworkCredential().Password
try
{
$results = & $snowsql @snowSqlParam | ConvertFrom-Csv
}
catch
{
$results = $null
}
$env:SNOWSQL_PWD = ""
Write-Verbose "LastExitCode[$LastExitCode]"
}
Expand Down
37 changes: 31 additions & 6 deletions SnowSQL/public/Open-SnowSqlConnection.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function Open-SnowSqlConnection
#>

[OutputType('SnowSql.Connection')]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification="Implemented in Invoke-SnowSql")]
[Diagnostics.CodeAnalysis.SuppressMessageAttribute("PSShouldProcess", "", Justification = "Implemented in Invoke-SnowSql")]
[cmdletbinding(SupportsShouldProcess)]
param(
# Snowflake endpoint (ex: contoso.east-us-2.azure)
Expand All @@ -26,8 +26,19 @@ function Open-SnowSqlConnection
# Credential for snowflake endpoint
[Parameter(Mandatory)]
[PSCredential]
$Credential
$Credential,

# Login timeout in seconds
[int]
$Timeout = 10
)
begin
{
if ($Endpoint -match '(http[s]?)(:\/\/)([^\s,]+)')
{
Write-Error ("Snowflake endpoint must not be a URL {0}" -f $Endpoint) -ErrorAction Stop
}
}

end
{
Expand All @@ -42,10 +53,24 @@ function Open-SnowSqlConnection
Query = '!help'
ErrorAction = 'Stop'
Connection = $SnowSqlConnection
timeout = $Timeout
}
if ($PSCmdlet.ShouldProcess("Execute SnowSql query [$($invokeSnowSqlSplat.query)] on [$Endpoint] as [$($Credential.UserName)]. Use -Debug to see full command"))
{
$Result = Invoke-SnowSql @invokeSnowSqlSplat
}
else
{
$Result = $true
}
if (-not $Result)
{
Write-Error ("Unable to connect to SnowSql endpoint {0}" -f $Endpoint) -ErrorAction Stop
Comment thread
aikiox marked this conversation as resolved.
Outdated
}
else
{
$Script:SnowSqlConnection = $SnowSqlConnection
return $Script:SnowSqlConnection
}
$null = Invoke-SnowSql @invokeSnowSqlSplat
$Script:SnowSqlConnection = $SnowSqlConnection

return $Script:SnowSqlConnection
}
}
2 changes: 1 addition & 1 deletion Tests/Get-SnowSqlConnection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ InModuleScope SnowSQL {
Describe 'Function Get-SnowSqlConnection' -Tag Build {
It 'Get SnowSql Connection' {
Mock Invoke-SnowSql -Verifiable {}
Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty)
Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty) -WhatIf
Get-SnowSqlConnection | Should -Not -BeNullOrEmpty
}
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Open-SnowSqlConnection.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ InModuleScope SnowSql {
Describe 'Function Open-SnowSqlConnection' -Tag Build {
It 'Open SnowSql Connection ' {
Mock Invoke-SnowSql -Verifiable {}
Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty)
Open-SnowSqlConnection -Endpoint "test" -Credential ([pscredential]::Empty) -Whatif
}
}
}