Exemplo n.º 1
0
        public bool TestPluginVaultConnection(string pluginName)
        {
            var plugin = _configDb.GetPluginByName(pluginName);

            if (_safeguardLogic.IsLoggedIn() && plugin?.VaultAccountId != null)
            {
                var pluginInstance = LoadedPlugins[pluginName];
                if (pluginInstance != null)
                {
                    try
                    {
                        RefreshPluginCredential(plugin);
                        if (pluginInstance.TestVaultConnection())
                        {
                            _logger.Error($"Test connection for plugin {pluginName} successful.");
                            return(true);
                        }
                    }
                    catch (Exception ex)
                    {
                        _logger.Error($"Failed to test the connection for plugin {pluginName}.  {ex.Message}");
                    }
                }
                else
                {
                    _logger.Error($"Failed to test the connection for plugin {pluginName}.  Plugin information is missing.");
                }
            }
            else
            {
                _logger.Error($"Failed to test the connection for plugin {pluginName}.  Missing login or vault account information.");
            }

            return(false);
        }
Exemplo n.º 2
0
        private void RefreshPluginCredential(Plugin plugin)
        {
            if (_safeguardLogic.IsLoggedIn() && plugin.VaultAccountId.HasValue)
            {
                try
                {
                    var a2aAccount = _safeguardLogic.GetA2ARetrievableAccount(plugin.VaultAccountId.Value,
                                                                              A2ARegistrationType.Vault);
                    if (a2aAccount != null)
                    {
                        SendPluginVaultCredentials(plugin.Name, a2aAccount.ApiKey);
                        return;
                    }

                    _logger.Error($"Failed to refresh the credential for plugin {plugin.Name} account {plugin.VaultAccountId}.");
                }
                catch (Exception ex)
                {
                    var msg = $"Failed to refresh the api key for {plugin.Name} account {plugin.VaultAccountId}: {ex.Message}";
                    _logger.Error(msg);
                }
            }
        }