Skip to content

Commit

Permalink
Merge pull request #193 from NoxOrg/bugfix/server-fails-on-templates
Browse files Browse the repository at this point in the history
Bugfix/server fails on templates
  • Loading branch information
jan-schutte authored Mar 1, 2024
2 parents 74df6fc + 715cdab commit 9810d81
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions src/Nox.Cli.Caching/NoxCliCacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ private void RaiseBuildEvent(string message)

internal string GetOnlineTemplate(string name)
{
Thread.Sleep(200);
var client = new RestClient(GetRemoteUri($"/templates/{name}"));
var fileRequest = new RestRequest() { Method = Method.Get };
fileRequest.AddHeader("Accept", "application/json");
Expand Down
29 changes: 18 additions & 11 deletions src/Nox.Cli.Variables/ClientVariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ClientVariableProvider: IClientVariableProvider
private NoxSolution? _projectConfig;
private readonly INoxCliCache? _cache;
private readonly ILocalTaskExecutorConfiguration? _lteConfig;

private readonly List<string> _serverVariables;

public ClientVariableProvider(
WorkflowConfiguration workflow,
Expand All @@ -30,6 +30,7 @@ public ClientVariableProvider(
INoxCliCache? cache = null)
{
_variables = new Dictionary<string, object?>(StringComparer.OrdinalIgnoreCase);
_serverVariables = new List<string>();
_orgSecretResolver = orgSecretResolver;
_projectConfig = projectConfig;
_lteConfig = lteConfig;
Expand All @@ -56,9 +57,9 @@ public void SetActionVariable(INoxAction action, string key, object value)
ResolveAllVariables(action);
}

public IDictionary<string, object> GetInputVariables(INoxAction action)
public IDictionary<string, object> GetInputVariables(INoxAction action, bool isServer = false)
{
ResolveAllVariables(action);
ResolveAllVariables(action, isServer);

return action.Inputs.ToDictionary(i => i.Key, i => i.Value.Default, StringComparer.OrdinalIgnoreCase);
}
Expand Down Expand Up @@ -111,7 +112,7 @@ public IDictionary<string, object> GetUnresolvedInputVariables(INoxAction action
return unresolvedVars;
}

public void StoreOutputVariables(INoxAction action, IDictionary<string, object> outputs)
public void StoreOutputVariables(INoxAction action, IDictionary<string, object> outputs, bool isServer = false)
{
foreach (var output in outputs)
{
Expand All @@ -126,7 +127,11 @@ public void StoreOutputVariables(INoxAction action, IDictionary<string, object>
{
_variables[varKey] = output.Value;
}

}

if (isServer && !_serverVariables.Contains(varKey))
{
_serverVariables.Add(varKey);
}
}

Expand Down Expand Up @@ -208,7 +213,7 @@ private void Initialize(WorkflowConfiguration workflow)
}
}

private object ReplaceVariable(object value, bool isIfCondition = false)
private object ReplaceVariable(object value, bool isIfCondition = false, bool isServer = false)
{
var result = value;

Expand All @@ -220,6 +225,8 @@ private object ReplaceVariable(object value, bool isIfCondition = false)

var variable = match.Groups["variable"].Value;

if (isServer && _serverVariables.Contains(variable)) return result;

var resolvedValue = LookupValue(variable);

if (resolvedValue?.GetType() == typeof(object))
Expand Down Expand Up @@ -270,13 +277,13 @@ private object ReplaceVariable(object value, bool isIfCondition = false)
return null;
}

private void ResolveAllVariables(INoxAction action)
private void ResolveAllVariables(INoxAction action, bool isServer = false)
{
foreach (var (_, input) in action.Inputs)
{
if (input.Default is string inputValueString)
{
input.Default = ReplaceVariable(inputValueString);
input.Default = ReplaceVariable(inputValueString, isServer: isServer);
}
else if (input.Default is List<object> inputObjectList)
{
Expand All @@ -285,7 +292,7 @@ private void ResolveAllVariables(INoxAction action)
if (inputObjectList[i] is string)
{
var index = inputObjectList.FindIndex(n => n.Equals(inputObjectList[i]));
inputObjectList[index] = ReplaceVariable((string)inputObjectList[i]);
inputObjectList[index] = ReplaceVariable((string)inputObjectList[i], isServer: isServer);
}
}
}
Expand All @@ -294,7 +301,7 @@ private void ResolveAllVariables(INoxAction action)
for (var i = 0; i < inputStringList.Count; i++)
{
var index = inputStringList.FindIndex(n => n.Equals(inputStringList[i]));
inputStringList[index] = ReplaceVariable(inputStringList[i]).ToString()!;
inputStringList[index] = ReplaceVariable(inputStringList[i], isServer: isServer).ToString()!;
}
}
else if (input.Default is Dictionary<object, object> inputValueDictionary)
Expand All @@ -305,7 +312,7 @@ private void ResolveAllVariables(INoxAction action)

if (item.Value is string itemValueString)
{
inputValueDictionary[item.Key] = ReplaceVariable(itemValueString);
inputValueDictionary[item.Key] = ReplaceVariable(itemValueString, isServer: isServer);
}
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/Nox.Cli.Variables/IClientVariableProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ public interface IClientVariableProvider
{
void SetVariable(string key, object value);
void SetActionVariable(INoxAction action, string key, object value);
IDictionary<string, object> GetInputVariables(INoxAction action);
IDictionary<string, object> GetInputVariables(INoxAction action, bool isServer = false);
IDictionary<string, object> GetUnresolvedInputVariables(INoxAction action);
void StoreOutputVariables(INoxAction action, IDictionary<string, object> outputs);
void StoreOutputVariables(INoxAction action, IDictionary<string, object> outputs, bool isServer = false);
void SetProjectConfiguration(NoxSolution projectConfig);

Task ResolveAll();
Task ResolveForServer();
Task ResolveProjectVariables();
Expand Down
6 changes: 3 additions & 3 deletions src/Nox.Cli/Actions/NoxWorkflowContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public async Task<IDictionary<string, object>> GetInputVariables(INoxAction acti
{
await _varProvider.ResolveAll();
}
return _varProvider.GetInputVariables(action);
return _varProvider.GetInputVariables(action, isServer);
}

public async Task ResolveJobVariables(INoxJob job)
Expand All @@ -168,9 +168,9 @@ public async Task ResolveJobVariables(INoxJob job)
_varProvider.ResolveJobVariables(job);
}

public void StoreOutputVariables(INoxAction action, IDictionary<string, object> outputs)
public void StoreOutputVariables(INoxAction action, IDictionary<string, object> outputs, bool isServer = false)
{
_varProvider.StoreOutputVariables(action, outputs);
_varProvider.StoreOutputVariables(action, outputs, isServer);
}

public IDictionary<string, object> GetUnresolvedInputVariables(INoxAction action)
Expand Down
3 changes: 2 additions & 1 deletion src/Nox.Cli/Actions/NoxWorkflowExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@ private async Task<bool> ProcessServerTask(NoxWorkflowContext ctx, string taskDe
ctx.SetState(executeResponse.State);
var outputs = executeResponse.Outputs;

if (outputs != null) ctx.StoreOutputVariables(ctx.CurrentAction, outputs);
if (outputs != null) ctx.StoreOutputVariables(ctx.CurrentAction, outputs, true);


ctx.CurrentAction.EvaluateValidate();

Expand Down
4 changes: 2 additions & 2 deletions src/Nox.Cli/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"profiles": {
"Nox.Cli": {
"commandName": "Project",
"commandLineArgs": "sync vc",
"workingDirectory": "/home/jan/demo/CliDemo",
"commandLineArgs": "sync tf",
"workingDirectory": "/home/jan/Projects/IWG/Fno.MultiInstance",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down

0 comments on commit 9810d81

Please sign in to comment.