Esempio n. 1
0
        public BlobContainerClient CreateStorageClient(BlobContainerClientOptions options, IAzureCredentialProvider provider = null)
        {
            EnsureArg.IsNotNull(options);
            var containerUri = EnsureArg.IsNotNull(options.BlobStorageContainerUri, nameof(options.BlobStorageContainerUri));
            var blobUri      = new BlobUriBuilder(containerUri);

            if (options.AuthenticationType == AuthenticationType.ManagedIdentity)
            {
                var tokenCredential = new DefaultAzureCredential();
                return(new BlobContainerClient(containerUri, tokenCredential));
            }
            else if (options.AuthenticationType == AuthenticationType.ConnectionString)
            {
                EnsureArg.IsNotNull(options.ConnectionString, nameof(options.ConnectionString));
                EnsureArg.IsNotNull(blobUri.BlobContainerName);

                return(new BlobContainerClient(options.ConnectionString, blobUri.BlobContainerName));
            }
            else if (options.AuthenticationType == AuthenticationType.Custom)
            {
                EnsureArg.IsNotNull(provider);

                var tokenCredential = provider.GetCredential();
                return(new BlobContainerClient(containerUri, tokenCredential));
            }
            else
            {
                var ex      = $"Unable to create blob container client for {blobUri}.";
                var message = "No authentication type was specified for BlobContainerClientOptions";
                throw new Exception($"{ex} {message}");
            }
        }
Esempio n. 2
0
        public BlobContainerClient CreateStorageClient(BlobContainerClientOptions options, IAzureCredentialProvider provider)
        {
            EnsureArg.IsNotNull(options);
            var containerUri = EnsureArg.IsNotNull(options.BlobStorageContainerUri);

            var tokenCredential = provider.GetCredential();

            return(new BlobContainerClient(containerUri, tokenCredential));
        }
Esempio n. 3
0
        public BlobContainerClient CreateStorageClient(BlobContainerClientOptions options)
        {
            EnsureArg.IsNotNull(options);
            var containerUri = EnsureArg.IsNotNull(options.BlobStorageContainerUri);
            var blobUri      = new BlobUriBuilder(containerUri);

            if (options.ServiceManagedIdentityAuth)
            {
                var tokenCredential = new DefaultAzureCredential();
                return(new BlobContainerClient(containerUri, tokenCredential));
            }
            else if (!string.IsNullOrEmpty(options.ConnectionString))
            {
                return(new BlobContainerClient(containerUri.ToString(), blobUri.BlobContainerName));
            }
            else
            {
                throw new Exception($"Unable to create blob container client for {blobUri}");
            }
        }