Skip to content

Commit

Permalink
allow to provide cookie data via env
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Aug 26, 2024
1 parent 27434ce commit 21e80ce
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions HackMdApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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();

Expand Down

0 comments on commit 21e80ce

Please sign in to comment.