From 1c5d3bc31a952bd924d672cd38afba35287b1d8f Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Mon, 30 Jan 2023 08:55:11 -0800 Subject: [PATCH 01/21] Add OpenAPI Go and C# --- .../content/docs/get-started/developer-qs.mdx | 236 +++++++++++++++++- 1 file changed, 223 insertions(+), 13 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 4cc34f86cfba..a45d4441161f 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -57,7 +57,7 @@ Let's install the Vault client library for your language of choice. -> **Note**: Some of these libraries are currently community-maintained. - + [Go](https://pkg.go.dev/github.com/hashicorp/vault/api) (official) client library: @@ -76,7 +76,7 @@ import vault "github.com/hashicorp/vault/api" - + [Ruby](https://github.com/hashicorp/vault-ruby) (official) client library: @@ -96,7 +96,7 @@ require "vault" - + [C#](https://github.com/rajanadar/VaultSharp) client library: @@ -119,7 +119,7 @@ using VaultSharp.V1.Commons; - + [Python](https://github.com/hvac/hvac) client library: @@ -139,7 +139,7 @@ import hvac - + [Java (Spring)](https://spring.io/projects/spring-vault) client library: @@ -167,6 +167,68 @@ import org.springframework.vault.core.VaultTemplate; + + + + +[OpenAPI Go](https://github.com/hashicorp/vault-client-go) (Beta) client library: + +```shell-session +$ export GOPRIVATE=github.com/hashicorp/vault-client-go +$ go get github.com/hashicorp/vault-client-go +``` + +Now, let's add the import statements for the client library to the top of the file. + + + +```go +import ( + "github.com/hashicorp/vault-client-go" + "github.com/hashicorp/vault-client-go/schema" +) +``` + + + + + + + + +[OpenAPI C#](https://github.com/hashicorp/vault-client-dotnet) (Beta) client library: + +The Nuget packages are hosted in an internal Nuget feed that can be found in [Artifactory](https://artifactory.hashicorp.engineering/ui/repos/tree/General/vault-devex-nuget-local). You can use the Dotnet CLI or Nuget CLI to retrieve the package. + +You need to add the private Nuget feed as a source in either CLI. You can also generate an [access token](https://www.jfrog.com/confluence/display/JFROG/User+Profile#UserProfile-IdentityTokenidentitytoken) that can be used in lieu of a password. + +```shell-session +$ nuget sources add \ + -name HashicorpArtifactory \ + -source https://artifactory.hashicorp.engineering/ui/repos/tree/General/vault-devex-nuget-local \ + -username "myusername" \ + -password "mypassword" +``` + +**Or:** + +```shell-session +$ dotnet nuget add source https://artifactory.hashicorp.engineering/artifactory/api/nuget/v3/vault-devex-nuget-local \ + --name HashicorpArtifactory \ + --username "myusername" \ + --password "mypassword" +``` + +Now, let's add the import statements for the client library to the top of the file. + + + +```cs +using Vault; +using Vault.Client; +``` + + @@ -179,7 +241,8 @@ A variety of [authentication methods](/vault/docs/auth) can be used to prove you To keep things simple for our example, we'll just use the root token created in **Step 1**. Paste the following code to initialize a new Vault client that will use token-based authentication for all its requests: - + + ```go config := vault.DefaultConfig() @@ -194,6 +257,9 @@ if err != nil { client.SetToken("dev-only-token") ``` + + + ```ruby Vault.configure do |config| config.address = "http://127.0.0.1:8200" @@ -201,6 +267,9 @@ Vault.configure do |config| end ``` + + + ```cs IAuthMethodInfo authMethod = new TokenAuthMethodInfo(vaultToken: "dev-only-token"); @@ -209,6 +278,9 @@ VaultClientSettings("http://127.0.0.1:8200", authMethod); IVaultClient vaultClient = new VaultClient(vaultClientSettings); ``` + + + ```Python client = hvac.Client( url='http://127.0.0.1:8200', @@ -216,6 +288,9 @@ client = hvac.Client( ) ``` + + + ```Java VaultEndpoint vaultEndpoint = new VaultEndpoint(); @@ -229,11 +304,45 @@ VaultTemplate vaultTemplate = new VaultTemplate( ); ``` + + + ```shell-session export VAULT_TOKEN="dev-only-token" ``` - + + + +```go +// prepare a client with the given base address +client, err := vault.New( + vault.WithBaseAddress("http://127.0.0.1:8200"), + vault.WithRequestTimeout(30*time.Second), +) +if err != nil { + log.Fatal(err) +} + +// authenticate with a root token (insecure) +if err := client.SetToken("my-token"); err != nil { + log.Fatal(err) +} +``` + + + + +```cs +string address = "http://127.0.0.1:8200"; +VaultConfiguration config = new VaultConfiguration(address); + +VaultClient vaultClient = new VaultClient(config); +vaultClient.SetToken("my-token"); +``` + + + ## Step 4: Store a secret @@ -241,7 +350,8 @@ Secrets are sensitive data like API keys and passwords that we shouldn’t be st We'll use the Vault client we just initialized to write a secret to Vault, like so: - + + ```go secretData := map[string]interface{}{ @@ -257,6 +367,9 @@ if err != nil { fmt.Println("Secret written successfully.") ``` + + + ```ruby secret_data = {data: {password: "Hashi123"}} Vault.logical.write("secret/data/my-secret-password", secret_data) @@ -264,6 +377,9 @@ Vault.logical.write("secret/data/my-secret-password", secret_data) puts "Secret written successfully." ``` + + + ```cs var secretData = new Dictionary { { "password", "Hashi123" } }; vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync( @@ -275,6 +391,9 @@ vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync( Console.WriteLine("Secret written successfully."); ``` + + + ```Python create_response = client.secrets.kv.v2.create_or_update_secret( path='my-secret-password', @@ -284,6 +403,9 @@ create_response = client.secrets.kv.v2.create_or_update_secret( print('Secret written successfully.') ``` + + + ```Java Map data = new HashMap<>(); data.put("password", "Hashi123"); @@ -295,6 +417,9 @@ Versioned.Metadata createResponse = vaultTemplate System.out.println("Secret written successfully."); ``` + + + ```shell-session curl \ --header "X-Vault-Token: $VAULT_TOKEN" \ @@ -304,7 +429,36 @@ curl \ http://127.0.0.1:8200/v1/secret/data/my-secret-password ``` - + + + +```go +_, err = client.Secrets.KVv2Write(ctx, "my-secret", schema.KVv2WriteRequest{ + Data: map[string]any{ + "password1": "abc123", + "password2": "correct horse battery staple", + }, +}) +if err != nil { + log.Fatal(err) +} +log.Println("secret written successfully") +``` + + + + +```cs +var secretData = new Dictionary { { "mypass", "pass" } }; + +// Write a secret +var kvRequestData = new KVv2WriteRequest(secretData); + +vaultClient.Secrets.KVv2Write("mypath", kvRequestData); +``` + + + A common way of storing secrets is as key-value pairs using the [KV secrets engine (v2)](/vault/docs/secrets/kv/kv-v2). In the code we've just added, `password` is the key in the key-value pair, and `Hashi123` is the value. @@ -318,7 +472,8 @@ Now that we know how to write a secret, let's practice reading one. Underneath the line where you wrote a secret to Vault, let's add a few more lines, where we will be retrieving the secret and unpacking the value: - + + ```go secret, err := client.KVv2("secret").Get(context.Background(), "my-secret-password") @@ -332,11 +487,17 @@ log.Fatalf("value type assertion failed: %T %#v", secret.Data["password"], secre } ``` + + + ```ruby secret = Vault.logical.read("secret/data/my-secret-password") password = secret.data[:data][:password] ``` + + + ```cs Secret secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync( path: "/my-secret-password", @@ -346,12 +507,18 @@ Secret secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync( var password = secret.Data.Data["password"]; ``` + + + ```Python read_response = client.secrets.kv.read_secret_version(path='my-secret-password') password = read_response['data']['data']['password'] ``` + + + ```Java Versioned> readResponse = vaultTemplate .opsForVersionedKeyValue("secret") @@ -363,17 +530,43 @@ if (readResponse != null && readResponse.hasData()) { } ``` + + + ```shell-session curl \ --header "X-Vault-Token: $VAULT_TOKEN" \ http://127.0.0.1:8200/v1/secret/data/my-secret-password > secrets.json ``` - + + + +```go +ctx := context.Background() + +s, err := client.Secrets.KVv2Read(ctx, "my-secret") +if err != nil { + log.Fatal(err) +} +log.Println("secret retrieved:", s.Data) +``` + + + + +```cs +VaultResponse resp = vaultClient.Secrets.KVv2Read("mypath"); +Console.WriteLine(resp.Data); +``` + + + Last, confirm that the value we unpacked from the read response is correct: - + + ```go if value != "Hashi123" { @@ -383,12 +576,18 @@ if value != "Hashi123" { fmt.Println("Access granted!") ``` + + + ```ruby abort "Unexpected password" if password != "Hashi123" puts "Access granted!" ``` + + + ```cs if (password.ToString() != "Hashi123") { @@ -398,6 +597,9 @@ if (password.ToString() != "Hashi123") Console.WriteLine("Access granted!"); ``` + + + ```Python if password != 'Hashi123': sys.exit('unexpected password') @@ -405,6 +607,9 @@ if password != 'Hashi123': print('Access granted!') ``` + + + ```Java if (!password.equals("Hashi123")) { throw new Exception("Unexpected password"); @@ -413,10 +618,15 @@ if (!password.equals("Hashi123")) { System.out.println("Access granted!"); ``` + + + ```shell-session cat secrets.json | jq '.data.data' ``` - + + + If the secret was fetched successfully, you should see the `Access granted!` message after you run the code. If not, check to see if you provided the correct path to your secret. From 5f6bfce598f91b50923a8b45c64c3c1a823fa029 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Mon, 30 Jan 2023 14:23:01 -0800 Subject: [PATCH 02/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index a45d4441161f..5f39b0332abb 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -174,7 +174,6 @@ import org.springframework.vault.core.VaultTemplate; [OpenAPI Go](https://github.com/hashicorp/vault-client-go) (Beta) client library: ```shell-session -$ export GOPRIVATE=github.com/hashicorp/vault-client-go $ go get github.com/hashicorp/vault-client-go ``` From 19ac76f8fa84200ade05adbb287ba4d10cb99cea Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:11:32 -0800 Subject: [PATCH 03/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 5f39b0332abb..87644afc6783 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -314,7 +314,6 @@ export VAULT_TOKEN="dev-only-token" ```go -// prepare a client with the given base address client, err := vault.New( vault.WithBaseAddress("http://127.0.0.1:8200"), vault.WithRequestTimeout(30*time.Second), From 4cda0684ec5606e2c2c511ae73abeba599f4f486 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:11:38 -0800 Subject: [PATCH 04/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 87644afc6783..0604abd3c0f2 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -322,8 +322,7 @@ if err != nil { log.Fatal(err) } -// authenticate with a root token (insecure) -if err := client.SetToken("my-token"); err != nil { +if err := client.SetToken("dev-only-token"); err != nil { log.Fatal(err) } ``` From bf8ca518d60642cdd667194244ba4d8f52740bf1 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:11:45 -0800 Subject: [PATCH 05/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 0604abd3c0f2..37c6b72ebe8a 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -430,7 +430,7 @@ curl \ ```go -_, err = client.Secrets.KVv2Write(ctx, "my-secret", schema.KVv2WriteRequest{ +_, err = client.Secrets.KVv2Write(context.Background(), "my-secret-password", schema.KVv2WriteRequest{ Data: map[string]any{ "password1": "abc123", "password2": "correct horse battery staple", From 4e064bdefe8384f5e13ff24fc2e431a7e680af3f Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:11:50 -0800 Subject: [PATCH 06/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 37c6b72ebe8a..b2dfaeedc71b 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -432,8 +432,7 @@ curl \ ```go _, err = client.Secrets.KVv2Write(context.Background(), "my-secret-password", schema.KVv2WriteRequest{ Data: map[string]any{ - "password1": "abc123", - "password2": "correct horse battery staple", + "password": "Hashi123", }, }) if err != nil { From 0cb023ecac2d81ecdebb892bef5cc16ae176bedb Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:11:58 -0800 Subject: [PATCH 07/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index b2dfaeedc71b..67fd85030843 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -438,7 +438,8 @@ _, err = client.Secrets.KVv2Write(context.Background(), "my-secret-password", sc if err != nil { log.Fatal(err) } -log.Println("secret written successfully") + +log.Println("Secret written successfully.") ``` From 475465362b1964ab42fec62d47253b968933a84a Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:12:12 -0800 Subject: [PATCH 08/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 67fd85030843..b2639ac91ff8 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -540,9 +540,7 @@ curl \ ```go -ctx := context.Background() - -s, err := client.Secrets.KVv2Read(ctx, "my-secret") +s, err := client.Secrets.KVv2Read(context.Background(), "my-secret-password") if err != nil { log.Fatal(err) } From 8a0d033cb3bb79ec7c68d5b090ab524ed59f775f Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:12:21 -0800 Subject: [PATCH 09/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index b2639ac91ff8..55844037d48f 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -544,7 +544,8 @@ s, err := client.Secrets.KVv2Read(context.Background(), "my-secret-password") if err != nil { log.Fatal(err) } -log.Println("secret retrieved:", s.Data) + +log.Println("Secret retrieved:", s.Data) ``` From b43c582934ba0122a5a6561404274481fee179c4 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:32:04 -0800 Subject: [PATCH 10/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 55844037d48f..57a8aefabd45 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -199,7 +199,6 @@ import ( The Nuget packages are hosted in an internal Nuget feed that can be found in [Artifactory](https://artifactory.hashicorp.engineering/ui/repos/tree/General/vault-devex-nuget-local). You can use the Dotnet CLI or Nuget CLI to retrieve the package. -You need to add the private Nuget feed as a source in either CLI. You can also generate an [access token](https://www.jfrog.com/confluence/display/JFROG/User+Profile#UserProfile-IdentityTokenidentitytoken) that can be used in lieu of a password. ```shell-session $ nuget sources add \ From 8665817092e0fc2ad7e002a5115c80279141eaf6 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:32:15 -0800 Subject: [PATCH 11/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 57a8aefabd45..1e62771dbcdd 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -197,7 +197,7 @@ import ( [OpenAPI C#](https://github.com/hashicorp/vault-client-dotnet) (Beta) client library: -The Nuget packages are hosted in an internal Nuget feed that can be found in [Artifactory](https://artifactory.hashicorp.engineering/ui/repos/tree/General/vault-devex-nuget-local). You can use the Dotnet CLI or Nuget CLI to retrieve the package. +Vault is a package available at [Hashicorp Nuget](https://www.nuget.org/profiles/hashicorp). ```shell-session From ab244ecb955795950ce5d9d28af3df97ac4cd535 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:32:23 -0800 Subject: [PATCH 12/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 1e62771dbcdd..0a85f1441b42 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -201,7 +201,7 @@ Vault is a package available at [Hashicorp Nuget](https://www.nuget.org/profiles ```shell-session -$ nuget sources add \ + nuget install HashiCorp.Vault -Version "0.1.0-beta" -name HashicorpArtifactory \ -source https://artifactory.hashicorp.engineering/ui/repos/tree/General/vault-devex-nuget-local \ -username "myusername" \ From 718b190d4b8318f6ba03b670a66ae3aaf3f2078c Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:32:33 -0800 Subject: [PATCH 13/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 0a85f1441b42..ad06273e8167 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -211,7 +211,7 @@ Vault is a package available at [Hashicorp Nuget](https://www.nuget.org/profiles **Or:** ```shell-session -$ dotnet nuget add source https://artifactory.hashicorp.engineering/artifactory/api/nuget/v3/vault-devex-nuget-local \ +dotnet add package Hashicorp.Vault -version "0.1.0-beta" --name HashicorpArtifactory \ --username "myusername" \ --password "mypassword" From 4a23679b8f986299150b57eacba227c57da371da Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 10:46:45 -0800 Subject: [PATCH 14/21] Add code sample links for OpenAPI-based Go and .NET --- website/content/docs/get-started/developer-qs.mdx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index ad06273e8167..3a2ab5d0db59 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -15,6 +15,8 @@ The complete code samples for the steps below are available here: - [C#](https://github.com/hashicorp/vault-examples/blob/main/examples/_quick-start/dotnet/Example.cs) - [Python](https://github.com/hashicorp/vault-examples/blob/main/examples/_quick-start/python/example.py) - [Java (Spring)](https://github.com/hashicorp/vault-examples/blob/main/examples/_quick-start/java/Example.java) +- [OpenAPI-based Go](https://github.com/hashicorp/vault-client-go/#getting-started) +- [OpenAPI-based .NET](https://github.com/hashicorp/vault-client-dotnet/#getting-started) For an out-of-the-box runnable demo application showcasing these concepts and more, see the hello-vault repositories ([Go](https://github.com/hashicorp/hello-vault-go), [C#](https://github.com/hashicorp/hello-vault-dotnet) and [Java/Spring Boot](https://github.com/hashicorp/hello-vault-spring)). @@ -306,7 +308,7 @@ VaultTemplate vaultTemplate = new VaultTemplate( ```shell-session -export VAULT_TOKEN="dev-only-token" +$ export VAULT_TOKEN="dev-only-token" ``` @@ -417,7 +419,7 @@ System.out.println("Secret written successfully."); ```shell-session -curl \ +$ curl \ --header "X-Vault-Token: $VAULT_TOKEN" \ --header "Content-Type: application/json" \ --request POST \ @@ -530,7 +532,7 @@ if (readResponse != null && readResponse.hasData()) { ```shell-session -curl \ +$ curl \ --header "X-Vault-Token: $VAULT_TOKEN" \ http://127.0.0.1:8200/v1/secret/data/my-secret-password > secrets.json ``` @@ -617,7 +619,7 @@ System.out.println("Access granted!"); ```shell-session - cat secrets.json | jq '.data.data' +$ cat secrets.json | jq '.data.data' ``` From 432928cbd9c554e1ddd2978b5122dbe5f2529edf Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 18:39:22 -0800 Subject: [PATCH 15/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: Anton Averchenkov <84287187+averche@users.noreply.github.com> --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 3a2ab5d0db59..53a894111e20 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -316,7 +316,7 @@ $ export VAULT_TOKEN="dev-only-token" ```go client, err := vault.New( - vault.WithBaseAddress("http://127.0.0.1:8200"), + vault.WithAddress("http://127.0.0.1:8200"), vault.WithRequestTimeout(30*time.Second), ) if err != nil { From cbd2b0497886367e241b87dd400a813344e7b492 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 18:39:58 -0800 Subject: [PATCH 16/21] Remove command flags that are no longer needed --- website/content/docs/get-started/developer-qs.mdx | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 53a894111e20..d1f5c1051bfb 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -203,20 +203,13 @@ Vault is a package available at [Hashicorp Nuget](https://www.nuget.org/profiles ```shell-session - nuget install HashiCorp.Vault -Version "0.1.0-beta" - -name HashicorpArtifactory \ - -source https://artifactory.hashicorp.engineering/ui/repos/tree/General/vault-devex-nuget-local \ - -username "myusername" \ - -password "mypassword" +$ nuget install HashiCorp.Vault -Version "0.1.0-beta" ``` **Or:** ```shell-session -dotnet add package Hashicorp.Vault -version "0.1.0-beta" - --name HashicorpArtifactory \ - --username "myusername" \ - --password "mypassword" +$ dotnet add package Hashicorp.Vault -version "0.1.0-beta" ``` Now, let's add the import statements for the client library to the top of the file. From 022eafe6b7392e02d28535d2277495e403a0c6da Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Fri, 3 Mar 2023 19:17:05 -0800 Subject: [PATCH 17/21] Fix 'OpenAPI C#' > 'OpenAPI .NET' --- website/content/docs/get-started/developer-qs.mdx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index d1f5c1051bfb..9c422127fc46 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -194,10 +194,10 @@ import ( - + -[OpenAPI C#](https://github.com/hashicorp/vault-client-dotnet) (Beta) client library: +[OpenAPI .NET](https://github.com/hashicorp/vault-client-dotnet) (Beta) client library: Vault is a package available at [Hashicorp Nuget](https://www.nuget.org/profiles/hashicorp). @@ -322,7 +322,7 @@ if err := client.SetToken("dev-only-token"); err != nil { ``` - + ```cs string address = "http://127.0.0.1:8200"; @@ -437,7 +437,7 @@ log.Println("Secret written successfully.") ``` - + ```cs var secretData = new Dictionary { { "mypass", "pass" } }; @@ -543,7 +543,7 @@ log.Println("Secret retrieved:", s.Data) ``` - + ```cs VaultResponse resp = vaultClient.Secrets.KVv2Read("mypath"); From fabd973eb58fa1d80140ab8313b09266951157ea Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Wed, 8 Mar 2023 20:19:05 -0800 Subject: [PATCH 18/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 9c422127fc46..4904e9685368 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -329,7 +329,7 @@ string address = "http://127.0.0.1:8200"; VaultConfiguration config = new VaultConfiguration(address); VaultClient vaultClient = new VaultClient(config); -vaultClient.SetToken("my-token"); +vaultClient.SetToken("dev-only-token"); ``` From 67ea8302eb44dc868d8466e01b32ffb6d6eee533 Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Wed, 8 Mar 2023 20:19:21 -0800 Subject: [PATCH 19/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 4904e9685368..6174b7673a08 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -440,7 +440,7 @@ log.Println("Secret written successfully.") ```cs -var secretData = new Dictionary { { "mypass", "pass" } }; +var secretData = new Dictionary { { "password", "Hashi123" } }; // Write a secret var kvRequestData = new KVv2WriteRequest(secretData); From 3c721c084c95358ce149ae2d0f796ab0641a0cfc Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Wed, 8 Mar 2023 20:19:32 -0800 Subject: [PATCH 20/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 6174b7673a08..50e2ae81c08f 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -445,7 +445,7 @@ var secretData = new Dictionary { { "password", "Hashi123" } }; // Write a secret var kvRequestData = new KVv2WriteRequest(secretData); -vaultClient.Secrets.KVv2Write("mypath", kvRequestData); +vaultClient.Secrets.KVv2Write("my-secret-password", kvRequestData); ``` From c2c3c7c7e2cc4562e5fb24a4b99a8fd2581920cf Mon Sep 17 00:00:00 2001 From: Yoko Hyakuna Date: Wed, 8 Mar 2023 20:19:42 -0800 Subject: [PATCH 21/21] Update website/content/docs/get-started/developer-qs.mdx Co-authored-by: AnPucel --- website/content/docs/get-started/developer-qs.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index 50e2ae81c08f..c969ca89aa00 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -546,7 +546,7 @@ log.Println("Secret retrieved:", s.Data) ```cs -VaultResponse resp = vaultClient.Secrets.KVv2Read("mypath"); +VaultResponse resp = vaultClient.Secrets.KVv2Read("my-secret-password"); Console.WriteLine(resp.Data); ```