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