diff --git a/.vscode/cSpell.json b/.vscode/cSpell.json new file mode 100644 index 0000000..ed2510a --- /dev/null +++ b/.vscode/cSpell.json @@ -0,0 +1,39 @@ +// cSpell Settings +{ + // Version of the setting file. Always 0.1 + "version": "0.1", + // language - current active spelling language + "language": "en", + // words - list of words to be always considered correct + "words": [ + "Ponduit", + "NTFS", + "Repo", + "Hashtable", + "googlemail", + "Cmdlet", + "appveyor", + "GUID", + "wildcards", + "Cmdlets", + "codecoverage", + "notmatch", + "Httpclient", + "Multipart", + "formdata", + "callsign", + "Veyor", + "notlike", + "Params", + "testresults", + "powershellgallery", + "chocolatey", + "choco" + ], + // flagWords - list of words to be always considered incorrect + // This is useful for offensive words and common spelling errors. + // For example "hte" should be "the" + "flagWords": [ + "hte" + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..05e9a14 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,50 @@ +// Place your settings in this file to overwrite default and user settings. +{ + // Set basic file related options: + "files.encoding": "utf8", + "files.eol": "\r\n", + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + // Formation and editor options + "editor.renderWhitespace": "boundary", + "editor.formatOnSave": true, + "editor.formatOnType": true, + "editor.rulers": [ + 116 + ], + // powershell general + "powershell.startAutomatically": true, + "powershell.useX86Host": false, + "powershell.enableProfileLoading": true, + "powershell.scriptAnalysis.enable": true, + // powershell code Formatting + "powershell.codeFormatting.openBraceOnSameLine": true, + "powershell.codeFormatting.newLineAfterOpenBrace": true, + "powershell.codeFormatting.newLineAfterCloseBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenBrace": true, + "powershell.codeFormatting.whitespaceBeforeOpenParen": true, + "powershell.codeFormatting.whitespaceAroundOperator": true, + "powershell.codeFormatting.whitespaceAfterSeparator": true, + "powershell.codeFormatting.ignoreOneLineBlock": true, + "powershell.codeFormatting.alignPropertyValuePairs": false, + // cspell spellchecker options + "cSpell.enabledLanguageIds": [ + "c", + "cpp", + "csharp", + "go", + "javascript", + "javascriptreact", + "json", + "latex", + "markdown", + "php", + "plaintext", + "powershell", + "python", + "text", + "typescript", + "typescriptreact", + "yml" + ] +} diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..4b42772 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,54 @@ +version: 0.1.{build} + +branches: + only: + - master + - dev + - debug + +skip_tags: true + +#image: WMF 5 +# Test ne build image: +image: Visual Studio 2017 + +# Install pester module and init the Appveyor support. +install: + - ps: Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose + - ps: Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force +# - ps: Install-Module -Name 'Pester' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber +# - ps: Update-Module 'Pester' +# - ps: Install-Module -Name 'posh-git' -Scope CurrentUser -Force -SkipPublisherCheck -AllowClobber +# - ps: Update-Module 'posh-git' + - ps: Import-Module .\tools\AppVeyor.psm1 + +environment: + NuGetToken: + secure: 835qfZIkC9mE7QhkYfOZVAdR8rZhPvxG8BO4CbeaelRQOhlqmaSr8G1DWRJzZ/bS + CoverallsToken: + secure: eTjWqHL48MBr8wp1rSgLrXHdtpfDV/uClacP3svlWJfCvn/zVokpuaMnWM5RoyIY + +build: false + +before_build: + - ps: Invoke-AppVeyorBumpVersion + +build_script: + - ps: Invoke-AppVeyorBuild + +test_script: + - ps: Invoke-AppVeyorTests + - ps: Invoke-CoverageReport + +deploy: + - provider: GitHub + auth_token: + secure: M+bBX5/nKdJB0eViP7xtrLVTwf3vGDUA9N2MMprZp2i+9ZR3CBVcJnSzJWUmalhB + artifact: PSCredentialStore.zip # upload all NuGet packages to release assets + draft: false + prerelease: false + on: + branch: master # release from master branch only + +after_deploy: + - ps: Invoke-AppVeyorPSGallery diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000..7756187 --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1 @@ +This is a placeholder file. The build Server will create all bin files here. diff --git a/resources/.gitignore b/resources/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/resources/cs/Broken_CS.json b/resources/cs/Broken_CS.json new file mode 100644 index 0000000..23e8eee --- /dev/null +++ b/resources/cs/Broken_CS.json @@ -0,0 +1,3 @@ +{ + "Version": "1.2.0", + "Creation": "2016-06-14 08:41:10" diff --git a/resources/cs/Challenge.bin b/resources/cs/Challenge.bin new file mode 100644 index 0000000..3b80551 --- /dev/null +++ b/resources/cs/Challenge.bin @@ -0,0 +1 @@ +!pH4"=wS2 \ No newline at end of file diff --git a/resources/cs/CredentialStore.json b/resources/cs/CredentialStore.json new file mode 100644 index 0000000..4d45b38 Binary files /dev/null and b/resources/cs/CredentialStore.json differ diff --git a/src/PSCredentialStore.psd1 b/src/PSCredentialStore.psd1 new file mode 100644 index 0000000..8900b1b --- /dev/null +++ b/src/PSCredentialStore.psd1 @@ -0,0 +1,123 @@ +# +# Module manifest for module 'PSCredentialStore' +# +# Generated by: OCram85 +# +# Generated on: 27.07.2017 +# + +@{ + + # Script module or binary module file associated with this manifest. + # RootModule = '' + + # Version number of this module. + ModuleVersion = '1.0' + + # Supported PSEditions + # CompatiblePSEditions = @() + + # ID used to uniquely identify this module + GUID = '6800e192-9df8-4e30-b253-eb2c799bbe84' + + # Author of this module + Author = 'OCram85' + + # Company or vendor of this module + CompanyName = 'Unknown' + + # Copyright statement for this module + Copyright = '(c) 2017 OCram85. All rights reserved.' + + # Description of the functionality provided by this module + # Description = '' + + # Minimum version of the Windows PowerShell engine required by this module + # PowerShellVersion = '' + + # Name of the Windows PowerShell host required by this module + # PowerShellHostName = '' + + # Minimum version of the Windows PowerShell host required by this module + # PowerShellHostVersion = '' + + # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # DotNetFrameworkVersion = '' + + # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. + # CLRVersion = '' + + # Processor architecture (None, X86, Amd64) required by this module + # ProcessorArchitecture = '' + + # Modules that must be imported into the global environment prior to importing this module + # RequiredModules = @() + + # Assemblies that must be loaded prior to importing this module + # RequiredAssemblies = @() + + # Script files (.ps1) that are run in the caller's environment prior to importing this module. + # ScriptsToProcess = @() + + # Type files (.ps1xml) to be loaded when importing this module + # TypesToProcess = @() + + # Format files (.ps1xml) to be loaded when importing this module + # FormatsToProcess = @() + + # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess + # NestedModules = @() + + # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. + FunctionsToExport = @() + + # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. + CmdletsToExport = @() + + # Variables to export from this module + VariablesToExport = '*' + + # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. + AliasesToExport = @() + + # DSC resources to export from this module + # DscResourcesToExport = @() + + # List of all modules packaged with this module + # ModuleList = @() + + # List of all files packaged with this module + # FileList = @() + + # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. + PrivateData = @{ + + PSData = @{ + + # Tags applied to this module. These help with module discovery in online galleries. + # Tags = @() + + # A URL to the license for this module. + # LicenseUri = '' + + # A URL to the main website for this project. + # ProjectUri = '' + + # A URL to an icon representing this module. + # IconUri = '' + + # ReleaseNotes of this module + # ReleaseNotes = '' + + } # End of PSData hashtable + + } # End of PrivateData hashtable + + # HelpInfo URI of this module + # HelpInfoURI = '' + + # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. + # DefaultCommandPrefix = '' + +} + diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/tools/AppVeyor.psm1 b/tools/AppVeyor.psm1 new file mode 100644 index 0000000..4026add --- /dev/null +++ b/tools/AppVeyor.psm1 @@ -0,0 +1,178 @@ +<# + Define the callsign of you PowerShell Module. + Callsign is used to identity: + - Module Manifest file name + - Artifact File + - Git repository name + - Module name +#> +$CALLSIGN = 'PSCoverage' +Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Yellow + +Function Invoke-AppVeyorBumpVersion() { + [CmdletBinding()] + Param() + + Write-Host "Listing Env Vars for debugging:" -ForegroundColor Yellow + # Filter Results to prevent exposing secure vars. + Get-ChildItem -Path "Env:*" | Where-Object { $_.name -notmatch "(NuGetToken|CoverallsToken)"} | Sort-Object -Property Name | Format-Table + + Try { + $ModManifest = Get-Content -Path (".\src\{0}.psd1" -f $CALLSIGN) + $BumpedManifest = $ModManifest -replace '\$Env:APPVEYOR_BUILD_VERSION', "'$Env:APPVEYOR_BUILD_VERSION'" + Remove-Item -Path (".\src\{0}.psd1" -f $CALLSIGN) + Out-File -FilePath (".\src\{0}.psd1" -f $CALLSIGN) -InputObject $BumpedManifest -NoClobber -Encoding utf8 -Force + } + Catch { + $MsgParams = @{ + Message = 'Could not bump current version into module manifest.' + Category = 'Error' + Details = $_.Exception.Message + } + Add-AppveyorMessage @MsgParams + Throw $MsgParams.Message + } +} + +Function Invoke-AppVeyorBuild() { + [CmdletBinding()] + Param() + $MsgParams = @{ + Message = 'Creating build artifacts' + Category = 'Information' + Details = 'Extracting source files and compressing them into zip file.' + } + Add-AppveyorMessage @MsgParams + $CompParams = @{ + Path = "{0}\src\*" -f $env:APPVEYOR_BUILD_FOLDER + DestinationPath = "{0}\bin\{1}.zip" -f $env:APPVEYOR_BUILD_FOLDER, $CALLSIGN + Update = $True + Verbose = $True + } + Compress-Archive @CompParams + $MsgParams = @{ + Message = 'Pushing artifacts' + Category = 'Information' + Details = 'Pushing artifacts to AppVeyor store.' + } + Add-AppveyorMessage @MsgParams + Push-AppveyorArtifact (".\bin\{0}.zip" -f $CALLSIGN) +} + +Function Invoke-AppVeyorTests() { + [CmdletBinding()] + Param() + + $MsgParams = @{ + Message = 'Starting Pester tests' + Category = 'Information' + Details = 'Now running all test found in .\tests\ dir.' + } + Add-AppveyorMessage @MsgParams + $testresults = Invoke-Pester -Path ".\tests\*" -ExcludeTag 'Disabled' -PassThru + ForEach ($Item in $testresults.TestResult) { + Switch ($Item.Result) { + "Passed" { + $TestParams = @{ + Name = "{0}: {1}" -f $Item.Context, $Item.Name + Framework = "NUnit" + Filename = $Item.Describe + Outcome = "Passed" + Duration = $Item.Time.Milliseconds + } + Add-AppveyorTest @TestParams + } + "Failed" { + $TestParams = @{ + Name = "{0}: {1}" -f $Item.Context, $Item.Name + Framework = "NUnit" + Filename = $Item.Describe + Outcome = "Failed" + Duration = $Item.Time.Milliseconds + ErrorMessage = $Item.FailureMessage + ErrorStackTrace = $Item.StackTrace + } + Add-AppveyorTest @TestParams + } + Default { + $TestParams = @{ + Name = "{0}: {1}" -f $Item.Context, $Item.Name + Framework = "NUnit" + Filename = $Item.Describe + Outcome = "None" + Duration = $Item.Time.Milliseconds + ErrorMessage = $Item.FailureMessage + ErrorStackTrace = $Item.StackTrace + } + Add-AppveyorTest @TestParams + } + } + } + If ($testresults.FailedCount -gt 0) { + $MsgParams = @{ + Message = 'Pester Tests failed.' + Category = 'Error' + Details = "$($testresults.FailedCount) tests failed." + } + Add-AppveyorMessage @MsgParams + Throw $MsgParams.Message + } + +} + +Function Invoke-CoverageReport() { + [CmdletBinding()] + Param( + [Parameter(Mandatory = $False)] + [ValidateNotNullOrEmpty()] + [String]$RepoToken = $Env:CoverallsToken + ) + + Import-Module '.\src\PSCoverage.psm1' -Verbose -Force + $FileMap = New-PesterFileMap -SourceRoot '.\src' -PesterRoot '.\tests' + $CoverageReport = New-CoverageReport -PesterFileMap $FileMap -RepoToken $RepoToken + Write-Host "CoverageReport JSON:" -ForegroundColor Yellow + $CoverageReport | Out-String | Write-Host + Publish-CoverageReport -CoverageReport $CoverageReport +} + +Function Invoke-AppVeyorPSGallery() { + [CmdletBinding()] + Param() + Expand-Archive -Path (".\bin\{0}.zip" -f $CALLSIGN) -DestinationPath ("C:\Users\appveyor\Documents\WindowsPowerShell\Modules\{0}\" -f $CALLSIGN) -Verbose + Import-Module -Name $CALLSIGN -Verbose -Force + Write-Host "Available Package Provider:" -ForegroundColor Yellow + Get-PackageProvider -ListAvailable + Write-Host "Available Package Sources:" -ForegroundColor Yellow + Get-PackageSource + Try { + Write-Host "Try to get NuGet Provider:" -ForegroundColor Yellow + Get-PackageProvider -Name NuGet -ErrorAction Stop + } + Catch { + Write-Host "Installing NuGet..." -ForegroundColor Yellow + Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force -Verbose + Import-PackageProvider NuGet -MinimumVersion '2.8.5.201' -Force + } + Try { + If ($env:APPVEYOR_REPO_BRANCH -eq 'master') { + Write-Host "try to publish module" -ForegroundColor Yellow + Write-Host ("Callsign is: {0}" -f $CALLSIGN) -ForegroundColor Yellow + Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -Force + } + Else { + Write-Host "Skip publishing to PS Gallery because we are on $($env:APPVEYOR_REPO_BRANCH) branch." -ForegroundColor Yellow + # had to remove the publish-Module statement because it would publish although the -WhatIf is given. + # Publish-Module -Name $CALLSIGN -NuGetApiKey $env:NuGetToken -Verbose -WhatIf + } + } + Catch { + $MsgParams = @{ + Message = 'Could not deploy module to PSGallery.' + Category = 'Error' + Details = $_.Exception.Message + } + Add-AppveyorMessage @MsgParams + Throw $MsgParams.Message + } +}