From 26112276db0ee00866af90b82edab99e732c9791 Mon Sep 17 00:00:00 2001 From: AnPucel Date: Wed, 29 Jun 2022 15:50:48 -0700 Subject: [PATCH] Add curl commands to Dev Quickstart guide (#16176) --- .../content/docs/get-started/developer-qs.mdx | 98 ++++--------------- 1 file changed, 20 insertions(+), 78 deletions(-) diff --git a/website/content/docs/get-started/developer-qs.mdx b/website/content/docs/get-started/developer-qs.mdx index d82e75eda2..19f99b5954 100644 --- a/website/content/docs/get-started/developer-qs.mdx +++ b/website/content/docs/get-started/developer-qs.mdx @@ -13,7 +13,7 @@ For an out-of-the-box runnable demo application showcasing these concepts and mo ## Prerequisites - [Docker](https://docs.docker.com/get-docker/) or a [local installation](https://learn.hashicorp.com/tutorials/vault/getting-started-install?in=vault/getting-started) of the Vault binary -- A development environment applicable to one of the languages in this quick start (currently **Go**, **Ruby**, **C#**, **Python**, and **Java (Spring)**) +- A development environment applicable to one of the languages in this quick start (currently **Go**, **Ruby**, **C#**, **Python**, **Java (Spring)**, and **Bash (curl)**) ## Step 1: Start Vault @@ -171,8 +171,6 @@ Paste the following code to initialize a new Vault client that will use token-ba - - ```go config := vault.DefaultConfig() @@ -186,10 +184,6 @@ if err != nil { client.SetToken("dev-only-token") ``` - - - - ```ruby Vault.configure do |config| config.address = "http://127.0.0.1:8200" @@ -197,10 +191,6 @@ Vault.configure do |config| end ``` - - - - ```cs IAuthMethodInfo authMethod = new TokenAuthMethodInfo(vaultToken: "dev-only-token"); @@ -209,10 +199,6 @@ VaultClientSettings("http://127.0.0.1:8200", authMethod); IVaultClient vaultClient = new VaultClient(vaultClientSettings); ``` - - - - ```Python client = hvac.Client( url='http://127.0.0.1:8200', @@ -220,10 +206,6 @@ client = hvac.Client( ) ``` - - - - ```Java VaultEndpoint vaultEndpoint = new VaultEndpoint(); @@ -237,7 +219,9 @@ VaultTemplate vaultTemplate = new VaultTemplate( ); ``` - +```shell-session +export VAULT_TOKEN="dev-only-token" +``` @@ -249,8 +233,6 @@ We'll use the Vault client we just initialized to write a secret to Vault, like - - ```go secretData := map[string]interface{}{ "password": "Hashi123", @@ -265,10 +247,6 @@ if err != nil { fmt.Println("Secret written successfully.") ``` - - - - ```ruby secret_data = {data: {password: "Hashi123"}} Vault.logical.write("secret/data/my-secret-password", secret_data) @@ -276,10 +254,6 @@ 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( @@ -291,10 +265,6 @@ 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', @@ -304,10 +274,6 @@ create_response = client.secrets.kv.v2.create_or_update_secret( print('Secret written successfully.') ``` - - - - ```Java Map data = new HashMap<>(); data.put("password", "Hashi123"); @@ -319,7 +285,14 @@ Versioned.Metadata createResponse = vaultTemplate System.out.println("Secret written successfully."); ``` - +```shell-session +curl \ + --header "X-Vault-Token: $VAULT_TOKEN" \ + --header "Content-Type: application/json" \ + --request POST \ + --data '{"data": {"password": "Hashi123"}}' \ + http://127.0.0.1:8200/v1/secret/data/my-secret-password +``` @@ -337,8 +310,6 @@ Underneath the line where you wrote a secret to Vault, let's add a few more line - - ```go secret, err := client.KVv2("secret").Get(context.Background(), "my-secret-password") if err != nil { @@ -351,19 +322,11 @@ 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", @@ -373,20 +336,12 @@ 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") @@ -398,7 +353,11 @@ 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 +``` @@ -406,8 +365,6 @@ Last, confirm that the value we unpacked from the read response is correct: - - ```go if value != "Hashi123" { log.Fatalf("unexpected password value %q retrieved from vault", value) @@ -416,20 +373,12 @@ if value != "Hashi123" { fmt.Println("Access granted!") ``` - - - - ```ruby abort "Unexpected password" if password != "Hashi123" puts "Access granted!" ``` - - - - ```cs if (password.ToString() != "Hashi123") { @@ -439,10 +388,6 @@ if (password.ToString() != "Hashi123") Console.WriteLine("Access granted!"); ``` - - - - ```Python if password != 'Hashi123': sys.exit('unexpected password') @@ -450,10 +395,6 @@ if password != 'Hashi123': print('Access granted!') ``` - - - - ```Java if (!password.equals("Hashi123")) { throw new Exception("Unexpected password"); @@ -462,8 +403,9 @@ 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.