public Task Authenticate(string appliance) { if (_safeguardConnection != null) { _safeguardConnection.LogOut(); _safeguardConnection.Dispose(); } _safeguardConnection = LoginWindow.Connect(appliance); return(Task.CompletedTask); }
private IEnumerable <AccountMapping> GetAccountMappings(Configuration configuration) { ISafeguardConnection connection = null; try { connection = Safeguard.Connect(configuration.SppAddress, configuration.CertificateUserThumbPrint, _safeguardApiVersion, _safeguardIgnoreSsl); var rawJson = connection.InvokeMethod(Service.Core, Method.Get, $"A2ARegistrations/{configuration.A2ARegistrationId}/RetrievableAccounts"); var retrievableAccounts = JsonHelper.DeserializeObject <IEnumerable <RetrievableAccount> >(rawJson); var accountMappings = new List <AccountMapping>(); foreach (var account in retrievableAccounts) { accountMappings.Add(new AccountMapping() { AccountName = account.AccountName, ApiKey = account.ApiKey, VaultName = "" }); } return(accountMappings); } finally { connection?.Dispose(); } }
public IEnumerable <RetrievableAccount> GetRetrievableAccounts() { var configuration = _configurationRepository.GetConfiguration(); if (configuration == null) { _logger.Error("No configuration was found. DevOps service must be configured first"); return(null); } ISafeguardConnection connection = null; try { connection = Safeguard.Connect(configuration.SppAddress, configuration.CertificateUserThumbPrint, _safeguardApiVersion, _safeguardIgnoreSsl); var rawJson = connection.InvokeMethod(Service.Core, Method.Get, $"A2ARegistrations/{configuration.A2ARegistrationId}/RetrievableAccounts"); var retrievableAccounts = JsonHelper.DeserializeObject <IEnumerable <RetrievableAccount> >(rawJson); return(retrievableAccounts.ToList()); } catch (Exception ex) { _logger.Error($"Failed to get the retrievable accounts from SPP: {ex.Message}."); } finally { connection?.Dispose(); } return(null); }
public void Stop() { // shut everything down foreach (var listener in _listeners) { listener?.Stop(); listener?.Dispose(); } _connection?.Dispose(); _a2AContext?.Dispose(); }
public void Stop() { _eventListener.Stop(); _eventListener?.Dispose(); _connection?.Dispose(); _serviceNowPassword?.Dispose(); _validator?.Dispose(); _eventListener = null; _connection = null; _serviceNowPassword = null; _validator = null; }
protected override void Dispose(bool disposing) { if (_disposed || !disposing) { return; } try { base.Dispose(true); _connection?.Dispose(); } finally { _disposed = true; } }
private RetrievableAccount GetRetrievableAccount(Configuration configuration, string apiKey) { var apiKeyInfo = _configurationRepository.GetSetting(apiKey); ISafeguardConnection connection = null; try { connection = Safeguard.Connect(configuration.SppAddress, configuration.CertificateUserThumbPrint, _safeguardApiVersion, _safeguardIgnoreSsl); var rawJson = connection.InvokeMethod(Service.Core, Method.Get, $"A2ARegistrations/{configuration.A2ARegistrationId}/RetrievableAccounts/{apiKeyInfo.Value}"); var retrievableAccount = JsonHelper.DeserializeObject <IEnumerable <RetrievableAccount> >(rawJson); return(retrievableAccount?.FirstOrDefault()); } finally { connection?.Dispose(); } }
public Configuration InitialConfiguration(InitialConfiguration initialConfig) { //TODO: Create a new configuration element here //TODO: Check to see if there is already a configuration. If so, throw. //TODO: Get the registration and store the configuration in the database if (initialConfig == null) { throw new Exception("The initial configuration cannot be null."); } if (initialConfig.CertificateUserThumbprint == null) { throw new Exception("The user certificate thumbprint cannot be null."); } if (initialConfig.SppAddress == null) { throw new Exception("The SPP network address cannot be null."); } ISafeguardConnection connection = null; try { connection = Safeguard.Connect(initialConfig.SppAddress, initialConfig.CertificateUserThumbprint, _safeguardApiVersion, _safeguardIgnoreSsl); var rawJson = connection.InvokeMethod(Service.Core, Method.Get, "A2ARegistrations"); var registrations = JsonHelper.DeserializeObject <IEnumerable <SppRegistration> >(rawJson); // TODO: Assume that we only have one registration that belongs to the cert user var registration = registrations?.FirstOrDefault(); if (registration != null) { var configuration = new Configuration { SppAddress = initialConfig.SppAddress, A2ARegistrationId = registration.Id, A2ARegistrationName = registration.AppName, CertificateUser = registration.CertificateUser, CertificateUserThumbPrint = registration.CertificateUserThumbPrint, CreatedByUserId = registration.CreatedByUserId, CreatedByUserDisplayName = registration.CreatedByUserDisplayName, CreatedDate = registration.CreatedDate, AccountMapping = new List <AccountMapping>() }; _configurationRepository.SaveConfiguration(configuration); return(configuration); } else { _logger.Error("No A2A registrations were found for the configured certificate user"); } } catch (Exception ex) { _logger.Error($"Failed to initialize the DevOps Serivce: {ex.Message}"); } finally { connection?.Dispose(); } throw new Exception("Failed to configure devops."); }