Port triggers script to PowerShell so it can be run from Windows
This commit is contained in:
Родитель
1b709bb871
Коммит
115a5253c3
|
@ -28,6 +28,8 @@ Download this script with a testing version of the three required triggers:
|
|||
<https://github.com/perforce/helix-authentication-extension/blob/master/containers/p4d/mfa-trigger.sh>
|
||||
|
||||
Note: There is a custom version of this script in our local repo (NativeVersionControlPlugins/MFA) that actually works (specially for MacOs users)
|
||||
- mfa-trigger.sh > bash script fot MacOs and Linux
|
||||
- mfa-trigger.ps1 > powershell script for Windows
|
||||
|
||||
Then run:
|
||||
```
|
||||
|
|
|
@ -0,0 +1,176 @@
|
|||
#!/usr/bin/env pwsh -NoLogo -NonInteractive
|
||||
param (
|
||||
[Parameter(Mandatory=$true)][string]$t,
|
||||
[Parameter(Mandatory=$true)][string]$e,
|
||||
[Parameter(Mandatory=$true)][string]$u,
|
||||
[Parameter(Mandatory=$true)][string]$h,
|
||||
[string]$m,
|
||||
[string]$s,
|
||||
[string]$k,
|
||||
[switch]$d
|
||||
)
|
||||
|
||||
if ($d) {
|
||||
$DEBUG = $true
|
||||
}
|
||||
|
||||
$AUTH_TRIGGER=''
|
||||
$AUTH_EMAIL=''
|
||||
$AUTH_USER=''
|
||||
$AUTH_HOST=''
|
||||
$AUTH_METHOD=''
|
||||
$AUTH_SCHEME=''
|
||||
$AUTH_TOKEN=''
|
||||
|
||||
function Write-Stop {
|
||||
|
||||
param (
|
||||
$Message
|
||||
)
|
||||
|
||||
Write-Error -Message $Message exit
|
||||
}
|
||||
|
||||
function Write-Usage {
|
||||
Write-Output @"
|
||||
Usage:
|
||||
|
||||
mfa-trigger.sh [-t] [-e] [-d] ...
|
||||
|
||||
Description:
|
||||
|
||||
Test trigger playing with MFA and HAS on the same instance.
|
||||
|
||||
Most of these options are not implemented (yet).
|
||||
|
||||
-t <trigger>
|
||||
Trigger to run: pre-2fa, init-2fa, or check-2fa
|
||||
|
||||
-e <user-email>
|
||||
Email address of the Perforce user authenticating.
|
||||
|
||||
-u <user-name>
|
||||
Name of the Perforce user authenticating.
|
||||
|
||||
-h <host-addr>
|
||||
Host address of the client system.
|
||||
|
||||
-m <method>
|
||||
The authentication method from list-methods.
|
||||
|
||||
-s <scheme>
|
||||
The authentication scheme set by init-auth.
|
||||
|
||||
-k <token>
|
||||
The stashed token from the last init-auth.
|
||||
|
||||
-d
|
||||
Enable debugging output for this configuration script.
|
||||
|
||||
no-arguments
|
||||
Display this help message.
|
||||
"@
|
||||
}
|
||||
|
||||
function Start-Pre2fa {
|
||||
Write-Output @"
|
||||
{
|
||||
"status" : 0,
|
||||
"message" : "A message for the caller",
|
||||
"methodlist" : [
|
||||
[ "otp-generated", "A One-Time-Password generated by a user device" ],
|
||||
[ "challenge", "type something in response to a challenge" ],
|
||||
]
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
function Start-Pre2fa-NoAuth {
|
||||
Write-Output @"
|
||||
{
|
||||
"status":2,
|
||||
"message" : "Second factor authentication not required"
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
function Start-Init2fa {
|
||||
Write-Output @"
|
||||
{
|
||||
"status": 0,
|
||||
"scheme": "challenge",
|
||||
"message": "Please enter your response",
|
||||
"challenge": "ABBACD",
|
||||
"token": "REQID:20003339189"
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
function Start-Check2fa {
|
||||
Write-Output @"
|
||||
{
|
||||
"status": 0
|
||||
}
|
||||
"@
|
||||
}
|
||||
|
||||
function main {
|
||||
|
||||
param (
|
||||
[string]$trigger,
|
||||
[string]$email,
|
||||
[string]$user,
|
||||
[string]$port,
|
||||
[string]$method,
|
||||
[string]$scheme,
|
||||
[string]$token
|
||||
)
|
||||
|
||||
$AUTH_TRIGGER = $trigger
|
||||
$AUTH_EMAIL = $email
|
||||
$AUTH_USER = $user
|
||||
$AUTH_HOST = $port
|
||||
if ($m) {
|
||||
$AUTH_METHOD = $method
|
||||
}
|
||||
if ($s) {
|
||||
$AUTH_SCHEME = $scheme
|
||||
}
|
||||
if ($k) {
|
||||
$AUTH_TOKEN = $token
|
||||
}
|
||||
|
||||
if ($DEBUG) {
|
||||
Write-Output @"
|
||||
AUTH_TRIGGER : $AUTH_TRIGGER
|
||||
AUTH_EMAIL : $AUTH_EMAIL
|
||||
AUTH_USER : $AUTH_USER
|
||||
AUTH_HOST : $AUTH_HOST
|
||||
AUTH_METHOD : $AUTH_METHOD
|
||||
AUTH_SCHEME : $AUTH_SCHEME
|
||||
AUTH_TOKEN : $AUTH_TOKEN
|
||||
"@
|
||||
}
|
||||
|
||||
if ( $AUTH_TRIGGER -eq 'pre-2fa' ) {
|
||||
if ( $AUTH_USER -eq 'noauth' ) {
|
||||
Start-Pre2fa-NoAuth
|
||||
}
|
||||
else {
|
||||
Start-Pre2fa
|
||||
}
|
||||
}
|
||||
elseif ( $AUTH_TRIGGER -eq 'init-2fa') {
|
||||
Start-Init2fa
|
||||
}
|
||||
elseif ( $AUTH_TRIGGER -eq 'check-2fa') {
|
||||
Start-Check2fa
|
||||
}
|
||||
else {
|
||||
Write-Usage
|
||||
exit 1
|
||||
}
|
||||
exit 0
|
||||
}
|
||||
|
||||
main $t $e $u $h $m $s $k
|
|
@ -306,6 +306,7 @@ sub SetupMFATriggers
|
|||
my $mfa_script = getcwd() . "/MFA/mfa-trigger.sh";
|
||||
if ($ENV{'TARGET'} eq "win32")
|
||||
{
|
||||
$mfa_script = "PowerShell " . getcwd() . "/MFA/mfa-trigger.ps1";
|
||||
$mfa_script =~ s/\//\\/g;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче