Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#7746 jwtfile path correction #7765

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.JsonRpc/JsonRpcConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public int WebSocketsPort
public long? MaxRequestBodySize { get; set; } = 30000000;
public int MaxLogsPerResponse { get; set; } = 20_000;
public int? EthModuleConcurrentInstances { get; set; } = null;
public string JwtSecretFile { get; set; } = "keystore/jwt-secret";
public string JwtSecretFile { get; set; } = null;
public bool UnsecureDevNoRpcAuthentication { get; set; }
public int? MaxLoggedRequestParametersCharacters { get; set; } = null;
public string[]? MethodsLoggingFiltering { get; set; } =
Expand Down
28 changes: 28 additions & 0 deletions src/Nethermind/Nethermind.Runner/Ethereum/Steps/StartRpc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System.Linq;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using Nethermind.Api;
Expand All @@ -14,6 +15,7 @@
using Nethermind.Logging;
using Nethermind.Runner.JsonRpc;
using Nethermind.Serialization.Json;
using Nethermind.KeyStore.Config;

namespace Nethermind.Runner.Ethereum.Steps
{
Expand All @@ -30,8 +32,34 @@ public StartRpc(INethermindApi api)
public async Task Execute(CancellationToken cancellationToken)
{
IJsonRpcConfig jsonRpcConfig = _api.Config<IJsonRpcConfig>();
IKeyStoreConfig keyStoreConfig = _api.Config<IKeyStoreConfig>();
ILogger logger = _api.LogManager.GetClassLogger();


// Update the JWT secret path based on the data directory.
try
{
string defaultPath = "keystore/jwt-secret";
string newPath = Path.Combine(keyStoreConfig.KeyStoreDirectory, "jwt-secret");
if (string.IsNullOrEmpty(jsonRpcConfig.JwtSecretFile))
{
logger.Warn("JsonRpcConfig JwtSecretFile is null or empty because of omission or human error.");
// check if jwt-secret file already exists in previous default directory
if (File.Exists(defaultPath))
{
// move the jwt-secret file
logger.Warn($"jwt-secret already exists at {defaultPath}. Moving it to {newPath} as data directory has been updated");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a side note: if you intend to take corrective action then they are info logs and not warning logs.

for now until we decide if we need to move or not based on @MarekM25 response,
we can just leave it as is.

File.Move(defaultPath, newPath);
}
logger.Warn($"jwt-secret file does not exist at {defaultPath}. Directly setting it to new path: {newPath}");
ssonthal marked this conversation as resolved.
Show resolved Hide resolved
jsonRpcConfig.JwtSecretFile = newPath;
}
}
catch (IOException ex)
{
logger.Error("IO error while setting jwt-secret file path: ", ex);
}

if (jsonRpcConfig.Enabled)
{
IInitConfig initConfig = _api.Config<IInitConfig>();
Expand Down