public void ReplaceSecretsInContent_Throws_If_Variable_Is_Empty() { _configManagerMock.ConfigReturns(null); var content = "CREATE ${{MG_SOME_VAR}} HERE OR THERE"; _configManagerMock.GetKeyFromMapping("MG_SOME_VAR", "MG_SOME_VAR"); _envMock.GetEnvironmentVariable("MG_SOME_VAR", string.Empty); var sut = new SecretManager(_envMock.Object, _fileManagerMock.Object, _configManagerMock.Object); Assert.Throws <Exception>(() => sut.ReplaceVariablesInContent(content)); }
public void ReplaceSecretsInContent_Replaces_Correctly() { _configManagerMock.ConfigReturns(null); var content = "CREATE ${{MG_SOME_VAR}} HERE OR THERE"; _configManagerMock.GetKeyFromMapping("MG_SOME_VAR", "MG_SOME_VAR"); _envMock.GetEnvironmentVariable("MG_SOME_VAR", "THIS"); var sut = new SecretManager(_envMock.Object, _fileManagerMock.Object, _configManagerMock.Object); var result = sut.ReplaceVariablesInContent(content); Assert.Equal("CREATE THIS HERE OR THERE", result); }
private string ResolveConfig(string fromConfig, string envKey, string defaultValue) { if (fromConfig != null) { if (SecretManager.HasVariable(fromConfig)) { return(SecretManager.ReplaceVariablesInContent(fromConfig)); } return(fromConfig); } if (!string.IsNullOrEmpty(envKey)) { return(SecretManager.GetEnvironmentVariable(envKey)); } return(defaultValue); }