0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

AzureでConfigurationSetting 、KeyVaultSecretを取得 (DIなし版)

Posted at
using System;
using System.Linq;
using Azure.Data.AppConfiguration;
using Azure.Identity;
using Azure.Security.KeyVault.Secrets;
using Microsoft.Azure.WebJobs;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace FunctionApp_v2_tf {
    public class Function1 {

        [FunctionName("Function1")]
        public void Run([TimerTrigger("0 */10 * * * *")] TimerInfo myTimer, ILogger log) {
            log.LogInformation($"C# Timer trigger function Started");

            DefaultAzureCredential credential = new DefaultAzureCredential(new DefaultAzureCredentialOptions());

            // AppConfig:Endpoint
            var configUrl = Environment.GetEnvironmentVariable("AppConfig:Endpoint", EnvironmentVariableTarget.Process);
            ConfigurationClient client = new ConfigurationClient(new Uri(configUrl), credential);
            ConfigurationSetting setting = client.GetConfigurationSetting("configs");
            log.LogInformation(@$"{setting.Value}");

            // KeyVault:Endpoint
            var keyVaultUrl = Environment.GetEnvironmentVariable("KeyVault:Endpoint", EnvironmentVariableTarget.Process);
            SecretClient keyVaultClient = new SecretClient(new Uri(keyVaultUrl), credential);
            KeyVaultSecret secret = keyVaultClient.GetSecret("dbkey");
            string dbkey = secret.Value;
            log.LogInformation(@$"{dbkey}");

        }
    }
}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?