refactoring and testing OpenVpnCertificatesServer with token
This commit is contained in:
parent
f62375ae54
commit
b8da0c379d
|
@ -0,0 +1,12 @@
|
||||||
|
namespace InnovEnergy.App.OpenVpnCertificatesServer;
|
||||||
|
|
||||||
|
internal class AccToken
|
||||||
|
{
|
||||||
|
public String token { get; init; }
|
||||||
|
public String bearer { get; init; }
|
||||||
|
public UInt64 idUser { get; init; }
|
||||||
|
public String verification_mode { get; init; }
|
||||||
|
public String idAccessToken { get; init; }
|
||||||
|
public Boolean verification_sent { get; init; }
|
||||||
|
public Boolean success { get; init; }
|
||||||
|
}
|
|
@ -12,5 +12,11 @@
|
||||||
<ProjectReference Include="../../Lib/Victron/VictronVRM/VictronVRM.csproj" />
|
<ProjectReference Include="../../Lib/Victron/VictronVRM/VictronVRM.csproj" />
|
||||||
<ProjectReference Include="../../Lib/Utils/Utils.csproj" />
|
<ProjectReference Include="../../Lib/Utils/Utils.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="token.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -32,8 +32,14 @@ public static class Program
|
||||||
private const String CcdDir = VpnDir + "/ccd";
|
private const String CcdDir = VpnDir + "/ccd";
|
||||||
private const String CertsDir = VpnDir + "/certs";
|
private const String CertsDir = VpnDir + "/certs";
|
||||||
private const String Endpoint = "http://localhost:4000/";
|
private const String Endpoint = "http://localhost:4000/";
|
||||||
|
|
||||||
private static readonly AccToken AccToken = JsonSerializer.Deserialize<AccToken>(File.OpenRead("./token.json"))!; //"d4179e69413ad8c507e0965a55bb90fe712184af9c81c196b9d19db5bb083d5f";
|
private static AccToken ReadAccessToken()
|
||||||
|
{
|
||||||
|
var content = File.ReadAllText("./token.json");
|
||||||
|
return JsonSerializer.Deserialize<AccToken>(content)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private const String ManualPw = "MwBRbQb3QaX7l9XIaakq";
|
private const String ManualPw = "MwBRbQb3QaX7l9XIaakq";
|
||||||
|
|
||||||
private const String QueryPath = "/get_cert";
|
private const String QueryPath = "/get_cert";
|
||||||
|
@ -136,8 +142,8 @@ public static class Program
|
||||||
Console.WriteLine($"looking up unique id {uniqueId} on VRM");
|
Console.WriteLine($"looking up unique id {uniqueId} on VRM");
|
||||||
|
|
||||||
//var installationName = await LookupInstallationNameByUniqueId(ccdName);
|
//var installationName = await LookupInstallationNameByUniqueId(ccdName);
|
||||||
|
var token = ReadAccessToken();
|
||||||
using var vrm = VrmAccount.Token(AccToken.idUser, AccToken.token);
|
using var vrm = VrmAccount.Token(token.idUser, token.token);
|
||||||
var installations = await vrm.GetInstallations();
|
var installations = await vrm.GetInstallations();
|
||||||
|
|
||||||
var installationName = installations
|
var installationName = installations
|
||||||
|
@ -153,8 +159,8 @@ public static class Program
|
||||||
private static async Task<(String ccdName, String humanReadableName)?> LookupInstallationNameByMachineSerial(String ccdName)
|
private static async Task<(String ccdName, String humanReadableName)?> LookupInstallationNameByMachineSerial(String ccdName)
|
||||||
{
|
{
|
||||||
Console.WriteLine($"looking up {ccdName} on VRM");
|
Console.WriteLine($"looking up {ccdName} on VRM");
|
||||||
|
var token = ReadAccessToken();
|
||||||
using var vrm = VrmAccount.Token(AccToken.idUser, AccToken.token);
|
using var vrm = VrmAccount.Token(token.idUser, token.token);
|
||||||
var installations = await vrm.GetInstallations();
|
var installations = await vrm.GetInstallations();
|
||||||
|
|
||||||
foreach (var installation in installations)
|
foreach (var installation in installations)
|
||||||
|
@ -268,15 +274,4 @@ public static class Program
|
||||||
|
|
||||||
return $"{VpnSubnet}{hi}.{lo}";
|
return $"{VpnSubnet}{hi}.{lo}";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal interface AccToken
|
|
||||||
{
|
|
||||||
public String token { get; init; }
|
|
||||||
public String bearer { get; init; }
|
|
||||||
public UInt64 idUser { get; init; }
|
|
||||||
public String verification_mode { get; init; }
|
|
||||||
public String idAccessToken { get; init; }
|
|
||||||
public Boolean verification_sent { get; init; }
|
|
||||||
public Boolean success { get; init; }
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue