VaultSharp 包似乎包含了我想要的所有内容,并且有据可查。我尝试使用 VaultSharp 包从 Vault 服务器读取我们的秘密。但是我生锈的 C# 在Secret<SecretData> kv2Secret = await vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync("/secret/my_corp/my_app/dev/db_creds");
下面的“”行阻止了我,并显示错误消息:
'await' 运算符只能在异步方法中使用。考虑使用“异步”修饰符标记此方法并将其返回类型更改为“任务”。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VaultSharp;
using VaultSharp.V1.AuthMethods.AppRole;
using VaultSharp.V1.AuthMethods;
using VaultSharp.V1.Commons;
using VaultSharp.V1.AuthMethods.Token;
namespace VaultConsoleApp
{
class Program
{
static void Main(string[] args)
{
var vaultUrl = "https://vault-server.url.com:443";
Program.by_token(vaultUrl);
}
static void by_token(string vaultUrl)
{
// Initialize one of the several auth methods.
IAuthMethodInfo authMethod = new TokenAuthMethodInfo("s.R2gFHDiup5wCeHHksfc2zKUN");
// Initialize settings. You can also set proxies, custom delegates etc. here.
var vaultClientSettings = new VaultClientSettings(vaultUrl, authMethod);
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
// Use client to read a key-value secret.
Secret<SecretData> kv2Secret = await vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync("/secret/my_corp/my_app/dev/db_creds");
}
}
}