-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* frontend support for expression validation * parse expression validation config * parse config file * evaluate expressions for validation * add argv function * migrate from newtonsoft and fix parsing * improve error handling and fix numeric parse * started making shared tests * improved test runner * fix list of resolved keys * add tests and refactor jsondatamodel * update settings * add app-settings-rewriter to altinn-app-cli * fix upgrade appsettings * refactor JsonDataModel RemoveField and check deleteRow arg * add source and throw exception
- Loading branch information
1 parent
c731cd5
commit 4da4527
Showing
33 changed files
with
1,951 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
cli-tools/altinn-app-cli/v7Tov8/AppSettingsRewriter/AppSettingsRewriter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
|
||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace altinn_app_cli.v7Tov8.AppSettingsRewriter; | ||
|
||
|
||
/// <summary> | ||
/// Rewrites the appsettings.*.json files | ||
/// </summary> | ||
public class AppSettingsRewriter | ||
{ | ||
/// <summary> | ||
/// The pattern used to search for appsettings.*.json files | ||
/// </summary> | ||
public static readonly string APP_SETTINGS_FILE_PATTERN = "appsettings*.json"; | ||
|
||
private Dictionary<string, JsonObject> appSettingsJsonCollection; | ||
|
||
private readonly IList<string> warnings = new List<string>(); | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="AppSettingsRewriter"/> class. | ||
/// </summary> | ||
public AppSettingsRewriter(string appSettingsFolder) | ||
{ | ||
appSettingsJsonCollection = new Dictionary<string, JsonObject>(); | ||
foreach (var file in Directory.GetFiles(appSettingsFolder, APP_SETTINGS_FILE_PATTERN)) | ||
{ | ||
var json = File.ReadAllText(file); | ||
var appSettingsJson = JsonNode.Parse(json); | ||
if (appSettingsJson is not JsonObject appSettingsJsonObject) | ||
{ | ||
warnings.Add($"Unable to parse AppSettings file {file} as a json object, skipping"); | ||
continue; | ||
} | ||
|
||
this.appSettingsJsonCollection.Add(file, appSettingsJsonObject); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the warnings | ||
/// </summary> | ||
public IList<string> GetWarnings() | ||
{ | ||
return warnings; | ||
} | ||
|
||
/// <summary> | ||
/// Upgrades the appsettings.*.json files | ||
/// </summary> | ||
public void Upgrade() | ||
{ | ||
foreach ((var fileName, var appSettingsJson) in appSettingsJsonCollection) | ||
{ | ||
RewriteRemoveHiddenDataSetting(fileName, appSettingsJson); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Writes the appsettings.*.json files | ||
/// </summary> | ||
public async Task Write() | ||
{ | ||
var tasks = appSettingsJsonCollection.Select(async appSettingsFiles => | ||
{ | ||
appSettingsFiles.Deconstruct(out var fileName, out var appSettingsJson); | ||
JsonSerializerOptions options = new JsonSerializerOptions | ||
{ | ||
WriteIndented = true, | ||
}; | ||
await File.WriteAllTextAsync(fileName, appSettingsJson.ToJsonString(options)); | ||
}); | ||
|
||
await Task.WhenAll(tasks); | ||
} | ||
|
||
private void RewriteRemoveHiddenDataSetting(string fileName, JsonObject settings) | ||
{ | ||
// Look for "AppSettings" object | ||
settings.TryGetPropertyValue("AppSettings", out var appSettingsNode); | ||
if (appSettingsNode is not JsonObject appSettingsObject) | ||
{ | ||
// No "AppSettings" object found, nothing to change | ||
return; | ||
} | ||
|
||
// Look for "RemoveHiddenDataPreview" property | ||
appSettingsObject.TryGetPropertyValue("RemoveHiddenDataPreview", out var removeHiddenDataPreviewNode); | ||
if (removeHiddenDataPreviewNode is not JsonValue removeHiddenDataPreviewValue) | ||
{ | ||
// No "RemoveHiddenDataPreview" property found, nothing to change | ||
return; | ||
} | ||
|
||
// Get value of "RemoveHiddenDataPreview" property | ||
if (!removeHiddenDataPreviewValue.TryGetValue<bool>(out var removeHiddenDataValue)) | ||
{ | ||
warnings.Add($"RemoveHiddenDataPreview has unexpected value {removeHiddenDataPreviewValue.ToJsonString()} in {fileName}, expected a boolean"); | ||
return; | ||
} | ||
|
||
appSettingsObject.Remove("RemoveHiddenDataPreview"); | ||
appSettingsObject.Add("RemoveHiddenData", removeHiddenDataValue); | ||
appSettingsObject.Add("RequiredValidation", removeHiddenDataValue); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.