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); }
public void Init() { TemplateModel = new TemplateModel(); TemplateProfile = new ProfileModel(); ProtectedFile = new Pbkdf2Model(); Secrets = new List <SecretEntryModel>(); _objectValidatorMock = new Mock <IObjectValidator>(); _sut = new Environmentalist.Services.LogicProcessor.LogicProcessor( _objectValidatorMock.Object); }
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 <Pbkdf2Model> Decrypt(string path, string entropy) { _stringValidator.IsNullOrWhitespace(path, nameof(path)); _stringValidator.IsNullOrWhitespace(entropy, nameof(entropy)); _fileValidator.IsExist(path); var content = await _diskService.ReadFileText(path); var plaintext = _pbkdF2Service.Decrypt(content, entropy); var fields = ProcessFileHelper.ProcessContent(plaintext); var result = new Pbkdf2Model(fields); var environmentVariables = ProcessFileHelper.ExtractEnvironmentVariables(result.Fields); var environmentVariablesValues = _environmentVariableReader.Read(environmentVariables); result = ProcessEnvironmentVariables(result, environmentVariablesValues); return(result); }
private static string TryGetValue(string value, TemplateModel template, ProfileModel profile, Pbkdf2Model protectedFile, ICollection <SecretEntryModel> secrets) { var foundValue = profile.Fields.ContainsKey(value) ? profile.Fields[value] : (protectedFile.Fields.ContainsKey(value) ? protectedFile.Fields[value] : value); foundValue = TryGetCustomValue(foundValue, secrets); return(foundValue); }