Шаблон SendGrid и Arm - PullRequest
       8

Шаблон SendGrid и Arm

0 голосов
/ 02 ноября 2018

Я добавил Send Grid API Key в настройки приложения следующим образом:

enter image description here

У меня есть шаблон ARM с элементом ресурсов, который включает в себя следующее:

"resources": [               
    {
       "apiVersion": "2016-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('apiApp').name)]"
        ],
        "properties": {
           "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(variables('dataResourceGroup').name, 'Microsoft.Insights/components', variables('dataAppInsights').name), '2014-04-01').InstrumentationKey]",
           "apiClientId": "[parameters('apiAppId')]",
           "prereqsKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-prereqs-', parameters('environmentAbbreviation'))]",
           "dataKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-data-', parameters('environmentAbbreviation'))]"
         }
     }
]

Как добавить SENDGRID_APIKEY в шаблон ARM и использовать его в программе, показанной ниже?

    private static void Main()
    {
        Execute().Wait();
    }
    static async Task Execute()
    {
        var apiKey = Environment.GetEnvironmentVariable("SENDGRID_APIKEY");
        var client = new SendGridClient(apiKey);
        var from = new EmailAddress("abc.com", "ABC");
        var subject = "Testing SendGrid";
        var to = new EmailAddress("xyz.com", "XYZ"); 
        var plainTextContent = "This is a test";
        var htmlContent = "test";
        var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
        var response = await client.SendEmailAsync(msg);
    }

1 Ответ

0 голосов
/ 02 ноября 2018

Я не понимаю вопроса, просто добавьте его как другую пару ключ / значение?

"resources": [               
    {
       "apiVersion": "2016-08-01",
        "name": "appsettings",
        "type": "config",
        "dependsOn": [
          "[resourceId('Microsoft.Web/sites', variables('apiApp').name)]"
        ],
        "properties": {
           "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId(variables('dataResourceGroup').name, 'Microsoft.Insights/components', variables('dataAppInsights').name), '2014-04-01').InstrumentationKey]",
           "apiClientId": "[parameters('apiAppId')]",
           "prereqsKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-prereqs-', parameters('environmentAbbreviation'))]",
           "dataKeyVaultName": "[concat(parameters('solutionAbbreviation'), '-data-', parameters('environmentAbbreviation'))]",
           "SENDGRIP_APIKEY": "somevalue"
         }
     }
]

если вы хотите передать его динамически, добавьте еще один параметр и назовите этот параметр, как и любой другой [parameters('sendgrid')]

...