-
-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RELEASE_NOTES=[BUGFIX] Improve convert output Fixes #2170 Signed-off-by: Dominik Schulz <dominik.schulz@gauner.org>
- Loading branch information
1 parent
16c071a
commit 77c93a8
Showing
9 changed files
with
125 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,91 @@ | ||
package action | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/gopasspw/gopass/internal/backend" | ||
"github.com/gopasspw/gopass/internal/backend/crypto/age" | ||
"github.com/gopasspw/gopass/internal/out" | ||
"github.com/gopasspw/gopass/pkg/ctxutil" | ||
"github.com/gopasspw/gopass/pkg/termio" | ||
"github.com/urfave/cli/v2" | ||
) | ||
|
||
// Convert converts a store to a different set of backends. | ||
func (s *Action) Convert(c *cli.Context) error { | ||
ctx := ctxutil.WithGlobalFlags(c) | ||
ctx = age.WithOnlyNative(ctx, true) | ||
|
||
store := c.String("store") | ||
move := c.Bool("move") | ||
storage, err := backend.StorageRegistry.Backend(c.String("storage")) | ||
|
||
sub, err := s.Store.GetSubStore(store) | ||
if err != nil { | ||
return err | ||
return fmt.Errorf("mount %q not found: %w", store, err) | ||
} | ||
|
||
oldStorage := sub.Storage().Name() | ||
|
||
storage, err := backend.StorageRegistry.Backend(oldStorage) | ||
if err != nil { | ||
return fmt.Errorf("unknown storage backend %q: %w", oldStorage, err) | ||
} | ||
if sv := c.String("storage"); sv != "" { | ||
var err error | ||
storage, err = backend.StorageRegistry.Backend(sv) | ||
if err != nil { | ||
return fmt.Errorf("unknown storage backend %q: %w", sv, err) | ||
} | ||
} | ||
|
||
oldCrypto := sub.Crypto().Name() | ||
|
||
crypto, err := backend.CryptoRegistry.Backend(oldCrypto) | ||
if err != nil { | ||
return fmt.Errorf("unknown crypto backend %q: %w", oldCrypto, err) | ||
} | ||
if sv := c.String("crypto"); sv != "" { | ||
var err error | ||
crypto, err = backend.CryptoRegistry.Backend(sv) | ||
if err != nil { | ||
return fmt.Errorf("unknown crypto backend %q: %w", sv, err) | ||
} | ||
} | ||
|
||
if oldCrypto == crypto.String() && oldStorage == storage.String() { | ||
out.Notice(ctx, "No conversion needed") | ||
|
||
return nil | ||
} | ||
|
||
if oldCrypto != crypto.String() { | ||
cbe, err := backend.NewCrypto(ctx, crypto) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := s.initCheckPrivateKeys(ctx, cbe); err != nil { | ||
return err | ||
} | ||
out.Printf(ctx, "Crypto %q has private keys", crypto.String()) | ||
} | ||
|
||
crypto, err := backend.CryptoRegistry.Backend(c.String("crypto")) | ||
out.Noticef(ctx, "Converting %q. Crypto: %q -> %q, Storage: %q -> %q", store, oldCrypto, crypto, oldStorage, storage) | ||
ok, err := termio.AskForBool(ctx, "Continue?", false) | ||
if err != nil { | ||
return err | ||
} | ||
if !ok { | ||
out.Notice(ctx, "Aborted") | ||
|
||
return nil | ||
} | ||
|
||
if err := s.Store.Convert(ctx, store, crypto, storage, move); err != nil { | ||
return fmt.Errorf("failed to convert %q: %w", store, err) | ||
} | ||
|
||
out.OKf(ctx, "Successfully converted %q", store) | ||
|
||
return s.Store.Convert(ctx, store, crypto, storage, move) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters