80 lines
2.6 KiB
C#
80 lines
2.6 KiB
C#
using System;
|
|
using System.ComponentModel;
|
|
using System.Threading.Tasks;
|
|
using BTCPayServerDockerConfigurator.Models;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace BTCPayServerDockerConfigurator.Controllers
|
|
{
|
|
public partial class ConfiguratorController
|
|
{
|
|
[HttpPost("deploy")]
|
|
public async Task<IActionResult> Deploy()
|
|
{
|
|
var model = GetConfiguratorSettings();
|
|
var bash = model.ConstructBashFile(null);
|
|
var oneliner = bash
|
|
.Replace("\r\n", "\n")
|
|
.Replace("\n", " &&\n");
|
|
|
|
if (model.DeploymentSettings.DeploymentType == DeploymentType.Manual)
|
|
{
|
|
return View(new UpdateSettings<ConfiguratorSettings, DeployAdditionalData>()
|
|
{
|
|
Additional = new DeployAdditionalData()
|
|
{
|
|
Bash = oneliner
|
|
},
|
|
Json = model.ToString(),
|
|
Settings = model
|
|
});
|
|
}
|
|
SSHSettings ssh = null;;
|
|
switch (model.DeploymentSettings.DeploymentType)
|
|
{
|
|
case DeploymentType.RemoteMachine when ModelState.IsValid:
|
|
{
|
|
ssh = new SSHSettings()
|
|
{
|
|
Password = model.DeploymentSettings.Password,
|
|
Server = model.DeploymentSettings.Host,
|
|
Username = model.DeploymentSettings.Username
|
|
};
|
|
break;
|
|
}
|
|
case DeploymentType.ThisMachine when ModelState.IsValid:
|
|
{
|
|
ssh = _options.Value.ParseSSHConfiguration();
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (ssh == null)
|
|
{
|
|
throw new Exception("lolita bonita");
|
|
}
|
|
|
|
var connection = await ssh.ConnectAsync();
|
|
var result = await connection.RunBash(oneliner);
|
|
return View(new UpdateSettings<ConfiguratorSettings, DeployAdditionalData>()
|
|
{
|
|
Additional = new DeployAdditionalData()
|
|
{
|
|
Bash = oneliner,
|
|
Error = result.Error,
|
|
Output = result.Output,
|
|
ExitStatus = result.ExitStatus
|
|
},
|
|
Json = model.ToString(),
|
|
Settings = model
|
|
});
|
|
|
|
|
|
}
|
|
}
|
|
|
|
public class DeployAdditionalData: SSHClientExtensions.SSHCommandResult
|
|
{
|
|
public string Bash { get; set; }
|
|
}
|
|
} |