From 21e80cef74998fe758c8f18a1771fa60aea4a910 Mon Sep 17 00:00:00 2001 From: Markus Keil Date: Mon, 26 Aug 2024 13:01:37 +0200 Subject: [PATCH] allow to provide cookie data via env --- HackMdApi.cs | 9 +++++++++ Program.cs | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/HackMdApi.cs b/HackMdApi.cs index d1612cf..3c5f381 100644 --- a/HackMdApi.cs +++ b/HackMdApi.cs @@ -298,6 +298,15 @@ private HttpRequestMessage CreateRequest(string path) }, }; } + + public void SetCookieExternal(string cookieCsrf, string cookieSessionId, string cookieUserId) + { + _crsfCookie = cookieCsrf; + _sessionCookie = cookieSessionId; + _useridCookie = cookieUserId; + StoreCachedCookies(); + Console.WriteLine("Stored externally provided cookie values"); + } } internal class CachedCookies diff --git a/Program.cs b/Program.cs index 078c530..ecfb491 100644 --- a/Program.cs +++ b/Program.cs @@ -28,6 +28,10 @@ string GetConfig(string envName, string defaultValue = "") string s3SecretKey = GetConfig("S3_SECRET_KEY"); string s3Bucket = GetConfig("S3_BUCKET"); +string cookieCsrf = GetConfig("COOKIE_CSRF"); +string cookieSessionId = GetConfig("COOKIE_SESSION_ID"); +string cookieUserId = GetConfig("COOKIE_USER_ID"); + HackMdApi api = new HackMdApi(webDriverEndpoint) { GitHubUsername = GetConfig("GITHUB_USERNAME"), @@ -38,6 +42,11 @@ string GetConfig(string envName, string defaultValue = "") HackMdHost = GetConfig("HACKMD_HOST"), }; +if (!string.IsNullOrEmpty(cookieSessionId)) +{ + api.SetCookieExternal(cookieCsrf, cookieSessionId, cookieUserId); +} + Console.WriteLine("==> Pulling notes"); await api.GetAllNotes();