Skip to content

Commit

Permalink
Fix Api Token usage
Browse files Browse the repository at this point in the history
  • Loading branch information
franklupo committed Jul 31, 2020
1 parent 3416112 commit 23b6070
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/Corsinvest.ProxmoxVE.TelegramBot.Api/BotManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,22 @@ public class BotManager
/// Constructor
/// </summary>
/// <param name="pveHostandPortHA">Proxmox VE host and port HA format 10.1.1.90:8006,10.1.1.91:8006,10.1.1.92:8006</param>
/// <param name="pveApiToken">Proxmox VE Api Token</param>
/// <param name="pveUsername">Proxmox VE username</param>
/// <param name="pvePassword">Proxmox VE password</param>
/// <param name="token">Token Telegram Bot</param>
/// <param name="chatsIdValid">Valid chats Id</param>
/// <param name="out">Output write</param>
public BotManager(string pveHostandPortHA,
string pveApiToken,
string pveUsername,
string pvePassword,
string token,
long[] chatsIdValid,
TextWriter @out)
{
PveHelper.HostandPortHA = pveHostandPortHA;
PveHelper.ApiToken = pveApiToken;
PveHelper.Username = pveUsername;
PveHelper.Password = pvePassword;
PveHelper.Out = @out;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.1</TargetFramework>
<GenerateDocumentationFile>true</GenerateDocumentationFile>

<Version>1.5.1</Version>
<Version>1.5.2</Version>
<Company>Corsinvest Srl</Company>
<Authors>Daniele Corsini</Authors>
<Copyright>Corsinvest Srl</Copyright>
Expand Down
13 changes: 11 additions & 2 deletions src/Corsinvest.ProxmoxVE.TelegramBot.Api/Helpers/PveHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,24 @@ internal static class PveHelper
public static string HostandPortHA { get; set; }
public static string Username { get; set; }
public static string Password { get; set; }
public static TextWriter Out { get; internal set; }
public static string ApiToken { get; set; }
public static TextWriter Out { get; set; }

public static ClassApi GetClassApiRoot(PveClient client)
=> _classApiRoot ??= GeneretorClassApi.Generate(client.Hostname, client.Port);

public static PveClient GetClient()
{
var client = ClientHelper.GetClientFromHA(HostandPortHA, Out);
client.Login(Username, Password);
if (string.IsNullOrWhiteSpace(ApiToken))
{
client.Login(Username, Password);
}
else
{
client.ApiToken = ApiToken;
}

return client;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Version>1.4.1</Version>
<Version>1.4.2</Version>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>cv4pve-botgram</AssemblyName>
<Company>Corsinvest Srl</Company>
Expand All @@ -21,8 +21,8 @@

<!-- <ProjectReference Include="..\..\..\cv4pve-api-dotnet\src\Corsinvest.ProxmoxVE.Api.Shell\Corsinvest.ProxmoxVE.Api.Shell.csproj" /> -->
<PackageReference Include="Corsinvest.ProxmoxVE.Api.Shell" Version="2.6.3" />

<!-- <ProjectReference Include="..\Corsinvest.ProxmoxVE.TelegramBot.Api\Corsinvest.ProxmoxVE.TelegramBot.Api.csproj" /> -->
<PackageReference Include="Corsinvest.ProxmoxVE.TelegramBot.Api" Version="1.5.1" />
<PackageReference Include="Corsinvest.ProxmoxVE.TelegramBot.Api" Version="1.5.2" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/Corsinvest.ProxmoxVE.TelegramBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ static void Main(string[] args)
}
var botManager = new BotManager(app.GetHost().Value(),
app.GetApiToken().Value(),
app.GetUsername().Value(),
app.GetPasswordFromOption(),
optToken.Value(),
Expand Down

0 comments on commit 23b6070

Please sign in to comment.