From 610aa05a38c36d0e10b745d45d85f6f4afe79a2c Mon Sep 17 00:00:00 2001 From: Kim Date: Thu, 23 Mar 2023 15:57:51 +0100 Subject: [PATCH] Wip test commit --- .../App/OpenVpnCertificatesServer/Program.cs | 28 +++++++++++++------ .../App/OpenVpnCertificatesServer/newToken.sh | 19 +++++++++++++ 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/csharp/App/OpenVpnCertificatesServer/Program.cs b/csharp/App/OpenVpnCertificatesServer/Program.cs index c9bff3a03..54b426516 100644 --- a/csharp/App/OpenVpnCertificatesServer/Program.cs +++ b/csharp/App/OpenVpnCertificatesServer/Program.cs @@ -1,5 +1,8 @@ using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Net; using System.Text; +using System.Text.Json; using Flurl; using ICSharpCode.SharpZipLib.Tar; using InnovEnergy.App.OpenVpnCertificatesServer.PKI; @@ -18,6 +21,7 @@ namespace InnovEnergy.App.OpenVpnCertificatesServer; // quotes!! // wget 'http://localhost:4000/get_cert?name=MYNAME&pw=MwBRbQb3QaX7l9XIaakq' +[SuppressMessage("Trimming", "IL2026:Members annotated with \'RequiresUnreferencedCodeAttribute\' require dynamic access otherwise can break functionality when trimming application code")] public static class Program { // TODO: use fody weaver to obfuscate strings? @@ -25,13 +29,13 @@ public static class Program private const String VpnSubnet = "10.2."; private const String VpnGateway = "10.2.0.1"; - private const String VpnDir = "/etc/openvpn/server/Salino"; - private const String CcdDir = VpnDir + "/ccd"; - private const String CertsDir = VpnDir + "/certs"; - private const String Endpoint = "http://localhost:4000/"; - private const String VrmUser = "victron@innov.energy"; - private const String VrmPwd = "NnoVctr201002"; - private const String ManualPw = "MwBRbQb3QaX7l9XIaakq"; + private const String VpnDir = "/etc/openvpn/server/Salino"; + private const String CcdDir = VpnDir + "/ccd"; + private const String CertsDir = VpnDir + "/certs"; + private const String Endpoint = "http://localhost:4000/"; + + private static readonly AccToken AccToken = JsonSerializer.Deserialize(File.OpenRead("./token.json"))!; //"d4179e69413ad8c507e0965a55bb90fe712184af9c81c196b9d19db5bb083d5f"; + private const String ManualPw = "MwBRbQb3QaX7l9XIaakq"; private const String QueryPath = "/get_cert"; private const String NameQueryParam = "name"; @@ -134,7 +138,7 @@ public static class Program //var installationName = await LookupInstallationNameByUniqueId(ccdName); - using var vrm = await VrmAccount.Login(VrmUser, VrmPwd); // TODO: use token + using var vrm = VrmAccount.Token(AccToken.Id, AccToken.Token); var installations = await vrm.GetInstallations(); var installationName = installations @@ -151,7 +155,7 @@ public static class Program { Console.WriteLine($"looking up {ccdName} on VRM"); - using var vrm = await VrmAccount.Login(VrmUser, VrmPwd); // TODO: use token + using var vrm = VrmAccount.Token(AccToken.Id, AccToken.Token); var installations = await vrm.GetInstallations(); foreach (var installation in installations) @@ -265,4 +269,10 @@ public static class Program return $"{VpnSubnet}{hi}.{lo}"; } +} + +internal interface AccToken +{ + public String Token { get; init; } + public UInt64 Id { get; init; } } \ No newline at end of file diff --git a/csharp/App/OpenVpnCertificatesServer/newToken.sh b/csharp/App/OpenVpnCertificatesServer/newToken.sh index e69de29bb..beda996eb 100644 --- a/csharp/App/OpenVpnCertificatesServer/newToken.sh +++ b/csharp/App/OpenVpnCertificatesServer/newToken.sh @@ -0,0 +1,19 @@ +#!/bin/bash +## USAGE: ./newToken.sh -u USERNAME -p PASSWORD + + +while getopts u:p: flag +do + case "${flag}" in + u) username=${OPTARG};; + p) password=${OPTARG};; + esac +done + +curl --request POST \ + --url https://vrmapi.victronenergy.com/v2/auth/login \ + --header 'Content-Type: application/json' \ + --data '{ + "username": '$username', + "password": '$password', +}' > token.json \ No newline at end of file