protected override void Run() { if (Connection.IsConnected) { #if DEBUG Program.Invoke(Program.MainWindow, () => { // check that local SL creds have been moved to pool.other_config by StorageLinkConnectionManager. Settings.CslgCredentials localCrds = Settings.GetCslgCredentials(Connection); Debug.Assert(localCrds == null || string.IsNullOrEmpty(localCrds.Host)); }); #endif Pool pool = Helpers.GetPoolOfOne(Connection); pool.SetStorageLinkCredentials(_host, _username, _password); // other-config gets set on event thread. // so wait until other-config has been updated. WaitForUpdate(pool); // force an other-config change event. In case only the value of the secret has changed. Program.BeginInvoke(Program.MainWindow, () => pool.NotifyPropertyChanged("other_config")); foreach (PBD pbd in Connection.Cache.PBDs) { StorageLinkCredentials creds = pbd.GetStorageLinkCredentials(); if (creds != null && creds.Host == _host && creds.Username == _username) { creds.SetPassword(_password); } } } }
/// <summary> /// Moves deprecated locally stored StorageLink creds to the pool other-config. This can only be done by /// pool operators and above. /// </summary> private void MoveLocalCredentials() { // StorageLink credentials are stored in 3 places: // 1. In the device-config of any StorageLink PBDs. // 2. Locally in the Settings, once for each pool. This was a poor design choice in Midnight Ride. // 3. In the pool other-config. This is a replacement for the local settings. Implemented in Cowley. // This method moves locally stored settings to the pool other-config. This might not be // possible if the user doesn't have the privileges to do this. foreach (IXenConnection c in GetXenConnectionsCopy()) { Pool pool = Helpers.GetPoolOfOne(c); if (c.IsConnected && pool != null && Helpers.MidnightRideOrGreater(c) && !Helpers.FeatureForbidden(c, Host.RestrictStorageChoices)) { Settings.CslgCredentials localCreds = null; Invoke(() => localCreds = Settings.GetCslgCredentials(c)); if (localCreds != null && !string.IsNullOrEmpty(localCreds.Host) && !string.IsNullOrEmpty(localCreds.Username)) { StorageLinkCredentials creds = pool.GetStorageLinkCredentials(); if (creds == null || string.IsNullOrEmpty(creds.Host)) { // there aren't any creds on the pool object, but there are some locally. // Attempt to move them. try { string secretRef = Secret.get_by_uuid(c.Session, localCreds.PasswordSecret); string password = Secret.get_value(c.Session, secretRef); pool.SetStorageLinkCredentials(localCreds.Host, localCreds.Username, password); } catch (Failure) { } catch (WebException) { } } // remove the local creds. Invoke(() => Settings.SetCslgCredentials(c, new Settings.CslgCredentials(null, null, null))); } } } }
private StorageLinkCredentials GetStorageLinkCredentials(IXenConnection connection) { if (Helpers.BostonOrGreater(connection)) { return(null); } if (_storageLinkObject != null) { return(GetAllValidStorageLinkCreds().Find(c => c.Host == _storageLinkObject.StorageLinkConnection.Host && c.Username == _storageLinkObject.StorageLinkConnection.Username && c.Password == _storageLinkObject.StorageLinkConnection.Password)); } else { // just do a check that local creds have been correctly moved the server pool object. Settings.CslgCredentials localCreds = Settings.GetCslgCredentials(connection); Debug.Assert(localCreds == null || string.IsNullOrEmpty(localCreds.Host)); Pool pool = Helpers.GetPoolOfOne(connection); if (pool != null) { StorageLinkCredentials creds = pool.GetStorageLinkCredentials(); if (creds != null && creds.IsValid) { return(creds); } else { // if there aren't any creds then try importing from another pool. The user will probably only // have one set of CSLG creds and they just haven't set the creds to this pool yet. Do it for them. var credsList = GetAllValidStorageLinkCreds(); if (credsList.Count > 0 && !Helpers.BostonOrGreater(Connection)) { var action = new SetCslgCredentialsToPoolAction(pool.Connection, credsList[0].Host, credsList[0].Username, credsList[0].Password); new ActionProgressDialog(action, ProgressBarStyle.Marquee).ShowDialog(this); return(pool.GetStorageLinkCredentials()); } } } return(null); } }