mirror of
https://github.com/openfaas/faas.git
synced 2025-06-16 21:06:54 +00:00
Generate user/pass for PowerShell deploy script
- Generates the password to mirror deploy_stack.sh - Uses hardcoded admin to mirror deploy_stack.sh - Uses throw to exit when error - Updates faas-cli login command for Powershell Signed-off-by: John McCabe <john@johnmccabe.net>
This commit is contained in:
parent
7d5955b6f2
commit
5d7776c951
@ -1,10 +1,23 @@
|
|||||||
#!ps1
|
#!ps1
|
||||||
|
|
||||||
|
param (
|
||||||
|
[switch] $noAuth,
|
||||||
|
[switch] $n
|
||||||
|
)
|
||||||
|
|
||||||
if (Get-Command docker -errorAction SilentlyContinue)
|
if (Get-Command docker -errorAction SilentlyContinue)
|
||||||
{
|
{
|
||||||
docker node ls 2>&1 | out-null
|
docker node ls 2>&1 | out-null
|
||||||
if($?)
|
if(-Not $?)
|
||||||
{
|
{
|
||||||
|
throw "Docker not in swarm mode, please initialise the cluster (`docker swarm init`) and retry"
|
||||||
|
}
|
||||||
|
|
||||||
|
Add-Type -AssemblyName System.Web
|
||||||
|
$secret = [System.Web.Security.Membership]::GeneratePassword(24,5)
|
||||||
|
$user = 'admin'
|
||||||
|
|
||||||
|
Write-Host "Attempting to create credentials for gateway.."
|
||||||
$user_secret = "basic-auth-user"
|
$user_secret = "basic-auth-user"
|
||||||
docker secret inspect $user_secret 2>&1 | out-null
|
docker secret inspect $user_secret 2>&1 | out-null
|
||||||
if($?)
|
if($?)
|
||||||
@ -13,7 +26,6 @@ if (Get-Command docker -errorAction SilentlyContinue)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$user = Read-Host 'Admin User?'
|
|
||||||
$user | docker secret create $user_secret -
|
$user | docker secret create $user_secret -
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,20 +37,30 @@ if (Get-Command docker -errorAction SilentlyContinue)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$pass = Read-Host 'Password?' -AsSecureString
|
$secret | docker secret create $password_secret -
|
||||||
[Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($pass)) | docker secret create $password_secret -
|
Write-Host "[Credentials]"
|
||||||
|
Write-Host " username: admin"
|
||||||
|
Write-Host " password: $secret"
|
||||||
|
Write-Host " Write-Output `"$secret`" | faas-cli login --username=$user --password-stdin"
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($noAuth -Or $n) {
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Disabling basic authentication for gateway.."
|
||||||
|
Write-Host ""
|
||||||
|
$env:BASIC_AUTH="false";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Write-Host ""
|
||||||
|
Write-Host "Enabling basic authentication for gateway.."
|
||||||
|
Write-Host ""
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Deploying stack"
|
Write-Host "Deploying stack"
|
||||||
docker stack deploy func --compose-file ./docker-compose.yml
|
docker stack deploy func --compose-file ./docker-compose.yml
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Write-Host "Docker not in swarm mode, please initialise the cluster (`docker swarm init`) and retry"
|
throw "Unable to find docker command, please install Docker (https://www.docker.com/) and retry"
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Write-Host "Unable to find docker command, please install Docker (https://www.docker.com/) and retry"
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user