You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn how to create, retrieve, and delete secrets from an Azure key vault using the Go client library
2
+
title: 'Quickstart: Manage secrets by using the Azure Key Vault Go client library'
3
+
description: Learn how to create, retrieve, and delete secrets from an Azure key vault by using the Go client library.
4
4
author: Duffney
5
5
ms.author: jduffney
6
6
ms.date: 12/29/2021
@@ -10,61 +10,60 @@ ms.topic: quickstart
10
10
ms.devlang: golang
11
11
---
12
12
13
-
# Quickstart: Azure Key Vault secret client library for Go
13
+
# Quickstart: Manage secrets by using the Azure Key Vault Go client library
14
14
15
-
In this quickstart, you'll learn to use the Azure SDK for Go to create, retrieve, list, and delete secrets from Azure Key Vault.
15
+
In this quickstart, you'll learn how to use the Azure SDK for Go to create, retrieve, list, and delete secrets from an Azure key vault.
16
16
17
-
Azure Key Vault can store [several objects types](../general/about-keys-secrets-certificates.md#object-types). But, this quickstart focuses on secrets. By using Azure Key Vault to store secrets, you avoid storing secrets in your code, which increases the security of your applications.
17
+
You can store a variety of [object types](../general/about-keys-secrets-certificates.md#object-types) in an Azure key vault. When you store secrets in a key vault, you avoid having to store them in your code, which helps improve the security of your applications.
18
18
19
-
Get started with the [azsecrets](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets) package and learn how to manage Azure Key Vault secrets using Go.
19
+
Get started with the [azsecrets](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets) package and learn how to manage your secrets in an Azure key vault by using Go.
20
20
21
21
## Prerequisites
22
22
23
-
- An Azure subscription -[create one for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
24
-
-**Go installed**: Version 1.16 or [above](https://golang.org/dl/)
25
-
-[Azure CLI](/cli/azure/install-azure-cli)
23
+
- An Azure subscription. If you don't already have a subscription, you can[create one for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
24
+
-[Go version 1.16 or later](https://golang.org/dl/), installed.
This quickstart uses the [azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity) package to authenticate to Azure using Azure CLI. To learn more about different methods of authentication, see [Azure authentication with the Azure SDK for Go](/azure/developer/go/azure-sdk-authentication).
29
+
For purposes of this quickstart, you use the [azidentity](https://pkg.go.dev/github.com/Azure/azure-sdk-for-go/sdk/azidentity) package to authenticate to Azure by using the Azure CLI. To learn about the various authentication methods, see [Azure authentication with the Azure SDK for Go](/azure/developer/go/azure-sdk-authentication).
30
30
31
-
### Sign into Azure
31
+
### Sign in to the Azure portal
32
32
33
-
1.Run the `az login` command:
33
+
1.In the Azure CLI, run the following command:
34
34
35
35
```azurecli-interactive
36
36
az login
37
37
```
38
38
39
-
If the CLI can open your default browser, it will do so and load an Azure sign-in page.
39
+
If the Azure CLI can open your default browser, it will do so on the Azure portal sign-in page.
40
40
41
-
Otherwise, open a browser page at [https://aka.ms/devicelogin](https://aka.ms/devicelogin) and enter the
42
-
authorization code displayed in your terminal.
41
+
If the page doesn't open automatically, go to [https://aka.ms/devicelogin](https://aka.ms/devicelogin), and then enter the authorization code that's displayed in your terminal.
43
42
44
-
1. Sign in with your account credentials in the browser.
43
+
1. Sign in to the Azure portal with your account credentials.
45
44
46
45
### Create a resource group and key vault instance
47
46
48
-
1. Run the following Azure CLI commands:
47
+
Run the following Azure CLI commands:
49
48
50
-
```azurecli
51
-
az group create --name quickstart-rg --location eastus
52
-
az keyvault create --name quickstart-kv --resource-group quickstart-rg
53
-
```
49
+
```azurecli
50
+
az group create --name quickstart-rg --location eastus
51
+
az keyvault create --name quickstart-kv --resource-group quickstart-rg
52
+
```
54
53
55
54
### Create a new Go module and install packages
56
55
57
-
1. Run the following Go commands:
56
+
Run the following Go commands:
58
57
59
-
```azurecli
60
-
go mod init kvSecrets
61
-
go get -u github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets
62
-
go get -u github.com/Azure/azure-sdk-for-go/sdk/azidentity
63
-
```
58
+
```azurecli
59
+
go mod init kvSecrets
60
+
go get -u github.com/Azure/azure-sdk-for-go/sdk/keyvault/azsecrets
61
+
go get -u github.com/Azure/azure-sdk-for-go/sdk/azidentity
62
+
```
64
63
65
64
## Code examples
66
65
67
-
This Code examples section shows how to create a client, set a secret, retrieve a secret, and delete a secret.
66
+
In the following sections, you create a client, set a secret, retrieve a secret, and delete a secret.
68
67
69
68
### Authenticate and create a client
70
69
@@ -80,7 +79,7 @@ if err != nil {
80
79
}
81
80
```
82
81
83
-
If you used a different Key Vault name, replace `quickstart-kv` with your vault's name.
82
+
If you used a different key vault name, replace `quickstart-kv` with that name.
84
83
85
84
### Create a secret
86
85
@@ -104,7 +103,7 @@ if err != nil {
104
103
fmt.Printf("secretValue: %s\n", *getResp.Value)
105
104
```
106
105
107
-
### Lists secrets
106
+
### List secrets
108
107
109
108
```go
110
109
pager:= client.ListSecrets(nil)
@@ -130,9 +129,9 @@ if err != nil {
130
129
}
131
130
```
132
131
133
-
## Sample Code
132
+
## Sample code
134
133
135
-
Create a file named `main.go` and copy the following code into the file:
134
+
Create a file named *main.go*, and then paste the following code into it:
136
135
137
136
```go
138
137
package main
@@ -205,28 +204,28 @@ func main() {
205
204
206
205
## Run the code
207
206
208
-
Before you run the code, create an environment variable named `KEY_VAULT_NAME`. Set the environment variable's value to the name of the Azure Key Vault created previously.
207
+
1.Before you run the code, create an environment variable named `KEY_VAULT_NAME`. Set the environment variable value to the name of the key vault that you created previously.
209
208
210
-
```azurecli
211
-
export KEY_VAULT_NAME=quickstart-kv
212
-
```
209
+
```azurecli
210
+
export KEY_VAULT_NAME=quickstart-kv
211
+
```
213
212
214
-
Run the following `go run` command to run the Go app:
213
+
1. To start the Go app, run the following command:
0 commit comments