Materialize local cache on first remote open
This commit is contained in:
@@ -1104,6 +1104,9 @@ func (u *ui) openRemoteAction() error {
|
||||
if err := u.state.OpenRemoteVault(client, strings.TrimSpace(u.remotePath.Text()), key); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := u.materializeCurrentRemoteCache(); err != nil {
|
||||
return err
|
||||
}
|
||||
u.noteRecentRemote(
|
||||
strings.TrimSpace(u.remoteBaseURL.Text()),
|
||||
strings.TrimSpace(u.remotePath.Text()),
|
||||
@@ -1192,6 +1195,9 @@ func (u *ui) startOpenRemoteAction() {
|
||||
}
|
||||
return func() error {
|
||||
manager.ApplyPreparedRemoteOpen(prepared)
|
||||
if err := u.materializeCurrentRemoteCache(); err != nil {
|
||||
return err
|
||||
}
|
||||
u.noteRecentRemote(
|
||||
strings.TrimSpace(u.remoteBaseURL.Text()),
|
||||
remotePath,
|
||||
@@ -2097,6 +2103,42 @@ func (u *ui) saveCurrentRemoteBindingAction() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ui) materializeCurrentRemoteCache() error {
|
||||
cachePath := strings.TrimSpace(u.vaultPath.Text())
|
||||
if cachePath == "" {
|
||||
cachePath = u.saveAsTargetPath()
|
||||
}
|
||||
if cachePath == "" {
|
||||
return nil
|
||||
}
|
||||
u.vaultPath.SetText(cachePath)
|
||||
if err := u.state.SaveAs(cachePath); err != nil {
|
||||
return err
|
||||
}
|
||||
u.noteRecentVault(cachePath)
|
||||
|
||||
username := strings.TrimSpace(u.remoteUsername.Text())
|
||||
password := u.remotePassword.Text()
|
||||
if username == "" && password == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
input, err := u.currentRemoteBindingInput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
binding, err := u.state.ConfigureRemoteBinding(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := u.state.SaveAs(cachePath); err != nil {
|
||||
return err
|
||||
}
|
||||
u.selectedVaultRemoteProfileID = binding.RemoteProfileID
|
||||
u.selectedVaultRemoteCredentialEntryID = binding.CredentialEntryID
|
||||
return nil
|
||||
}
|
||||
|
||||
func (u *ui) bootstrapSelectedVaultRemoteBinding(key vault.MasterKey) (appstate.RemoteBinding, appstate.ResolvedRemoteBinding, bool, error) {
|
||||
if u.hasOpenVault() {
|
||||
return u.resolvedSelectedVaultRemoteBinding()
|
||||
|
||||
Reference in New Issue
Block a user