mirror of
https://github.com/hashicorp/vault.git
synced 2025-11-29 06:31:10 +01:00
Add curl commands to Dev Quickstart guide (#16176)
This commit is contained in:
parent
f241f300ef
commit
26112276db
@ -13,7 +13,7 @@ For an out-of-the-box runnable demo application showcasing these concepts and mo
|
|||||||
## Prerequisites
|
## 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
|
- [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
|
## 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">
|
<CodeTabs heading="initialize a new vault client">
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
config := vault.DefaultConfig()
|
config := vault.DefaultConfig()
|
||||||
|
|
||||||
@ -186,10 +184,6 @@ if err != nil {
|
|||||||
client.SetToken("dev-only-token")
|
client.SetToken("dev-only-token")
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
Vault.configure do |config|
|
Vault.configure do |config|
|
||||||
config.address = "http://127.0.0.1:8200"
|
config.address = "http://127.0.0.1:8200"
|
||||||
@ -197,10 +191,6 @@ Vault.configure do |config|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
IAuthMethodInfo authMethod = new TokenAuthMethodInfo(vaultToken: "dev-only-token");
|
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);
|
IVaultClient vaultClient = new VaultClient(vaultClientSettings);
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
client = hvac.Client(
|
client = hvac.Client(
|
||||||
url='http://127.0.0.1:8200',
|
url='http://127.0.0.1:8200',
|
||||||
@ -220,10 +206,6 @@ client = hvac.Client(
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Java
|
```Java
|
||||||
VaultEndpoint vaultEndpoint = new VaultEndpoint();
|
VaultEndpoint vaultEndpoint = new VaultEndpoint();
|
||||||
|
|
||||||
@ -237,7 +219,9 @@ VaultTemplate vaultTemplate = new VaultTemplate(
|
|||||||
);
|
);
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
```shell-session
|
||||||
|
export VAULT_TOKEN="dev-only-token"
|
||||||
|
```
|
||||||
|
|
||||||
</CodeTabs>
|
</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">
|
<CodeTabs heading="write a secret to vault">
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
secretData := map[string]interface{}{
|
secretData := map[string]interface{}{
|
||||||
"password": "Hashi123",
|
"password": "Hashi123",
|
||||||
@ -265,10 +247,6 @@ if err != nil {
|
|||||||
fmt.Println("Secret written successfully.")
|
fmt.Println("Secret written successfully.")
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
secret_data = {data: {password: "Hashi123"}}
|
secret_data = {data: {password: "Hashi123"}}
|
||||||
Vault.logical.write("secret/data/my-secret-password", secret_data)
|
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."
|
puts "Secret written successfully."
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
var secretData = new Dictionary<string, object> { { "password", "Hashi123" } };
|
var secretData = new Dictionary<string, object> { { "password", "Hashi123" } };
|
||||||
vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync(
|
vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync(
|
||||||
@ -291,10 +265,6 @@ vaultClient.V1.Secrets.KeyValue.V2.WriteSecretAsync(
|
|||||||
Console.WriteLine("Secret written successfully.");
|
Console.WriteLine("Secret written successfully.");
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
create_response = client.secrets.kv.v2.create_or_update_secret(
|
create_response = client.secrets.kv.v2.create_or_update_secret(
|
||||||
path='my-secret-password',
|
path='my-secret-password',
|
||||||
@ -304,10 +274,6 @@ create_response = client.secrets.kv.v2.create_or_update_secret(
|
|||||||
print('Secret written successfully.')
|
print('Secret written successfully.')
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Java
|
```Java
|
||||||
Map<String, String> data = new HashMap<>();
|
Map<String, String> data = new HashMap<>();
|
||||||
data.put("password", "Hashi123");
|
data.put("password", "Hashi123");
|
||||||
@ -319,7 +285,14 @@ Versioned.Metadata createResponse = vaultTemplate
|
|||||||
System.out.println("Secret written successfully.");
|
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>
|
</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">
|
<CodeTabs heading="read a secret">
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
secret, err := client.KVv2("secret").Get(context.Background(), "my-secret-password")
|
secret, err := client.KVv2("secret").Get(context.Background(), "my-secret-password")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -351,19 +322,11 @@ log.Fatalf("value type assertion failed: %T %#v", secret.Data["password"], secre
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
secret = Vault.logical.read("secret/data/my-secret-password")
|
secret = Vault.logical.read("secret/data/my-secret-password")
|
||||||
password = secret.data[:data][:password]
|
password = secret.data[:data][:password]
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
Secret<SecretData> secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(
|
Secret<SecretData> secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(
|
||||||
path: "/my-secret-password",
|
path: "/my-secret-password",
|
||||||
@ -373,20 +336,12 @@ Secret<SecretData> secret = vaultClient.V1.Secrets.KeyValue.V2.ReadSecretAsync(
|
|||||||
var password = secret.Data.Data["password"];
|
var password = secret.Data.Data["password"];
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
read_response = client.secrets.kv.read_secret_version(path='my-secret-password')
|
read_response = client.secrets.kv.read_secret_version(path='my-secret-password')
|
||||||
|
|
||||||
password = read_response['data']['data']['password']
|
password = read_response['data']['data']['password']
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Java
|
```Java
|
||||||
Versioned<Map<String, Object>> readResponse = vaultTemplate
|
Versioned<Map<String, Object>> readResponse = vaultTemplate
|
||||||
.opsForVersionedKeyValue("secret")
|
.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>
|
</CodeTabs>
|
||||||
|
|
||||||
@ -406,8 +365,6 @@ Last, confirm that the value we unpacked from the read response is correct:
|
|||||||
|
|
||||||
<CodeTabs heading="confirm value">
|
<CodeTabs heading="confirm value">
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```go
|
```go
|
||||||
if value != "Hashi123" {
|
if value != "Hashi123" {
|
||||||
log.Fatalf("unexpected password value %q retrieved from vault", value)
|
log.Fatalf("unexpected password value %q retrieved from vault", value)
|
||||||
@ -416,20 +373,12 @@ if value != "Hashi123" {
|
|||||||
fmt.Println("Access granted!")
|
fmt.Println("Access granted!")
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
abort "Unexpected password" if password != "Hashi123"
|
abort "Unexpected password" if password != "Hashi123"
|
||||||
|
|
||||||
puts "Access granted!"
|
puts "Access granted!"
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```cs
|
```cs
|
||||||
if (password.ToString() != "Hashi123")
|
if (password.ToString() != "Hashi123")
|
||||||
{
|
{
|
||||||
@ -439,10 +388,6 @@ if (password.ToString() != "Hashi123")
|
|||||||
Console.WriteLine("Access granted!");
|
Console.WriteLine("Access granted!");
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Python
|
```Python
|
||||||
if password != 'Hashi123':
|
if password != 'Hashi123':
|
||||||
sys.exit('unexpected password')
|
sys.exit('unexpected password')
|
||||||
@ -450,10 +395,6 @@ if password != 'Hashi123':
|
|||||||
print('Access granted!')
|
print('Access granted!')
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
|
||||||
|
|
||||||
<CodeBlockConfig lineNumbers>
|
|
||||||
|
|
||||||
```Java
|
```Java
|
||||||
if (!password.equals("Hashi123")) {
|
if (!password.equals("Hashi123")) {
|
||||||
throw new Exception("Unexpected password");
|
throw new Exception("Unexpected password");
|
||||||
@ -462,8 +403,9 @@ if (!password.equals("Hashi123")) {
|
|||||||
System.out.println("Access granted!");
|
System.out.println("Access granted!");
|
||||||
```
|
```
|
||||||
|
|
||||||
</CodeBlockConfig>
|
```shell-session
|
||||||
|
cat secrets.json | jq '.data.data'
|
||||||
|
```
|
||||||
</CodeTabs>
|
</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.
|
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.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user