mirror of https://github.com/dapr/docs.git
Added secrets store documentation
Signed-off-by: Amulya Varote <amulyavarote@Amulyas-MacBook-Pro.local>
This commit is contained in:
parent
4dbf126292
commit
f12b671731
|
@ -110,9 +110,16 @@ Once you have a secret store, call Dapr to get the secrets from your application
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
```csharp
|
```csharp
|
||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Net.Http;
|
||||||
|
using System.Net.Http.Headers;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Dapr.Client;
|
using Dapr.Client;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Text.Json;
|
||||||
|
|
||||||
//code
|
//code
|
||||||
namespace EventService
|
namespace EventService
|
||||||
|
@ -126,21 +133,24 @@ namespace EventService
|
||||||
//Using Dapr SDK to get a secret
|
//Using Dapr SDK to get a secret
|
||||||
var secret = await client.GetSecretAsync(SECRET_STORE_NAME, "secret");
|
var secret = await client.GetSecretAsync(SECRET_STORE_NAME, "secret");
|
||||||
Console.WriteLine($"Result: {string.Join(", ", secret)}");
|
Console.WriteLine($"Result: {string.Join(", ", secret)}");
|
||||||
Console.WriteLine($"Result for bulk: {string.Join(", ", secret.Keys)}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```java
|
```java
|
||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import io.dapr.client.DaprClient;
|
import io.dapr.client.DaprClient;
|
||||||
import io.dapr.client.DaprClientBuilder;
|
import io.dapr.client.DaprClientBuilder;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
//code
|
//code
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
|
@ -158,22 +168,23 @@ public class OrderProcessingServiceApplication {
|
||||||
log.info("Result: " + JSON_SERIALIZER.writeValueAsString(secret));
|
log.info("Result: " + JSON_SERIALIZER.writeValueAsString(secret));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```python
|
```python
|
||||||
|
|
||||||
#dependencies
|
#dependencies
|
||||||
|
import random
|
||||||
|
from time import sleep
|
||||||
|
import requests
|
||||||
|
import logging
|
||||||
from dapr.clients import DaprClient
|
from dapr.clients import DaprClient
|
||||||
from dapr.clients.grpc._state import StateItem
|
from dapr.clients.grpc._state import StateItem
|
||||||
from dapr.clients.grpc._request import TransactionalStateOperation, TransactionOperationType
|
from dapr.clients.grpc._request import TransactionalStateOperation, TransactionOperationType
|
||||||
|
|
||||||
#code
|
#code
|
||||||
logging.basicConfig(level = logging.INFO)
|
logging.basicConfig(level = logging.INFO)
|
||||||
|
|
||||||
DAPR_STORE_NAME = "localsecretstore"
|
DAPR_STORE_NAME = "localsecretstore"
|
||||||
key = 'secret'
|
key = 'secret'
|
||||||
|
|
||||||
|
@ -182,17 +193,16 @@ with DaprClient() as client:
|
||||||
secret = client.get_secret(store_name=DAPR_STORE_NAME, key=key)
|
secret = client.get_secret(store_name=DAPR_STORE_NAME, key=key)
|
||||||
logging.info('Result: ')
|
logging.info('Result: ')
|
||||||
logging.info(secret.secret)
|
logging.info(secret.secret)
|
||||||
|
#Using Dapr SDK to get bulk secrets
|
||||||
secret = client.get_bulk_secret(store_name=DAPR_STORE_NAME)
|
secret = client.get_bulk_secret(store_name=DAPR_STORE_NAME)
|
||||||
logging.info('Result for bulk secret: ')
|
logging.info('Result for bulk secret: ')
|
||||||
logging.info(sorted(secret.secrets.items()))
|
logging.info(sorted(secret.secrets.items()))
|
||||||
|
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
@ -209,7 +219,7 @@ func main() {
|
||||||
}
|
}
|
||||||
defer client.Close()
|
defer client.Close()
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
//Using Dapr SDK to get a secret
|
||||||
secret, err := client.GetSecret(ctx, SECRET_STORE_NAME, "secret", nil)
|
secret, err := client.GetSecret(ctx, SECRET_STORE_NAME, "secret", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Got error for accessing key")
|
return nil, errors.Wrap(err, "Got error for accessing key")
|
||||||
|
@ -219,7 +229,7 @@ func main() {
|
||||||
log.Println("Result : ")
|
log.Println("Result : ")
|
||||||
log.Println(secret)
|
log.Println(secret)
|
||||||
}
|
}
|
||||||
|
//Using Dapr SDK to get bulk secrets
|
||||||
secretRandom, err := client.GetBulkSecret(ctx, SECRET_STORE_NAME, nil)
|
secretRandom, err := client.GetBulkSecret(ctx, SECRET_STORE_NAME, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "Got error for accessing key")
|
return nil, errors.Wrap(err, "Got error for accessing key")
|
||||||
|
@ -230,14 +240,12 @@ func main() {
|
||||||
log.Println(secretRandom)
|
log.Println(secretRandom)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
{{% codetab %}}
|
{{% codetab %}}
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
|
||||||
//dependencies
|
//dependencies
|
||||||
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from 'dapr-client';
|
import { DaprClient, HttpMethod, CommunicationProtocolEnum } from 'dapr-client';
|
||||||
|
|
||||||
|
@ -247,14 +255,15 @@ const daprHost = "127.0.0.1";
|
||||||
async function main() {
|
async function main() {
|
||||||
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
const client = new DaprClient(daprHost, process.env.DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||||
const SECRET_STORE_NAME = "localsecretstore";
|
const SECRET_STORE_NAME = "localsecretstore";
|
||||||
|
//Using Dapr SDK to get a secret
|
||||||
var secret = await client.secret.get(SECRET_STORE_NAME, "secret");
|
var secret = await client.secret.get(SECRET_STORE_NAME, "secret");
|
||||||
console.log("Result: " + secret);
|
console.log("Result: " + secret);
|
||||||
|
//Using Dapr SDK to get bulk secrets
|
||||||
secret = await client.secret.getBulk(SECRET_STORE_NAME);
|
secret = await client.secret.getBulk(SECRET_STORE_NAME);
|
||||||
console.log("Result for bulk: " + secret);
|
console.log("Result for bulk: " + secret);
|
||||||
}
|
}
|
||||||
|
|
||||||
main();
|
main();
|
||||||
|
|
||||||
```
|
```
|
||||||
{{% /codetab %}}
|
{{% /codetab %}}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue