From 1bd47f581e24d17b975920cf55d9ce9ad12499ff Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Thu, 24 Nov 2022 18:45:24 +0200 Subject: [PATCH] remove secrets from source code --- ...moxConnector.Integration.Corsinvest.csproj | 2 ++ .../Services/PveConnector.cs | 34 ++++++++++++++----- .../ProxmoxConnector.Server/appsettings.json | 9 ++++- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/integration/ProxmoxConnector.Integration.Corsinvest/ProxmoxConnector.Integration.Corsinvest.csproj b/src/integration/ProxmoxConnector.Integration.Corsinvest/ProxmoxConnector.Integration.Corsinvest.csproj index f7db579..af13a64 100644 --- a/src/integration/ProxmoxConnector.Integration.Corsinvest/ProxmoxConnector.Integration.Corsinvest.csproj +++ b/src/integration/ProxmoxConnector.Integration.Corsinvest/ProxmoxConnector.Integration.Corsinvest.csproj @@ -6,7 +6,9 @@ + + diff --git a/src/integration/ProxmoxConnector.Integration.Corsinvest/Services/PveConnector.cs b/src/integration/ProxmoxConnector.Integration.Corsinvest/Services/PveConnector.cs index d813c09..87c3c5e 100644 --- a/src/integration/ProxmoxConnector.Integration.Corsinvest/Services/PveConnector.cs +++ b/src/integration/ProxmoxConnector.Integration.Corsinvest/Services/PveConnector.cs @@ -1,4 +1,5 @@ using Corsinvest.ProxmoxVE.Api; +using Microsoft.Extensions.Configuration; using Newtonsoft.Json; using ProxmoxConnector.Integration.Abstractions; using System; @@ -8,11 +9,26 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services { internal class PveConnector : IPveConnector { + private readonly string _hostName; + private readonly int _port; + private readonly string _userName; + private readonly string _password; + private readonly string _token; + + public PveConnector(IConfiguration configuration) + { + var config = configuration.GetSection("Pve"); + _hostName = config["HostName"]; + _port = config.GetValue("Port"); + _userName = config["UserName"]; + _password = config["Password"]; + _token = config["Token"]; + } + public async Task TestWithLogin() { - //var client = new PveClient("***REMOVED***"); ***REMOVED*** ***REMOVED*** - var client = new PveClient("***REMOVED***"); ***REMOVED*** - if (await client.Login(***REMOVED***)) + var client = new PveClient(_hostName, _port); + if (await client.Login(_userName, _password)) { var vm = client.Nodes["pve-lora"].Qemu[100]; @@ -46,16 +62,16 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services public async Task TestWithToken() { //using Api Token - var client2 = new PveClient("***REMOVED***"); - client2.ApiToken = "root@pam!test-token=***REMOVED***"; + var client2 = new PveClient(_hostName, _port); + client2.ApiToken = _token; var version = await client2.Version.Version(); Console.WriteLine(JsonConvert.SerializeObject(version.Response.data, Formatting.Indented)); } public async Task Start() { - var client = new PveClient("***REMOVED***"); ***REMOVED*** - if (await client.Login(***REMOVED***)) + var client = new PveClient(_hostName, _port); + if (await client.Login(_userName, _password)) { var vm = client.Nodes["pve-lora"].Qemu[100]; @@ -68,8 +84,8 @@ namespace ProxmoxConnector.Integration.Corsinvest.Services public async Task Stop() { - var client = new PveClient("***REMOVED***"); ***REMOVED*** - if (await client.Login(***REMOVED***)) + var client = new PveClient(_hostName, _port); + if (await client.Login(_userName, _password)) { var vm = client.Nodes["pve-lora"].Qemu[100]; diff --git a/src/server/ProxmoxConnector.Server/appsettings.json b/src/server/ProxmoxConnector.Server/appsettings.json index cb8e87e..6bb2f8a 100644 --- a/src/server/ProxmoxConnector.Server/appsettings.json +++ b/src/server/ProxmoxConnector.Server/appsettings.json @@ -15,5 +15,12 @@ //"BaseAddress": "http://localhost:5063/" "BaseAddress": "https://toodle.ddns.net/identity-server-api/" }, - "Workspace": "Workspace" + "Workspace": "Workspace", + "Pve": { + "HostName": "127.0.0.1", + "Port": "8006", + "UserName": "user", + "Password": "pass", + "Token": "user@pam!test-token=76****-***-***-***-1*******5a" + } } \ No newline at end of file