Skip to content
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

add timeout connexion and add check on open connect #2

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 11 additions & 6 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
//-------- 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.codeFormatting.pipelineIndentationStyle": "IncreaseIndentationAfterEveryPipeline",
"powershell.scriptAnalysis.settingsPath": "./ScriptAnalyzerSettings.psd1",

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

"[xml]": {
"editor.tabSize": 2
},
Expand All @@ -32,6 +29,14 @@
"titleBar.inactiveForeground": "#e7e7e799",
"statusBar.background": "#2ba66c",
"statusBarItem.hoverBackground": "#38cc86",
"statusBar.foreground": "#e7e7e7"
}
"statusBar.foreground": "#e7e7e7",
"activityBar.activeBackground": "#38cc86",
"activityBar.activeBorder": "#934dd1",
"activityBar.background": "#38cc86",
"activityBar.foreground": "#15202b",
"activityBar.inactiveForeground": "#15202b99",
"activityBarBadge.background": "#934dd1",
"activityBarBadge.foreground": "#e7e7e7"
},
"peacock.color": "#2ba66c"
}
1 change: 1 addition & 0 deletions BuildTasks/GenerateMarkdown.Task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ task GenerateMarkdown {
Module = $ModuleName
OutputFolder = "$DocsPath\en-US"
WithModulePage = $true
Force = $true
}

# ErrorAction is set to SilentlyContinue so this
Expand Down
2 changes: 1 addition & 1 deletion BuildTasks/ImportDevModule.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@

task ImportDevModule {
ImportModule -Path "$Source\$ModuleName.psd1" -Force
Import-BuildModule -Path "$Source\$ModuleName.psd1" -Force
}
4 changes: 2 additions & 2 deletions BuildTasks/ImportModule.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function ImportModule
function Import-BuildModule
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't normally name internal functions with *-* syntax, but thats personal preference. Makes it confusing as it looks like you're using a cmdlet when you're using a local function instead. You can leave this, but just pointing out why it was named as it was originally.

{
param(
[string]$path,
Expand Down Expand Up @@ -29,5 +29,5 @@ function ImportModule
}

task ImportModule {
ImportModule -Path $ManifestPath
Import-BuildModule -Path $ManifestPath
}
2 changes: 2 additions & 0 deletions BuildTasks/InvokeBuildInit.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Write-Verbose " ModulePath [$ModulePath]" -Verbose
$Script:Folders = 'Classes', 'Includes', 'Internal', 'Private', 'Public', 'Resources'
Write-Verbose " Folders [$Folders]" -Verbose

$timestamp = Get-Date -Format o | ForEach-Object { $_ -replace ":", "." }
$PSVersion = $PSVersionTable.PSVersion.ToString()
$Script:TestFile = "$BuildRoot\Output\TestResults_PS$PSVersion`_$TimeStamp.xml"
Write-Verbose " TestFile [$TestFile]" -Verbose

Expand Down
46 changes: 23 additions & 23 deletions BuildTasks/Pester.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
task Pester {
$requiredPercent = $Script:CodeCoveragePercent
Import-Module Pester -Force
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't support pester 5+ so I can't really help you here, the help tests rely on pester 4 functionality, pester 5 appears to be completely throwing out variables from the outer scope within Context blocks. The tests should work fine on Pester 4.10 (they are still passing for me on https://github.com/loanDepot/SnowSQL master branch. I can't test 4.10 on your branch since your changes here will not run on 4.10 due to the changes below being 5.0 functionality).

I would recommend rolling the pester changes back, honestly, We've had nothing but trouble with pester 5 historically. Feel free to replace with a forced load of
Import-Module Pester -RequiredVersion 4.10.1 -Force
and a silent install of 4.10.1 if needed on appveyor (not sure how that works, really).

PSScriptAnalyzer and Pester updates are pretty involved sometimes, and we normally bulk update all our modules at once to a new version of pester once we know what we're getting ourselves into rather than piecemealing like this. If you can figure out how to make Pester 5 work here, be my guest, but it looks like the $node variables are completely gone once you enter the Context block in Pester 5, so you'd have to work around that somehow. I'm sure there's a way if you want to figure it out, but since we upgrade Pester in bulk across 50+ modules by merging a common base module repo in, we'd rather just solve it there once and leave this working as-is on Pester 4.10.1 until then, and merge that in one big batch to all our modules as we normally do.

$configuration = [PesterConfiguration]::Default
# assing properties & discover via intellisense
$configuration.Run.Path = 'Tests'
$configuration.Filter.Tag = 'Build'
$configuration.Run.PassThru = $true
$configuration.Output.Verbosity = 'Detailed'
$configuration.TestResult.Enabled = $true
$configuration.TestResult.OutputFormat = 'NUnitXml'
$configuration.TestResult.OutputPath = $testFile

$params = @{
OutputFile = $testFile
OutputFormat = 'NUnitXml'
PassThru = $true
Path = 'Tests'
Show = 'Failed', 'Fails', 'Summary'
Tag = 'Build'
}
if ($requiredPercent -gt 0.00) {

if($requiredPercent -gt 0.00)
{
$params['CodeCoverage'] = 'Output\*\*.psm1'
$params['CodeCoverageOutputFile'] = 'Output\codecoverage.xml'
$configuration.CodeCoverage.Enabled = $true
$configuration.CodeCoverage.OutputPath = 'Output\codecoverage.xml'
}

$results = Invoke-Pester @params
if ($results.FailedCount -gt 0)
{
Write-Error -Message "Failed [$($results.FailedCount)] Pester tests."
}
$results = Invoke-Pester -Configuration $configuration
if ($requiredPercent -gt 0.00) {

if($results.codecoverage.NumberOfCommandsAnalyzed -gt 0)
{
$codeCoverage = $results.codecoverage.NumberOfCommandsExecuted / $results.codecoverage.NumberOfCommandsAnalyzed
if ($results.TotalCount -gt 0) {
$CodeCoveragePercent = $results.TotalCount * ($results.PassedCount / 100)
$codeCoverage = [math]::Round($CodeCoveragePercent,2)

if($codeCoverage -lt $requiredPercent)
{
Write-Error ("Failed Code Coverage [{0:P}] below {1:P}" -f $codeCoverage,$requiredPercent)
if ($codeCoverage -lt [Math]::Round($requiredPercent,2)) {
Write-Error ("Failed Code Coverage [{0:P}] below {1:P}" -f $codeCoverage, $requiredPercent)
}
}
} elseif ($results.FailedCount -gt 0) {
Write-Error -Message "Failed [$($results.FailedCount)] Pester tests."
}
}
4 changes: 2 additions & 2 deletions BuildTasks/SetVersion.Task.ps1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function GetModulePublicInterfaceMap
{
param($Path)
$module = ImportModule -Path $Path -PassThru
$module = Import-BuildModule -Path $Path -PassThru
$exportedCommands = @(
$module.ExportedFunctions.values
$module.ExportedCmdlets.values
Expand Down 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
2 changes: 1 addition & 1 deletion Docs/en-US/Add-SnowSqlRoleMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Add users to role

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Add-SnowSqlRoleMember -Role TEST_ROLE -Name TEST_USER
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/Disable-SnowSqlUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Disable user account

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Disable-SnowSqlUser -Name TEST_USER
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/Enable-SnowSqlUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Enable user account

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Enable-SnowSqlUser -Name TEST_USER
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/Get-SnowSqlConnection.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gets the current Snowflake connection

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Get-SnowSqlConnection
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/Get-SnowSqlRole.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Get list of Snowflake roles

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Get-SnowSqlRole
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/Get-SnowSqlRoleMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gets the members of the Snowflake role

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Get-SnowSqlRoleMember
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/Get-SnowSqlUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Get list of Snowflake users

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Get-SnowSqlUser
```
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
2 changes: 1 addition & 1 deletion Docs/en-US/New-SnowSqlRole.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Create a new Snowflake role

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
New-SnowSqlRole -Role TEST_ROLE
```
Expand Down
2 changes: 1 addition & 1 deletion Docs/en-US/New-SnowSqlUser.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Create a new Snowflake user account

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
New-SnowSqlUser -Name TESTUSER -LoginName TESTUSER@CONTOSO.COM -Description 'AD Account'
```
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
2 changes: 1 addition & 1 deletion Docs/en-US/Remove-SnowSqlRoleMember.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Remove Snowflake user from role

## EXAMPLES

### EXAMPLE 1
### EXEMPLE 1
```
Remove-SnowSqlRoleMember -Role TEST_ROLE -Name TEST_USER
```
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}
10 changes: 5 additions & 5 deletions ScriptAnalyzerSettings.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# subset of: Error, Warning and Information.
# Uncomment the following line if you only want Errors and Warnings but
# not Information diagnostic records.
Severity = @('Error','Warning')
#Severity = @('Error','Warning')

# Use IncludeRules when you want to run only a subset of the default rule set.
#IncludeRules = @('PSAvoidDefaultValueSwitchParameter',
Expand All @@ -18,17 +18,17 @@
# Use ExcludeRules when you want to run most of the default set of rules except
# for a few rules you wish to "exclude". Note: if a rule is in both IncludeRules
# and ExcludeRules, the rule will be excluded.
ExcludeRules = @('PSUseToExportFieldsInManifest','PSMissingModuleManifestField')
ExcludeRules = @('PSMissingModuleManifestField')

# You can use the following entry to supply parameters to rules that take parameters.
# For instance, the PSAvoidUsingCmdletAliases rule takes a whitelist for aliases you
# want to allow.
Rules = @{
#Rules = @{
# Do not flag 'cd' alias.
PSAvoidUsingCmdletAliases = @{Whitelist = @('Where','Select')}
# PSAvoidUsingCmdletAliases = @{Whitelist = @('Where','Select')}

# Check if your script uses cmdlets that are compatible on PowerShell Core,
# version 6.0.0-alpha, on Linux.
# PSUseCompatibleCmdlets = @{Compatibility = @("core-6.0.0-alpha-linux")}
}
#}
}
2 changes: 1 addition & 1 deletion SnowSQL/SnowSQL.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'SnowSQL.psm1'

# Version number of this module.
ModuleVersion = '0.1.1'
ModuleVersion = '0.1.3'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
Loading