-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'update-testing-2' into 'main'
Localize Warnings and Expand Testing See merge request wmarshall/SecretManagement.Warden!18
- Loading branch information
Showing
33 changed files
with
881 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
SecretManagement.Warden.Extension/SecretManagement.Warden.Extension.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
SecretManagement.Warden.Extension/private/Test-CLIVersion.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<# | ||
.SYNOPSIS | ||
Checks Bitwarden CLI version against blacklist. | ||
.DESCRIPTION | ||
Long description | ||
.EXAMPLE | ||
An example | ||
.NOTES | ||
General notes | ||
#> | ||
function Test-CLIVersion { | ||
[CmdletBinding()] | ||
Param( | ||
# CommandInfo of the Bitwarden CLI. Returned from Get-Command or dehydrated from Import-CliXml. | ||
[Parameter(Mandatory = $true)] | ||
[ValidateNotNullOrEmpty()] | ||
[ValidateScript({ | ||
if($_.PSTypeNames -match '^(?:Deserialized\.)?System\.Management\.Automation\.CommandInfo$') | ||
{ return $true } | ||
else { throw "Cannot convert the `"$_`" value of type `"$iptType`" to type `"System.Management.Automation.ApplicationInfo`"." } | ||
})] | ||
[PSObject]$BitwardenCLI, | ||
# Minimum Supported Version of the Bitwarden CLI. | ||
[ValidateNotNullOrEmpty()] | ||
[Version]$MinSupportedVersion = '2022.8.0' | ||
) | ||
|
||
#region Get CLI Version | ||
# Get the Version number from file metadata if possible. | ||
[Version]$CurrentVersion = $BitwardenCLI.Version | ||
|
||
# ?Find the version elsewhere if the file version would fail the test. Workaround for how the file version is not always the cli version. | ||
if( $CurrentVersion -lt $MinSupportedVersion ) { | ||
# Handle the various shims | ||
# ?The Brew CLI is rather fast so we use it to get version number | ||
$HomebrewPrefix = $env:HOMEBREW_PREFIX ?? "/home/linuxbrew/.linuxbrew" | ||
if ( $BitwardenCLI.Source -eq "$HomebrewPrefix/bin/bw" -and (Get-Command brew -ErrorAction Ignore)) | ||
{ | ||
$CurrentVersion = ((brew list bitwarden-cli --versions) -split ' ')[1] | ||
} | ||
# ?The Chocolatey CLI is very slow, so we prefer querying bw directly if needed. | ||
# if ( $BitwardenCLI.Source -eq (Join-Path $env:ProgramData "chocolatey" "bin" "bw.exe") ` | ||
# -and (Get-Command choco -ErrorAction Ignore)) | ||
# { | ||
# $CurrentVersion = (choco info bitwarden-cli --local-only --limit-output).Split("|")[1] | ||
# } | ||
# ?npm creates a ps1 shim that is stripped of all version info. The CLI is fast though. | ||
elseif ( $BitwardenCLI.Name -eq "bw.ps1" -and (Get-Command npm -ErrorAction Ignore)) { | ||
$CurrentVersion = (npm view -g @bitwarden/cli version) | ||
} | ||
# ?Scoop shims eliminate version numbers, so we ask scoop for the true version. | ||
elseif( $BitwardenCLI.Source -like "*\scoop\shims\bw.exe" -and (Get-Command scoop -ErrorAction Ignore)) { | ||
$CurrentVersion = (scoop list bitwarden-cli 6> $null).Version ?? $CurrentVersion | ||
} | ||
# ?Getting the version from snap is very fast, so ask it for that. | ||
elseif( $BitwardenCLI.Source -like "*/snapd/snap/bin/bw" -and (Get-Command snap -ErrorAction Ignore) ) { | ||
# Query snap for a list containing only the bw command. | ||
$snapVerChk = snap list bw | ||
# Get the position of the Version Header and treat that as the startPos | ||
$startPos = ($snapVerChk | Select-String Version).Matches[0].Index | ||
# Get the position of the first space after startPos on line 2 | ||
$endPos = $snapVerChk[1].Substring($startPos).IndexOf(' ') | ||
# The version is the text between the startPos and endPos on line 2. | ||
$CurrentVersion = $snapVerChk[1].Substring($startPos, $endPos) ?? $CurrentVersion | ||
} | ||
# ?WinGet shims have the wrong version, and the winget CLI is slow. Disabled in favor of querying bw.exe instead. | ||
# elseif( $BitwardenCLI.Source -like "*\WinGet\Links\bw.exe" -or <# Machine Scope #> | ||
# $BitwardenCLI.Source -like "*\Winget\Packages\*\bw.exe" <# User Scope #>) { | ||
# $wingetVerChk = winget list --id Bitwarden.CLI | ||
# $startPos = ($wingetVerChk | Select-String Version).Matches[0].Index | ||
# $endPos = ($wingetVerChk | Where-Object {![String]::IsNullOrWhiteSpace($_) -and $_.Length -gt $startPos})[2].Substring($startPos).IndexOf(' ') | ||
# $CurrentVersion = $snapVerChk[1].Substring($startPos, $endPos) ?? $CurrentVersion | ||
# } | ||
# ?If all other methods fail, ask bw.exe what version it is. This is a surprisingly slow process. | ||
else { | ||
$CurrentVersion = (.$BitwardenCLI --version) ?? $CurrentVersion | ||
} | ||
} | ||
#endregion Get CLI Version | ||
|
||
|
||
#region Version Warnings | ||
# Default Warning Message templates. Will be used if a localized variant cannot be found in the localization subdirectory. | ||
#culture="en-US" | ||
$Warnings = DATA {@{ | ||
WarnOutdated = "Your bitwarden-cli is version {0} and is out of date. Please upgrade to at least version {1}." | ||
WarnSpecificVersion = "Your bitwarden-cli is version {0}. This version of the CLI has a known issue affecting [{1}], which is used by [{2}]." | ||
WarnVersionRange = "Your bitwarden-cli is version {0}. Versions {1} – {2} of the CLI have a known issue affecting [{3}], which is used by [{4}]." | ||
See = "See: {0}." | ||
StrongAction = "It is `e[3mstrongly`e[23m recommended that you move to another version." | ||
}} | ||
Import-LocalizedData -BindingVariable Warnings -BaseDirectory (Join-Path $PSScriptRoot "localization") -ErrorAction Ignore | ||
|
||
if ( $CurrentVersion -lt $MinSupportedVersion ) { | ||
Write-Warning ($Warnings.WarnOutdated -f $CurrentVersion, $MinSupportedVersion) | ||
} | ||
elseif ( $CurrentVersion -ge '2023.12.0' -and $CurrentVersion -le '2023.12.1' ) { | ||
$warn = "{0} {1} {2}" -f ($Warnings.WarnVersionRange -f $CurrentVersion, '2023.12.0', '2023.12.1', 'bw list', 'Test-SecretVault'), | ||
($Warnings.See -f 'https://github.com/bitwarden/clients/issues/7126'), | ||
$Warnings.StrongAction | ||
Write-Warning $warn | ||
} | ||
elseif ( $CurrentVersion -ge '2024.6.1' -and $CurrentVersion -le '2024.7.1' ) { | ||
$warn = "{0} {1} {2}" -f ($Warnings.WarnVersionRange -f $CurrentVersion, '2024.6.1', '2024.7.1', 'bw unlock', 'Unlock-SecretVault'), | ||
($Warnings.See -f 'https://github.com/bitwarden/clients/issues/9919'), | ||
$Warnings.StrongAction | ||
Write-Warning $warn | ||
} | ||
#endregion Version Warnings | ||
} |
19 changes: 19 additions & 0 deletions
19
SecretManagement.Warden.Extension/private/localization/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# README | ||
|
||
Directory serving as the BaseDirectory for using [`Import-LocalizedData`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-localizeddata) in private functions. As such, directory layout and filenames are goverened by the requirements of that function | ||
|
||
In short: all directory names should either be a language code or a language-country code, i.e., `de` (German) or `ar-SA` (Saudi Arabian Arabic). Within each directory, localizations for a particular file are stored in `.psd1` of the same name. | ||
|
||
## Example Directory Layout | ||
|
||
``` | ||
└── Test-Function.ps1 | ||
└── localization | ||
├── de | ||
│ └── Test-Function.psd1 | ||
└── ar-SA | ||
└── Test-Function.psd1 | ||
``` | ||
|
||
## See Also | ||
For more details, refer to PowerShell documentation, specifically [about_Script_Internationalization](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_script_internationalization) and [Import-LocalizedData](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/import-localizeddata). |
8 changes: 8 additions & 0 deletions
8
SecretManagement.Warden.Extension/private/localization/cs/Test-CLIVersion.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Czech | ||
@{ | ||
WarnOutdated = "Váš bitwarden-cli má verzi {0} a je zastaralý. Upgradujte prosím alespoň na verzi {1}." | ||
WarnSpecificVersion = "Váš bitwarden-cli je verze {0}. Tato verze CLI má známý problém, který ovlivňuje [{1}], které používá [{2}]." | ||
WarnVersionRange = "Váš bitwarden-cli je verze {0}. Verze {1} - {2} CLI má známý problém, který ovlivňuje [{3}], které používá [{4}]." | ||
See = "Viz: {0}." | ||
StrongAction = "`e[3mDůrazně`e[23m doporučujeme přejít na jinou verzi." | ||
} |
8 changes: 8 additions & 0 deletions
8
SecretManagement.Warden.Extension/private/localization/de/Test-CLIVersion.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# German | ||
@{ | ||
WarnOutdated = "Ihr bitwarden-cli hat die Version {0} und ist veraltet. Bitte aktualisieren Sie mindestens auf Version {1}." | ||
WarnSpecificVersion = "Ihr bitwarden-cli hat die Version {0}. Diese Version der CLI hat ein bekanntes Problem, das [{1}] betrifft, das von [{2}] verwendet wird." | ||
WarnVersionRange = "Ihr bitwarden-cli hat die Version {0}. Die Versionen {0} - {1} der CLI haben ein bekanntes Problem, das [{2}] betrifft, das von [{3}] verwendet wird." | ||
See = "Siehe: {0}." | ||
StrongAction = "Es wird `e[3mdringend`e[23m empfohlen, zu einer anderen Version zu wechseln." | ||
} |
8 changes: 8 additions & 0 deletions
8
SecretManagement.Warden.Extension/private/localization/el/Test-CLIVersion.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Greek | ||
@{ | ||
WarnOutdated = "Το bitwarden-cli σας έχει την έκδοση {0} και είναι ξεπερασμένο. Παρακαλούμε αναβαθμίστε τουλάχιστον στην έκδοση {1}." | ||
WarnSpecificVersion = "Το bitwarden-cli σας έχει την έκδοση {0}. Αυτή η έκδοση του CLI έχει ένα γνωστό πρόβλημα που επηρεάζει το [{1}], το οποίο χρησιμοποιείται από το [{2}]." | ||
WarnVersionRange = "Το bitwarden-cli σας έχει την έκδοση {0}. Οι εκδόσεις {0} - {1} του CLI έχουν ένα γνωστό πρόβλημα που επηρεάζει το [{2}], το οποίο χρησιμοποιείται από το [{3}]." | ||
See = "Βλέπε: {0}." | ||
StrongAction = "Συνιστάται `e[3mέντονα`e[23m η μετάβαση σε άλλη έκδοση." | ||
} |
8 changes: 8 additions & 0 deletions
8
SecretManagement.Warden.Extension/private/localization/es/Test-CLIVersion.psd1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Spanish | ||
@{ | ||
WarnOutdated = "Su bitwarden-cli es la versión {0} y está desactualizada. Por favor, actualice al menos a la versión {1}." | ||
WarnSpecificVersion = "Su bitwarden-cli es la versión {0}. Esta versión de la CLI tiene un problema conocido que afecta a [{1}], que es utilizado por [{2}]." | ||
WarnVersionRange = "Su bitwarden-cli es la versión {0}. Las versiones {0} - {1} del CLI tienen un problema conocido que afecta a [{2}], que es utilizado por [{3}]." | ||
See = "Mira: {0}." | ||
StrongAction = "Se recomienda `e[3mencarecidamente`e[23m pasar a otra versión." | ||
} |
Oops, something went wrong.