mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-02 03:27:54 +00:00
Add curl commands to Dev Quickstart guide (#16176)
This commit is contained in:
@@ -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
|
||||
|
||||
<CodeTabs heading="initialize a new vault client">
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```go
|
||||
config := vault.DefaultConfig()
|
||||
|
||||
@@ -186,10 +184,6 @@ if err != nil {
|
||||
client.SetToken("dev-only-token")
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```ruby
|
||||
Vault.configure do |config|
|
||||
config.address = "http://127.0.0.1:8200"
|
||||
@@ -197,10 +191,6 @@ Vault.configure do |config|
|
||||
end
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```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);
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Python
|
||||
client = hvac.Client(
|
||||
url='http://127.0.0.1:8200',
|
||||
@@ -220,10 +206,6 @@ client = hvac.Client(
|
||||
)
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Java
|
||||
VaultEndpoint vaultEndpoint = new VaultEndpoint();
|
||||
|
||||
@@ -237,7 +219,9 @@ VaultTemplate vaultTemplate = new VaultTemplate(
|
||||
);
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
```shell-session
|
||||
export VAULT_TOKEN="dev-only-token"
|
||||
```
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
@@ -249,8 +233,6 @@ We'll use the Vault client we just initialized to write a secret to Vault, like
|
||||
|
||||
<CodeTabs heading="write a secret to vault">
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```go
|
||||
secretData := map[string]interface{}{
|
||||
"password": "Hashi123",
|
||||
@@ -265,10 +247,6 @@ if err != nil {
|
||||
fmt.Println("Secret written successfully.")
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```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."
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```cs
|
||||
var secretData = new Dictionary<string, object> { { "password", "Hashi123" } };
|
||||
vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync(
|
||||
@@ -291,10 +265,6 @@ vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync(
|
||||
Console.WriteLine("Secret written successfully.");
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```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.')
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Java
|
||||
Map<String, String> data = new HashMap<>();
|
||||
data.put("password", "Hashi123");
|
||||
@@ -319,7 +285,14 @@ Versioned.Metadata createResponse = vaultTemplate
|
||||
System.out.println("Secret written successfully.");
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
```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
|
||||
```
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
@@ -337,8 +310,6 @@ Underneath the line where you wrote a secret to Vault, let's add a few more line
|
||||
|
||||
<CodeTabs heading="read a secret">
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```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
|
||||
}
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```ruby
|
||||
secret = Vault.logical.read("secret/data/my-secret-password")
|
||||
password = secret.data[:data][:password]
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```cs
|
||||
Secret<SecretData> secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(
|
||||
path: "/my-secret-password",
|
||||
@@ -373,20 +336,12 @@ Secret<SecretData> secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(
|
||||
var password = secret.Data.Data["password"];
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Python
|
||||
read_response = client.secrets.kv.read_secret_version(path='my-secret-password')
|
||||
|
||||
password = read_response['data']['data']['password']
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Java
|
||||
Versioned<Map<String, Object>> readResponse = vaultTemplate
|
||||
.opsForVersionedKeyValue("secret")
|
||||
@@ -398,7 +353,11 @@ if (readResponse != null && readResponse.hasData()) {
|
||||
}
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
```shell-session
|
||||
curl \
|
||||
--header "X-Vault-Token: $VAULT_TOKEN" \
|
||||
http://127.0.0.1:8200/v1/secret/data/my-secret-password > secrets.json
|
||||
```
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
@@ -406,8 +365,6 @@ Last, confirm that the value we unpacked from the read response is correct:
|
||||
|
||||
<CodeTabs heading="confirm value">
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```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!")
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```ruby
|
||||
abort "Unexpected password" if password != "Hashi123"
|
||||
|
||||
puts "Access granted!"
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```cs
|
||||
if (password.ToString() != "Hashi123")
|
||||
{
|
||||
@@ -439,10 +388,6 @@ if (password.ToString() != "Hashi123")
|
||||
Console.WriteLine("Access granted!");
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Python
|
||||
if password != 'Hashi123':
|
||||
sys.exit('unexpected password')
|
||||
@@ -450,10 +395,6 @@ if password != 'Hashi123':
|
||||
print('Access granted!')
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
<CodeBlockConfig lineNumbers>
|
||||
|
||||
```Java
|
||||
if (!password.equals("Hashi123")) {
|
||||
throw new Exception("Unexpected password");
|
||||
@@ -462,8 +403,9 @@ if (!password.equals("Hashi123")) {
|
||||
System.out.println("Access granted!");
|
||||
```
|
||||
|
||||
</CodeBlockConfig>
|
||||
|
||||
```shell-session
|
||||
cat secrets.json | jq '.data.data'
|
||||
```
|
||||
</CodeTabs>
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user