public TemplateModel Process(TemplateModel template, ProfileModel profile, Pbkdf2Model protectedFile, ICollection <SecretEntryModel> secrets) { _objectValidator.IsNull(template, nameof(template)); _objectValidator.IsNull(profile, nameof(profile)); _objectValidator.IsNull(protectedFile, nameof(protectedFile)); _objectValidator.IsNull(secrets, nameof(secrets)); var resultModel = new TemplateModel(); try { foreach (var templateLine in template.Fields) { var key = templateLine.Key; var value = TryGetValue(templateLine.Value, template, profile, protectedFile, secrets); resultModel.Fields.Add(key, value); Log.Logger.Debug($"Bounded key: '{key}' to value '{value}'"); } } catch (Exception exception) { Log.Logger.Error(exception, "During preparing output an error has been occured"); throw; } return(resultModel); }
private ProfileModel ProcessEnvironmentVariables(ProfileModel profile, IDictionary <string, string> environmentVariables) { _objectValidator.IsNull(profile, nameof(profile)); _objectValidator.IsNull(environmentVariables, nameof(environmentVariables)); var newProfile = new ProfileModel(); foreach (var field in profile.Fields) { var value = EnvironmentVariableHelper.TryGetEnvironmentVariableValueForField(field.Value, environmentVariables); newProfile.Fields.Add(field.Key, value); } return(newProfile); }
private Pbkdf2Model ProcessEnvironmentVariables(Pbkdf2Model model, IDictionary <string, string> environmentVariables) { _objectValidator.IsNull(model, nameof(model)); _objectValidator.IsNull(environmentVariables, nameof(environmentVariables)); var newModel = new Pbkdf2Model(); foreach (var field in model.Fields) { var value = EnvironmentVariableHelper.TryGetEnvironmentVariableValueForField(field.Value, environmentVariables); newModel.Fields.Add(field.Key, value); } return(newModel); }
public async Task Write(TemplateModel model, string outputPath, string oroginalTemplatePath) { _stringValidator.IsNullOrWhitespace(outputPath, nameof(outputPath)); _stringValidator.IsNullOrWhitespace(oroginalTemplatePath, nameof(oroginalTemplatePath)); _objectValidator.IsNull(model, nameof(model)); var orifinalFileContent = await _diskService.ReadFileText(oroginalTemplatePath); //This is stupid version of algorithm, should be improved in the future foreach (var keyValue in model.Fields) { var indexOfKey = orifinalFileContent.IndexOf(keyValue.Key); var indexOfEndLine = orifinalFileContent.IndexOf(Environment.NewLine, indexOfKey); if (indexOfEndLine == -1) { indexOfEndLine = orifinalFileContent.Length; } var charactersToCheck = indexOfEndLine - indexOfKey; var indexOfAssign = orifinalFileContent.IndexOf(AssignChar, indexOfKey, charactersToCheck); var indexOffirstCharacter = GetFirstNonWhitespace(orifinalFileContent, indexOfAssign, indexOfEndLine); var lengthToReplace = indexOfEndLine - indexOffirstCharacter; var partToReplace = orifinalFileContent.Substring(indexOffirstCharacter, lengthToReplace); orifinalFileContent = orifinalFileContent.Replace(partToReplace, keyValue.Value); } await _diskService.WriteFileText(orifinalFileContent, outputPath); }
public ICollection <string> ExtractEnvironmentVariables(ProfileModel model) { _objectValidator.IsNull(model, nameof(model)); var foundEnvironmentVariables = ProcessFileHelper.ExtractEnvironmentVariables(model.Fields); return(foundEnvironmentVariables); }
public IDictionary <string, string> Read(IEnumerable <string> variablesNames) { _objectValidator.IsNull(variablesNames, nameof(variablesNames)); var readVariables = variablesNames.ToDictionary(item => item, item => Read(item)); return(readVariables); }
private ICollection <string> ExtractEnvironmentVariables(ConfigurationModel model) { _objectValidator.IsNull(model, nameof(model)); var foundEnvironmentVariables = new List <string>(); if (model.TemplatePath.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.TemplatePath.GetBetweenParentheses()); } if (model.ResultPath.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.ResultPath.GetBetweenParentheses()); } if (model.ProfilePath.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.ProfilePath.GetBetweenParentheses()); } if (model.SecureVaultPath.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.SecureVaultPath.GetBetweenParentheses()); } if (model.SecureVaultPass.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.SecureVaultPass.GetBetweenParentheses()); } if (model.ProtectedFilePath.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.ProtectedFilePath.GetBetweenParentheses()); } if (model.ProtectedFileEntropy.StartsWith(Consts.EnvironmentalVariableTagName)) { foundEnvironmentVariables.Add(model.ProtectedFileEntropy.GetBetweenParentheses()); } return(foundEnvironmentVariables); }
public void When_is_null_And_object_is_not_null_Then_does_not_throw_any_exception() { Assert.DoesNotThrow(() => _sut.IsNull(new object(), string.Empty)); }