When building an app, you’d most likely create your own component file definitions, depending on the building block and specific component that you’d like to use.
In this tutorial, you will create a component definition file to interact with the secrets building block API:
Create a new directory named my-components
to hold the new secret and component file:
mkdir my-components
Navigate into this directory.
cd my-components
Dapr supports many types of secret stores, but for this tutorial, create a local JSON file named mysecrets.json
with the following secret:
{
"my-secret" : "I'm Batman"
}
Create a new file localSecretStore.yaml
with the following contents:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: my-secret-store
namespace: default
spec:
type: secretstores.local.file
version: v1
metadata:
- name: secretsFile
value: ./mysecrets.json
- name: nestedSeparator
value: ":"
In the above file definition:
type: secretstores.local.file
tells Dapr to use the local file component as a secret store.dapr run
.Launch a Dapr sidecar that will listen on port 3500 for a blank application named myapp
:
PowerShell environment:
dapr run --app-id myapp --dapr-http-port 3500 --resources-path ../
non-PowerShell environment:
dapr run --app-id myapp --dapr-http-port 3500 --resources-path .
If an error message occurs, stating the app-id
is already in use, you may need to stop any currently running Dapr sidecars. Stop the sidecar before running the next dapr run
command by either:
dapr stop
command in the terminal.In a separate terminal, run:
curl http://localhost:3500/v1.0/secrets/my-secret-store/my-secret
Invoke-RestMethod -Uri 'http://localhost:3500/v1.0/secrets/my-secret-store/my-secret'
Output:
{"my-secret":"I'm Batman"}