I am using LanguageExt to have functional programming features in C#. I have a method in which I want to build an instance of VaultSharp to access our HashiCorp Vault service. My goal is to create an instance of VaultClientSettings (see methods below) through a chain of two Eithers. In the end, either return an exception from any Either in the chain or the instance of VaultClientSettings. I think that I am close but cannot make the last step work. I'd appreciate your suggestions.
Here are links to the FP library for C# and the VaultSharp library;
- https://github.com/louthy/language-ext/tree/main/LanguageExt.Core
- https://github.com/rajanadar/VaultSharp
Here is an image showing the error that I am seeing:
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;
}));
}