refactoring and testing OpenVpnCertificatesServer with token

This commit is contained in:
Kim 2023-03-23 17:17:10 +01:00
parent f62375ae54
commit b8da0c379d
3 changed files with 30 additions and 17 deletions

View File

@ -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; }
}

View File

@ -13,4 +13,10 @@
<ProjectReference Include="../../Lib/Utils/Utils.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="token.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>

View File

@ -33,7 +33,13 @@ public static class Program
private const String CertsDir = VpnDir + "/certs";
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 QueryPath = "/get_cert";
@ -136,8 +142,8 @@ public static class Program
Console.WriteLine($"looking up unique id {uniqueId} on VRM");
//var installationName = await LookupInstallationNameByUniqueId(ccdName);
using var vrm = VrmAccount.Token(AccToken.idUser, AccToken.token);
var token = ReadAccessToken();
using var vrm = VrmAccount.Token(token.idUser, token.token);
var installations = await vrm.GetInstallations();
var installationName = installations
@ -153,8 +159,8 @@ public static class Program
private static async Task<(String ccdName, String humanReadableName)?> LookupInstallationNameByMachineSerial(String ccdName)
{
Console.WriteLine($"looking up {ccdName} on VRM");
using var vrm = VrmAccount.Token(AccToken.idUser, AccToken.token);
var token = ReadAccessToken();
using var vrm = VrmAccount.Token(token.idUser, token.token);
var installations = await vrm.GetInstallations();
foreach (var installation in installations)
@ -269,14 +275,3 @@ public static class Program
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; }
}