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}"); } }
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)); }
public EventProcessorClient CreateProcessorClient(BlobContainerClient blobContainerClient, EventHubClientOptions options, EventProcessorClientOptions eventProcessorClientOptions, IAzureCredentialProvider provider = null) { EnsureArg.IsNotNull(blobContainerClient); EnsureArg.IsNotNull(eventProcessorClientOptions); EnsureArg.IsNotNull(options); EnsureArg.IsNotNull(options.EventHubConsumerGroup, nameof(options.EventHubConsumerGroup)); if (options.AuthenticationType == AuthenticationType.ManagedIdentity) { EnsureArg.IsNotNull(options.EventHubNamespaceFQDN); EnsureArg.IsNotNull(options.EventHubName); var tokenCredential = new DefaultAzureCredential(); var eventHubFQDN = EventHubFormatter.GetEventHubFQDN(options.EventHubNamespaceFQDN); return(new EventProcessorClient(blobContainerClient, options.EventHubConsumerGroup, eventHubFQDN, options.EventHubName, tokenCredential, eventProcessorClientOptions)); } else if (options.AuthenticationType == AuthenticationType.ConnectionString) { EnsureArg.IsNotNull(options.ConnectionString); return(new EventProcessorClient(blobContainerClient, options.EventHubConsumerGroup, options.ConnectionString, eventProcessorClientOptions)); } else if (options.AuthenticationType == AuthenticationType.Custom) { EnsureArg.IsNotNull(options.EventHubNamespaceFQDN); EnsureArg.IsNotNull(options.EventHubName); EnsureArg.IsNotNull(provider); var eventHubFQDN = EventHubFormatter.GetEventHubFQDN(options.EventHubNamespaceFQDN); return(new EventProcessorClient(blobContainerClient, options.EventHubConsumerGroup, eventHubFQDN, options.EventHubName, provider.GetCredential(), eventProcessorClientOptions)); } else { var ex = $"Unable to create Event Hub processor client for {options.EventHubName}."; var message = "No authentication type was specified for EventHubClientOptions"; throw new Exception($"{ex} {message}"); } }
public EventHubProducerClient GetEventHubProducerClient(EventHubClientOptions options, IAzureCredentialProvider provider = null) { EnsureArg.IsNotNull(options); if (options.AuthenticationType == AuthenticationType.ManagedIdentity) { EnsureArg.IsNotNull(options.EventHubName); EnsureArg.IsNotNull(options.EventHubNamespaceFQDN); var tokenCredential = new DefaultAzureCredential(); var eventHubFQDN = EventHubFormatter.GetEventHubFQDN(options.EventHubNamespaceFQDN); return(new EventHubProducerClient(eventHubFQDN, options.EventHubName, tokenCredential)); } else if (options.AuthenticationType == AuthenticationType.ConnectionString) { EnsureArg.IsNotNull(options.ConnectionString); return(new EventHubProducerClient(options.ConnectionString)); } else if (options.AuthenticationType == AuthenticationType.Custom) { EnsureArg.IsNotNull(options.EventHubName); EnsureArg.IsNotNull(options.EventHubNamespaceFQDN); EnsureArg.IsNotNull(provider); var eventHubFQDN = EventHubFormatter.GetEventHubFQDN(options.EventHubNamespaceFQDN); return(new EventHubProducerClient(eventHubFQDN, options.EventHubName, provider.GetCredential())); } else { var ex = $"Unable to create Event Hub producer client for {options.EventHubName}"; var message = "No authentication type was specified for EventHubClientOptions."; throw new Exception($"{ex} {message}"); } }
public ManagedIdentityAuthService(IAzureCredentialProvider azureCredentialProvider) { _tokenCredential = azureCredentialProvider.GetCredential(); }