mirror of https://github.com/dapr/quickstarts.git
Added secrets management examples with the workflow (#653)
* Added secrets management examples with the workflow Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Fixed syntax error for validation Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Increased time of the rollouts - distributed calc eg using k8s Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changed hello-kubernetes readme Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Changes based on the review comments Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Resolved merge conflicts Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Removed k8s installation from secrets mgnt Signed-off-by: Amulya Varote <amulyavarote@microsoft.com> * Removed dapr k8s installation from secrets mgnt Signed-off-by: Amulya Varote <amulyavarote@microsoft.com>
This commit is contained in:
parent
017da7db25
commit
cf3054f04e
|
@ -0,0 +1,106 @@
|
|||
#
|
||||
# Copyright 2021 The Dapr Authors
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
name: Validate Secrets Management
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
- feature/new_quickstarts
|
||||
- release-*
|
||||
tags:
|
||||
- v*
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
- feature/new_quickstarts
|
||||
- release-*
|
||||
jobs:
|
||||
deploy:
|
||||
name: Validate quickstarts on ${{ matrix.os }}
|
||||
runs-on: ${{ matrix.os }}
|
||||
env:
|
||||
DAPR_INSTALL_URL: https://raw.githubusercontent.com/dapr/cli/master/install
|
||||
GOVER: 1.17
|
||||
KUBERNETES_VERSION: v1.21.1
|
||||
KIND_VERSION: v0.11.0
|
||||
KIND_IMAGE_SHA: sha256:69860bda5563ac81e3c0057d654b5253219618a22ec3a346306239bba8cfa1a6
|
||||
strategy:
|
||||
matrix:
|
||||
os: [ubuntu-latest, macos-latest]
|
||||
steps:
|
||||
- name: Install docker - MacOS
|
||||
if: matrix.os == 'macos-latest'
|
||||
uses: docker-practice/actions-setup-docker@1.0.8
|
||||
with:
|
||||
docker_buildx: false
|
||||
docker_version: 20.10
|
||||
- name: Set up Go ${{ env.GOVER }}
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: ${{ env.GOVER }}
|
||||
- name: Determine latest Dapr Runtime version including Pre-releases
|
||||
run: |
|
||||
helm repo add dapr https://dapr.github.io/helm-charts/ && helm repo update && export RUNTIME_VERSION=$(helm search repo dapr/dapr --devel --versions | awk '/dapr\/dapr/ {print $3; exit}' )
|
||||
echo "DAPR_RUNTIME_VERSION=$RUNTIME_VERSION" >> $GITHUB_ENV
|
||||
echo "Found $RUNTIME_VERSION"
|
||||
shell: bash
|
||||
- name: Determine latest Dapr Cli version including Pre-releases
|
||||
run: |
|
||||
export CLI_VERSION=$(curl "https://api.github.com/repos/dapr/cli/releases?per_page=1&page=1" --header 'authorization: Bearer ${{ secrets.GITHUB_TOKEN }}' | jq '.[0].tag_name'| tr -d '",v')
|
||||
echo "DAPR_CLI_VERSION=$CLI_VERSION" >> $GITHUB_ENV
|
||||
echo "Found $CLI_VERSION"
|
||||
shell: bash
|
||||
- name: Set up Dapr CLI - Mac/Linux
|
||||
if: matrix.os != 'windows-latest'
|
||||
run: wget -q ${{ env.DAPR_INSTALL_URL }}/install.sh -O - | /bin/bash -s ${{ env.DAPR_CLI_VERSION }}
|
||||
- name: Set up Dapr CLI - Windows
|
||||
if: matrix.os == 'windows-latest'
|
||||
run: powershell -Command "\$$script=iwr -useb ${{ env.DAPR_INSTALL_URL }}/install.ps1; \$$block=[ScriptBlock]::Create(\$$script); invoke-command -ScriptBlock \$$block -ArgumentList ${{ env.DAPR_CLI_VERSION }}"
|
||||
- name: Install Dapr
|
||||
run: |
|
||||
export GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
||||
dapr init --runtime-version=${{ env.DAPR_RUNTIME_VERSION }}
|
||||
dapr --version
|
||||
- name: Check out code
|
||||
uses: actions/checkout@v2
|
||||
- name: Install utilities dependencies
|
||||
run: |
|
||||
echo "PATH=$PATH:$HOME/.local/bin" >> $GITHUB_ENV
|
||||
pip3 install setuptools wheel
|
||||
pip3 install mechanical-markdown
|
||||
- name: Validate Python http Secrets Management
|
||||
run: |
|
||||
pushd secrets_management/python/http
|
||||
make validate
|
||||
popd
|
||||
- name: Validate Python sdk Secrets Management
|
||||
run: |
|
||||
pushd secrets_management/python/sdk
|
||||
make validate
|
||||
popd
|
||||
- name: Validate Javascript http Secrets Management
|
||||
run: |
|
||||
pushd secrets_management/javascript/http
|
||||
make validate
|
||||
popd
|
||||
- name: Validate Javascript sdk Secrets Management
|
||||
run: |
|
||||
pushd secrets_management/javascript/sdk
|
||||
make validate
|
||||
popd
|
||||
- name: Linkcheck README.md
|
||||
run: |
|
||||
make validate
|
|
@ -0,0 +1,13 @@
|
|||
apiVersion: dapr.io/v1alpha1
|
||||
kind: Component
|
||||
metadata:
|
||||
name: localsecretstore
|
||||
namespace: default
|
||||
spec:
|
||||
type: secretstores.local.file
|
||||
version: v1
|
||||
metadata:
|
||||
- name: secretsFile
|
||||
value: secrets.json
|
||||
- name: nestedSeparator
|
||||
value: ":"
|
|
@ -0,0 +1,48 @@
|
|||
# Dapr secrets management (HTTP Client)
|
||||
|
||||
In this quickstart, you'll create a microservice to demonstrate Dapr's secrets management API. The service fetches secret from a secret store. See [Why secrets management](#why-secrets-management) to understand when to use this API.
|
||||
|
||||
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/secrets/) link for more information about Dapr and Secrets Management.
|
||||
|
||||
> **Note:** This example leverages HTTP `requests` only. If you are looking for the example using the Dapr Client SDK (recommended) [click here](../sdk/).
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Dotnet client service `order-processor`
|
||||
|
||||
### Run Dotnet service with Dapr
|
||||
|
||||
1. Open a new terminal window and navigate to `order-processor` directory:
|
||||
|
||||
<!-- STEP
|
||||
name: Install Dotnet dependencies
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
dotnet restore
|
||||
dotnet build
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
2. Run the Dotnet service app with Dapr:
|
||||
|
||||
<!-- STEP
|
||||
name: Run order-processor service
|
||||
expected_stdout_lines:
|
||||
- '== APP == Fetched Secret: {"secret":"YourPasskeyHere"}'
|
||||
- "Exited App successfully"
|
||||
expected_stderr_lines:
|
||||
output_match_mode: substring
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
dapr run --app-id order-processor --components-path ../../../components/ -- dotnet run
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
||||
```bash
|
||||
dapr stop --app-id order-processor
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
DOCKER_IMAGE_PREFIX ?=dotnet-http-
|
||||
APPS ?=order-processor
|
||||
|
||||
include ../../../docker.mk
|
||||
include ../../../validate.mk
|
|
@ -0,0 +1,15 @@
|
|||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
var baseURL = (Environment.GetEnvironmentVariable("BASE_URL") ?? "http://localhost") + ":"
|
||||
+ (Environment.GetEnvironmentVariable("DAPR_HTTP_PORT") ?? "3500");
|
||||
const string DAPR_SECRET_STORE = "localsecretstore";
|
||||
const string SECRET_NAME = "secret";
|
||||
|
||||
var httpClient = new HttpClient();
|
||||
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
|
||||
|
||||
// Get secret from a local secret store
|
||||
var secret = await httpClient.GetStringAsync($"{baseURL}/v1.0/secrets/{DAPR_SECRET_STORE}/{SECRET_NAME}");
|
||||
Console.WriteLine("Fetched Secret: " + secret);
|
|
@ -0,0 +1,10 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"secret": "YourPasskeyHere"
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
# Dapr secrets management
|
||||
|
||||
In this quickstart, you'll create a microservice to demonstrate Dapr's secrets management API. The service fetches secret from a secret store. See [Why secrets management](#why-secrets-management) to understand when to use this API.
|
||||
|
||||
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/secrets/) link for more information about Dapr and Secrets Management.
|
||||
|
||||
> **Note:** This example leverages the Dapr client SDK. If you are looking for the example using only HTTP [click here](../http).
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Dotnet client service `order-processor`
|
||||
|
||||
### Run Dotnet service with Dapr
|
||||
|
||||
1. Open a new terminal window and navigate to `order-processor` directory:
|
||||
|
||||
<!-- STEP
|
||||
name: Install Dotnet dependencies
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
dotnet restore
|
||||
dotnet build
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
2. Run the Dotnet service app with Dapr:
|
||||
|
||||
<!-- STEP
|
||||
name: Run order-processor service
|
||||
expected_stdout_lines:
|
||||
- '== APP == Fetched Secret: [secret, YourPasskeyHere]'
|
||||
- "Exited App successfully"
|
||||
expected_stderr_lines:
|
||||
output_match_mode: substring
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
dapr run --app-id order-processor --components-path ../../../components/ -- dotnet run
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
||||
```bash
|
||||
dapr stop --app-id order-processor
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
DOCKER_IMAGE_PREFIX ?=dotnet-sdk-
|
||||
APPS ?=order-processor
|
||||
|
||||
include ../../../docker.mk
|
||||
include ../../../validate.mk
|
|
@ -0,0 +1,11 @@
|
|||
using System;
|
||||
using Dapr.Client;
|
||||
|
||||
const string DAPR_SECRET_STORE = "localsecretstore";
|
||||
const string SECRET_NAME = "secret";
|
||||
var client = new DaprClientBuilder().Build();
|
||||
|
||||
// Get secret from a local secret store
|
||||
var secret = await client.GetSecretAsync(DAPR_SECRET_STORE, SECRET_NAME);
|
||||
var secretValue = string.Join(", ", secret);
|
||||
Console.WriteLine($"Fetched Secret: {secretValue}");
|
|
@ -0,0 +1,12 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Dapr.AspNetCore" Version="1.5.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"secret": "YourPasskeyHere"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
##lint files
|
||||
*.cjs
|
||||
|
||||
##node modules
|
||||
node_modules
|
|
@ -0,0 +1,47 @@
|
|||
# Dapr secrets management (HTTP Client)
|
||||
|
||||
In this quickstart, you'll create a microservice to demonstrate Dapr's secrets management API. The service fetches secret from a secret store. See [Why secrets management](#why-secrets-management) to understand when to use this API.
|
||||
|
||||
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/secrets/) link for more information about Dapr and Secrets Management.
|
||||
|
||||
> **Note:** This example leverages HTTP `requests` only. If you are looking for the example using the Dapr Client SDK (recommended) [click here](../sdk/).
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Node client service `order-processor`
|
||||
|
||||
### Run Node service with Dapr
|
||||
|
||||
1. Navigate to folder and install dependencies:
|
||||
|
||||
<!-- STEP
|
||||
name: Install Node dependencies
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
npm install
|
||||
```
|
||||
<!-- END_STEP -->
|
||||
|
||||
2. Run the Node service app with Dapr:
|
||||
|
||||
<!-- STEP
|
||||
name: Run Node publisher
|
||||
expected_stdout_lines:
|
||||
- "== APP == Fetched Secret: { secret: 'YourPasskeyHere' }"
|
||||
- "Exited App successfully"
|
||||
expected_stderr_lines:
|
||||
working_dir: ./order-processor
|
||||
output_match_mode: substring
|
||||
-->
|
||||
|
||||
```bash
|
||||
dapr run --app-id order-processor --components-path ../../../components/ -- npm start
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
||||
```bash
|
||||
dapr stop --app-id order-processor
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
DOCKER_IMAGE_PREFIX ?=javascript-http-
|
||||
APPS ?=order-processor
|
||||
|
||||
include ../../../docker.mk
|
||||
include ../../../validate.mk
|
|
@ -0,0 +1,14 @@
|
|||
import axios from "axios";
|
||||
|
||||
const DAPR_HOST = process.env.DAPR_HOST || "http://localhost";
|
||||
const DAPR_HTTP_PORT = process.env.DAPR_HTTP_PORT || "3500";
|
||||
const DAPR_SECRET_STORE = "localsecretstore";
|
||||
const SECRET_NAME = "secret";
|
||||
|
||||
async function main() {
|
||||
// Get secret from a local secret store
|
||||
const secret = await axios.get(`${DAPR_HOST}:${DAPR_HTTP_PORT}/v1.0/secrets/${DAPR_SECRET_STORE}/${SECRET_NAME}`);
|
||||
console.log("Fetched Secret: ", secret.data);
|
||||
}
|
||||
|
||||
main().catch(e => console.error(e))
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "order-processor",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"start:dapr": "dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm run start"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"axios": "^0.25.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.8.0",
|
||||
"eslint-plugin-react": "^7.28.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"secret": "YourPasskeyHere"
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
##lint files
|
||||
*.cjs
|
||||
|
||||
##node modules
|
||||
node_modules
|
|
@ -0,0 +1,51 @@
|
|||
# Dapr secrets management
|
||||
|
||||
In this quickstart, you'll create a microservice to demonstrate Dapr's secrets management API. The service fetches secret from a secret store. See [Why secrets management](#why-secrets-management) to understand when to use this API.
|
||||
|
||||
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/secrets/) link for more information about Dapr and Secrets Management.
|
||||
|
||||
> **Note:** This example leverages the Dapr client SDK. If you are looking for the example using only HTTP [click here](../http).
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Node client service `order-processor`
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Node client service `order-processor`
|
||||
|
||||
### Run Node service with Dapr
|
||||
|
||||
1. Navigate to folder and install dependencies:
|
||||
|
||||
<!-- STEP
|
||||
name: Install Node dependencies
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
npm install
|
||||
```
|
||||
<!-- END_STEP -->
|
||||
|
||||
2. Run the Node service app with Dapr:
|
||||
|
||||
<!-- STEP
|
||||
name: Run Node publisher
|
||||
expected_stdout_lines:
|
||||
- '== APP == Fetched Secret: {"secret":"YourPasskeyHere"}'
|
||||
- "Exited App successfully"
|
||||
expected_stderr_lines:
|
||||
working_dir: ./order-processor
|
||||
output_match_mode: substring
|
||||
-->
|
||||
|
||||
```bash
|
||||
dapr run --app-id order-processor --components-path ../../../components/ -- npm start
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
||||
```bash
|
||||
dapr stop --app-id order-processor
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
DOCKER_IMAGE_PREFIX ?=javascript-sdk-
|
||||
APPS ?=order-processor
|
||||
|
||||
include ../../../docker.mk
|
||||
include ../../../validate.mk
|
|
@ -0,0 +1,14 @@
|
|||
import { DaprClient, CommunicationProtocolEnum } from 'dapr-client';
|
||||
|
||||
const DAPR_HOST = process.env.DAPR_HOST || "http://localhost";
|
||||
const DAPR_HTTP_PORT = process.env.DAPR_HTTP_PORT || "3500";
|
||||
const DAPR_SECRET_STORE = "localsecretstore";
|
||||
const SECRET_NAME = "secret";
|
||||
|
||||
async function main() {
|
||||
const client = new DaprClient(DAPR_HOST, DAPR_HTTP_PORT, CommunicationProtocolEnum.HTTP);
|
||||
const secret = await client.secret.get(DAPR_SECRET_STORE, SECRET_NAME);
|
||||
console.log("Fetched Secret: " + JSON.stringify(secret));
|
||||
}
|
||||
|
||||
main().catch(e => console.error(e))
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"name": "order-processor",
|
||||
"version": "1.0.0",
|
||||
"description": "",
|
||||
"main": "index.js",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"start": "node index.js",
|
||||
"start:dapr": "dapr run --app-id checkout --app-protocol http --dapr-http-port 3500 -- npm run start"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"dapr-client": "^2.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^8.8.0",
|
||||
"eslint-plugin-react": "^7.28.0"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"secret": "YourPasskeyHere"
|
||||
}
|
|
@ -0,0 +1,47 @@
|
|||
# Dapr secrets management (HTTP client)
|
||||
|
||||
In this quickstart, you'll create a microservice to demonstrate Dapr's secrets management API. The service fetches secret from a secret store. See [Why secrets management](#why-secrets-management) to understand when to use this API.
|
||||
|
||||
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/secrets/) link for more information about Dapr and Secrets Management.
|
||||
|
||||
> **Note:** This example leverages HTTP `requests` only. If you are looking for the example using the Dapr Client SDK (recommended) [click here](../sdk/).
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Python service `order-processor`
|
||||
|
||||
### Run Python service with Dapr
|
||||
|
||||
1. Open a new terminal window and navigate to `order-processor` directory:
|
||||
|
||||
<!-- STEP
|
||||
name: Install python dependencies
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
2. Run the Python service app with Dapr:
|
||||
|
||||
<!-- STEP
|
||||
name: Run order-processor service
|
||||
expected_stdout_lines:
|
||||
- "== APP == INFO:root:Fetched Secret: {'secret': 'YourPasskeyHere'}"
|
||||
- "Exited App successfully"
|
||||
expected_stderr_lines:
|
||||
output_match_mode: substring
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
dapr run --app-id order-processor --components-path ../../../components/ -- python3 app.py
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
||||
```bash
|
||||
dapr stop --app-id order-processor
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
DOCKER_IMAGE_PREFIX ?=python-http-
|
||||
APPS ?=order-processor
|
||||
|
||||
include ../../../docker.mk
|
||||
include ../../../validate.mk
|
|
@ -0,0 +1,17 @@
|
|||
import time
|
||||
import logging
|
||||
import requests
|
||||
import os
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
base_url = os.getenv('BASE_URL', 'http://localhost') + ':' + os.getenv(
|
||||
'DAPR_HTTP_PORT', '3500')
|
||||
DAPR_SECRET_STORE = 'localsecretstore'
|
||||
SECRET_NAME = 'secret'
|
||||
|
||||
# Get secret from a local secret store
|
||||
secret = requests.get(
|
||||
url='%s/v1.0/secrets/%s/%s' % (base_url, DAPR_SECRET_STORE, SECRET_NAME)
|
||||
)
|
||||
logging.info('Fetched Secret: ' + str(secret.json()))
|
|
@ -0,0 +1 @@
|
|||
requests
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"secret": "YourPasskeyHere"
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
# Dapr secrets management
|
||||
|
||||
In this quickstart, you'll create a microservice to demonstrate Dapr's secrets management API. The service fetches secret from a secret store. See [Why secrets management](#why-secrets-management) to understand when to use this API.
|
||||
|
||||
Visit [this](https://docs.dapr.io/developing-applications/building-blocks/secrets/) link for more information about Dapr and Secrets Management.
|
||||
|
||||
> **Note:** This example leverages the Dapr client SDK. If you are looking for the example using only HTTP `requests` [click here](../http).
|
||||
|
||||
This quickstart includes one service:
|
||||
|
||||
- Python service `order-processor`
|
||||
|
||||
### Run Python service with Dapr
|
||||
|
||||
1. Open a new terminal window and navigate to `order-processor` directory:
|
||||
|
||||
<!-- STEP
|
||||
name: Install python dependencies
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
pip3 install -r requirements.txt
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
2. Run the Python service app with Dapr:
|
||||
|
||||
<!-- STEP
|
||||
name: Run order-processor service
|
||||
expected_stdout_lines:
|
||||
- "== APP == INFO:root:Fetched Secret: {'secret': 'YourPasskeyHere'}"
|
||||
- "Exited App successfully"
|
||||
expected_stderr_lines:
|
||||
output_match_mode: substring
|
||||
background: true
|
||||
sleep: 15
|
||||
-->
|
||||
|
||||
```bash
|
||||
cd ./order-processor
|
||||
dapr run --app-id order-processor --components-path ../../../components/ -- python3 app.py
|
||||
```
|
||||
|
||||
<!-- END_STEP -->
|
||||
|
||||
```bash
|
||||
dapr stop --app-id order-processor
|
||||
```
|
|
@ -0,0 +1,5 @@
|
|||
DOCKER_IMAGE_PREFIX ?=python-sdk-
|
||||
APPS ?=order-processor
|
||||
|
||||
include ../../../docker.mk
|
||||
include ../../../validate.mk
|
|
@ -0,0 +1,10 @@
|
|||
import logging
|
||||
from dapr.clients import DaprClient
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
|
||||
DAPR_SECRET_STORE = 'localsecretstore'
|
||||
SECRET_NAME = 'secret'
|
||||
with DaprClient() as client:
|
||||
secret = client.get_secret(store_name=DAPR_SECRET_STORE, key=SECRET_NAME)
|
||||
logging.info('Fetched Secret: %s', secret.secret)
|
|
@ -0,0 +1 @@
|
|||
dapr
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"secret": "YourPasskeyHere"
|
||||
}
|
|
@ -394,6 +394,8 @@ Each of the services will spin up a pod with two containers: one for your servic
|
|||
|
||||
<!-- STEP
|
||||
name: "Deploy Kubernetes"
|
||||
sleep: 60
|
||||
timeout_seconds: 50
|
||||
expected_stdout_lines:
|
||||
- 'deployment "addapp" successfully rolled out'
|
||||
- 'deployment "subtractapp" successfully rolled out'
|
||||
|
|
|
@ -96,7 +96,7 @@ component.dapr.io/statestore created
|
|||
|
||||
<!-- STEP
|
||||
name: Deploy Node App
|
||||
sleep: 90
|
||||
sleep: 70
|
||||
expected_stdout_lines:
|
||||
- "service/nodeapp created"
|
||||
- "deployment.apps/nodeapp created"
|
||||
|
|
Loading…
Reference in New Issue