/// <summary> /// Gets the appropriate cloud provider /// </summary> /// <returns>cloud provider</returns> public ICloudProvider Provider() { // Our cloud provider selection will be based on a config value "cloud" // that can be set in any of the configuration sources string cloudProvider = this.config.GetValue <string>("cloud"); /* * If we have a known cloud provider then we will instantiate the configuration and * attempt to bind the config object to configuration values by matching * property names against configuration keys recursively * https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-2.2 */ if (cloudProvider == "azure") { var cloudConfig = new AzureConfiguration(); this.config.Bind(cloudConfig); return(new AzureProvider(cloudConfig)); } else if (cloudProvider == "gcp") { var cloudConfig = new GoogleConfiguration(); this.config.Bind(cloudConfig); return(new GoogleProvider(cloudConfig)); } else if (cloudProvider == "development") { // Initialize the MockCloudProvider in development to facilitate api logic testing return(new MockCloudProvider(true)); } throw new ArgumentOutOfRangeException("cloud", "Empty or invalid"); }
/// <summary> /// Initializes a new instance of the <see cref="AzureStorageProvider" /> class /// </summary> /// <param name="cloud">Azure config</param> public AzureStorageProvider(AzureConfiguration cloud) { var storageAccount = cloud.GetStorageAccountAsync().Result; if (storageAccount == null) { throw new CloudErrorException(); } this.cloudBlobContainer = storageAccount.CreateCloudBlobClient().GetContainerReference(cloud.StorageFolder); this.cloudBlobContainer.CreateIfNotExists(); }
/// <summary> /// Initializes a new instance of the <see cref="AzureQueueProvider" /> class /// </summary> /// <param name="cloud">Azure cloud configuration</param> public AzureQueueProvider(AzureConfiguration cloud) { var storageAccount = cloud.GetStorageAccountAsync().Result; if (storageAccount == null) { throw new Exception("Azure Queue provider can't find storage account"); } var queueClient = storageAccount.CreateCloudQueueClient(); this.cloudQueue = queueClient.GetQueueReference(cloud.QueueName); this.cloudQueue.CreateIfNotExistsAsync(); }
/// <summary> /// Initializes a new instance of the <see cref="AzureAuthMiddleware" /> class /// </summary> /// <param name="cloud">Azure config</param> public AzureAuthMiddleware(AzureConfiguration cloud) { this.cloud = cloud; }