Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use real secret in samples #19186

Merged
merged 1 commit into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ This sample shows how to use the library to create, retrieve, and delete Secret
To create a secret reference, use the `SecretReferenceConfigurationSetting` class:

```C# Snippet:Sample_CreateSecretReference
var secretReferenceSetting = new SecretReferenceConfigurationSetting("setting", new Uri("https://<keyvault_name>.vault.azure.net/secrets/<secret_name>"));
var secretId = "https://keyvault_name.vault.azure.net/secrets/<secret_name>";
var secretReferenceSetting = new SecretReferenceConfigurationSetting("setting", new Uri(secretId));
```

**NOTE** you can retrieve the secret identifier from the Azure Portal or using the `KeyVaultSecret.Id` property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ public class AppConfigurationTestEnvironment : TestEnvironment
{
public string ConnectionString => GetRecordedVariable("APPCONFIGURATION_CONNECTION_STRING", options => options.HasSecretConnectionStringParameter("secret", SanitizedValue.Base64));
public string Endpoint => GetRecordedVariable("APPCONFIGURATION_ENDPOINT_STRING");
public string SecretId => GetRecordedVariable("KEYVAULT_SECRET_URL");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public async Task CreateSecretReference()
var client = new ConfigurationClient(connectionString);

#region Snippet:Sample_CreateSecretReference
var secretReferenceSetting = new SecretReferenceConfigurationSetting("setting", new Uri("https://<keyvault_name>.vault.azure.net/secrets/<secret_name>"));
var secretId = "https://keyvault_name.vault.azure.net/secrets/<secret_name>";
/*@@*/ secretId = TestEnvironment.SecretId;
var secretReferenceSetting = new SecretReferenceConfigurationSetting("setting", new Uri(secretId));
#endregion

#region Snippet:Sample_SetSecretReference
Expand Down
44 changes: 42 additions & 2 deletions sdk/appconfiguration/test-resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
"variables": {
"roleDefinitionId": "[format('/subscriptions/{0}/providers/Microsoft.Authorization/roleDefinitions/5ae67dd6-50cb-40e7-96ff-dc2bfa4b606b', subscription().subscriptionId)]",
"uniqueAzConfigName": "[format('{0}-{1}', parameters('baseName'), parameters('azConfigPrefix'))]",
"endpointValue": "[format('https://{0}-{1}.azconfig.io', parameters('baseName'), parameters('azConfigPrefix'))]"
"endpointValue": "[format('https://{0}-{1}.azconfig.io', parameters('baseName'), parameters('azConfigPrefix'))]",
"azureKeyVaultSecretUrl": "[format('https://{0}.vault.azure.net/secrets/TestSecret', parameters('baseName'))]"
},
"resources": [
{
Expand All @@ -79,17 +80,56 @@
"roleDefinitionId": "[variables('roleDefinitionId')]",
"principalId": "[parameters('testApplicationOid')]"
}
},
{
"type": "Microsoft.KeyVault/vaults",
"apiVersion": "2016-10-01",
"name": "[parameters('baseName')]",
"location": "[parameters('location')]",
"properties": {
"sku": {
"family": "A",
"name": "premium"
},
"tenantId": "[parameters('tenantId')]",
"accessPolicies": [
{
"tenantId": "[parameters('tenantId')]",
"objectId": "[parameters('testApplicationOid')]",
"permissions": {
"secrets": [
"get"
]
}
}
]
}
},
{
"type": "Microsoft.KeyVault/vaults/secrets",
"name": "[concat(parameters('baseName'), '/TestSecret')]",
"apiVersion": "2016-10-01",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.KeyVault/vaults', parameters('baseName'))]"
],
"properties": {
"value": "Very secret value"
}
}
],
"outputs": {

"APPCONFIGURATION_CONNECTION_STRING": {
"type": "string",
"value": "[listKeys(resourceId('Microsoft.AppConfiguration/configurationStores',variables('uniqueAzConfigName')), '2019-02-01-preview').value[0].connectionString]"
},
"APPCONFIGURATION_ENDPOINT_STRING": {
"type": "string",
"value": "[variables('endpointValue')]"
},
"KEYVAULT_SECRET_URL": {
"type": "string",
"value": "[variables('azureKeyVaultSecretUrl')]"
}
}
}