【发布时间】:2020-11-04 13:02:18
【问题描述】:
我正在使用 LanguageExt 在 C# 中提供函数式编程功能。我有一个方法,我想在其中构建一个 VaultSharp 实例来访问我们的 HashiCorp Vault 服务。我的目标是通过两个 Either 的链创建一个 VaultClientSettings 实例(参见下面的方法)。最后,要么从链中的任何 Either 或实例中返回异常 Vault 客户端设置。我认为我很接近但无法完成最后一步。非常感谢您的建议。
这里是 C# 的 FP 库和 VaultSharp 库的链接;
- https://github.com/louthy/language-ext/tree/main/LanguageExt.Core
- https://github.com/rajanadar/VaultSharp
这是显示我看到的错误的图像:
Either<Exception, Uri> GetVaultUri() =>
EnvironmentVariable.GetEnvironmentVariable(KVaultAddressEnvironmentVariableName)
.Map(uri => new Uri(uri));
Either<Exception, TokenAuthMethodInfo> GetAuthInfo() =>
EnvironmentVariable.GetEnvironmentVariable(KVaultTokenEnvironmentVariableName)
.Map(token => new TokenAuthMethodInfo(token));
Either<Exception, VaultClientSettings> GetVaultClientSettings(
Either<Exception, Uri> vaultUri,
Either<Exception, TokenAuthMethodInfo> authInfo
)
{
/////////////////////////////////////////////////////////////////////////
// I have access to the uri as u and the authmethod as a, but I cannot //
// figure out how to create the instance of VaultClientSettings. //
Either<Exception, VaultClientSettings> settings =
vaultUri.Bind<Uri>(u =>
authInfo.Bind<TokenAuthMethodInfo>(a =>
{
Either<Exception, VaultClientSettings> vaultClientSettings =
new VaultClientSettings(u.AbsoluteUri, a);
return vaultClientSettings;
}));
}
【问题讨论】:
标签: c# functional-programming f# hashicorp-vault language-ext