public override async Task OpenAsync(string correlationId, List <ConnectionParams> connections, CredentialParams credential) { try { var connection = connections?.FirstOrDefault(); if (connection == null) { throw new ArgumentNullException(nameof(connections)); } _topicName = connection.GetAsNullableString("topic") ?? Name; _tempSubscriber = connection.Get("subscription") == null || connection.Get("Subscription") == null; _subscriptionName = connection.GetAsNullableString("subscription") ?? connection.Get("Subscription") ?? IdGenerator.NextLong(); // "AllMessages"; _connectionString = ConfigParams.FromTuples( "Endpoint", connection.GetAsNullableString("uri") ?? connection.GetAsNullableString("Endpoint"), "SharedAccessKeyName", credential.AccessId ?? credential.GetAsNullableString("shared_access_key_name") ?? credential.GetAsNullableString("SharedAccessKeyName"), "SharedAccessKey", credential.AccessKey ?? credential.GetAsNullableString("shared_access_key") ?? credential.GetAsNullableString("SharedAccessKey") ).ToString(); _namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString); _messageReceiver = new MessageReceiver(_connectionString, EntityNameHelper.FormatSubscriptionPath(_topicName, _subscriptionName)); } catch (Exception ex) { _namespaceManager = null; _logger.Error(correlationId, ex, $"Failed to open message topic '{Name}'."); } await Task.CompletedTask; }
public async override Task OpenAsync(string correlationId, ConnectionParams connection, CredentialParams credential) { try { var connectionString = ConfigParams.FromTuples( "DefaultEndpointsProtocol", connection.Protocol ?? connection.GetAsNullableString("DefaultEndpointsProtocol") ?? "https", "AccountName", credential.AccessId ?? credential.GetAsNullableString("account_name") ?? credential.GetAsNullableString("AccountName"), "AccountKey", credential.AccessKey ?? credential.GetAsNullableString("account_key") ?? credential.GetAsNullableString("AccountKey") ).ToString(); _logger.Info(null, "Connecting queue {0} to {1}", Name, connectionString); var storageAccount = CloudStorageAccount.Parse(connectionString); var client = storageAccount.CreateCloudQueueClient(); var queueName = connection.Get("queue") ?? Name; _queue = client.GetQueueReference(queueName); await _queue.CreateIfNotExistsAsync(); var deadName = connection.Get("dead"); _deadQueue = deadName != null?client.GetQueueReference(deadName) : null; } catch (Exception ex) { _queue = null; _logger.Error(correlationId, ex, $"Failed to open queue {Name}."); } await Task.Delay(0); }
public KeyVaultClient(ConnectionParams connection, CredentialParams credential) { _keyVault = connection.GetAsNullableString("key_vault") ?? connection.GetAsNullableString("uri") ?? connection.GetAsNullableString("KeyVault"); if (_keyVault == null) { throw new ArgumentNullException("KeyVault parameter is not defined"); } if (!_keyVault.StartsWith("http")) { _keyVault = "https://" + _keyVault + ".vault.azure.net"; } _clientId = credential.AccessId ?? credential.GetAsNullableString("ClientId"); if (_clientId == null) { throw new ArgumentNullException("CliendId parameter is not defined"); } _clientKey = credential.AccessKey ?? credential.GetAsNullableString("ClientKey"); _thumbPrint = credential.GetAsNullableString("thumbprint") ?? credential.GetAsNullableString("ThumbPrint"); if (_clientKey == null && _thumbPrint == null) { throw new ArgumentNullException("Neither ClientKey or ThumbPrint parameters are not defined"); } _client = new Microsoft.Azure.KeyVault.KeyVaultClient( new Microsoft.Azure.KeyVault.KeyVaultClient.AuthenticationCallback(GetAccessToken)); }
public override async Task OpenAsync(string correlationId, List <ConnectionParams> connections, CredentialParams credential) { try { var connection = connections?.FirstOrDefault(); if (connection == null) { throw new ArgumentNullException(nameof(connections)); } _queueName = connection.GetAsNullableString("queue") ?? Name; _connectionString = ConfigParams.FromTuples( "Endpoint", connection.GetAsNullableString("uri") ?? connection.GetAsNullableString("Endpoint"), "SharedAccessKeyName", credential.AccessId ?? credential.GetAsNullableString("SharedAccessKeyName"), "SharedAccessKey", credential.AccessKey ?? credential.GetAsNullableString("SharedAccessKey") ).ToString(); _logger.Info(null, "Connecting queue {0} to {1}", Name, _connectionString); _queueClient = new QueueClient(_connectionString, _queueName); _namespaceManager = NamespaceManager.CreateFromConnectionString(_connectionString); _messageReceiver = new MessageReceiver(_connectionString, _queueName); } catch (Exception ex) { _queueClient = null; _namespaceManager = null; _messageReceiver = null; _logger.Error(correlationId, ex, $"Failed to open queue '{Name}'."); } await Task.CompletedTask; }
private void UpdateConnection(ConnectionParams connection, CredentialParams credential) { if (string.IsNullOrEmpty(connection.Uri)) { var uri = connection.Protocol + "://" + connection.Host; if (connection.Port != 0) { uri += ":" + connection.Port; } connection.Uri = uri; } else { var uri = new Uri(connection.Uri); connection.Protocol = uri.Scheme; connection.Host = uri.Host; connection.Port = uri.Port; } if (connection.Protocol == "https") { connection.AddSection("credential", credential.GetAsNullableString("internal_network") == null ? credential : new CredentialParams()); } else { connection.AddSection("credential", new CredentialParams()); } }
private void ValidateConnection(string correlationId, ConnectionParams connection, CredentialParams credential) { if (connection == null) { throw new ConfigException(correlationId, "NO_CONNECTION", "HTTP connection is not set"); } var uri = connection.Uri; if (!string.IsNullOrEmpty(uri)) { return; } var protocol = connection.GetProtocolWithDefault("http"); if ("http" != protocol && "https" != protocol) { throw new ConfigException( correlationId, "WRONG_PROTOCOL", "Protocol is not supported by REST connection") .WithDetails("protocol", protocol); } var host = connection.Host; if (host == null) { throw new ConfigException(correlationId, "NO_HOST", "Connection host is not set"); } var port = connection.Port; if (port == 0) { throw new ConfigException(correlationId, "NO_PORT", "Connection port is not set"); } // Check HTTPS credentials if (protocol == "https") { // Check for credential if (credential == null) { throw new ConfigException( correlationId, "NO_CREDENTIAL", "SSL certificates are not configured for HTTPS protocol"); } // Sometimes when we use https we are on an internal network and do not want to have to deal with security. // When we need a https connection and we don't want to pass credentials, set the value 'no_credentials_needed' in the config yml credentials section if (credential.GetAsNullableString("internal_network") == null) { if (credential.GetAsNullableString("ssl_password") == null) { throw new ConfigException( correlationId, "NO_SSL_PASSWORD", "SSL password is not configured in credentials"); } if (credential.GetAsNullableString("ssl_pfx_file") == null) { throw new ConfigException( correlationId, "NO_SSL_PFX_FILE", "SSL pfx file is not configured in credentials"); } } } }