public BlobContainerFactory(IConfiguration configuration, ILoggerFactory loggerFactory)
        {
            _blobSettings  = configuration.GetConfiguredSettings <BlobStorageSettings>();
            _aadSettings   = configuration.GetConfiguredSettings <AadSettings>();
            _vaultSettings = configuration.GetConfiguredSettings <VaultSettings>();
            _logger        = loggerFactory.CreateLogger <BlobContainerFactory>();

            if (!TryCreateUsingMsi())
            {
                if (!TryCreateUsingSpn())
                {
                    if (!TryCreateFromKeyVault())
                    {
                        TryCreateUsingConnStr();
                    }
                }
            }
        }
Example #2
0
        public OldBlobClient(IConfiguration config, ILoggerFactory loggerFactory)
        {
            logger          = loggerFactory.CreateLogger <OldBlobClient>();
            storageSettings = config.GetConfiguredSettings <BlobStorageSettings>();
            logger.LogInformation(
                $"accessing blob (account={storageSettings.Account}, container={storageSettings.Container}) using default azure credential");
            var aadSettings        = config.GetConfiguredSettings <AadSettings>();
            var authBuilder        = new AadAuthBuilder(aadSettings);
            var clientSecretOrCert = authBuilder.GetClientSecretOrCert();

            logger.LogInformation($"Retrieving access token for aad client: {aadSettings.ClientId}");
            var tokenCredential = GetTokenCredential(
                aadSettings.Authority,
                $"https://{storageSettings.Account}.blob.core.windows.net/",
                aadSettings.ClientId,
                clientSecretOrCert.secret).GetAwaiter().GetResult();
            StorageCredentials storageCredentials = new StorageCredentials(tokenCredential);

            blobClient = new CloudBlobClient(storageSettings.BlobEndpointUri, storageCredentials);
        }