Other: Add vault editor CI tool

This commit is contained in:
James Houlahan
2022-10-26 10:11:25 +02:00
parent d376b88cf0
commit 784896434d
7 changed files with 127 additions and 6 deletions

View File

@ -163,13 +163,13 @@ func run(c *cli.Context) error { //nolint:funlen
// Handle crashes with various actions.
return withCrashHandler(restarter, reporter, func(crashHandler *crash.Handler) error {
// Load the locations where we store our files.
return withLocations(func(locations *locations.Locations) error {
return WithLocations(func(locations *locations.Locations) error {
// Initialize logging.
return withLogging(c, crashHandler, locations, func() error {
// Ensure we are the only instance running.
return withSingleInstance(locations, version, func() error {
// Unlock the encrypted vault.
return withVault(locations, func(vault *vault.Vault, insecure, corrupt bool) error {
return WithVault(locations, func(vault *vault.Vault, insecure, corrupt bool) error {
// Load the cookies from the vault.
return withCookieJar(vault, func(cookieJar http.CookieJar) error {
// Create a new bridge instance.
@ -245,8 +245,8 @@ func withLogging(c *cli.Context, crashHandler *crash.Handler, locations *locatio
return fn()
}
// Provide access to locations where we store our files.
func withLocations(fn func(*locations.Locations) error) error {
// WithLocations provides access to locations where we store our files.
func WithLocations(fn func(*locations.Locations) error) error {
// Create a locations provider to determine where to store our files.
provider, err := locations.NewDefaultProvider(filepath.Join(constants.VendorName, constants.ConfigName))
if err != nil {

View File

@ -30,7 +30,7 @@ import (
"golang.org/x/exp/slices"
)
func withVault(locations *locations.Locations, fn func(*vault.Vault, bool, bool) error) error {
func WithVault(locations *locations.Locations, fn func(*vault.Vault, bool, bool) error) error {
// Create the encVault.
encVault, insecure, corrupt, err := newVault(locations)
if err != nil {

View File

@ -0,0 +1,41 @@
// Copyright (c) 2022 Proton AG
//
// This file is part of Proton Mail Bridge.
//
// Proton Mail Bridge is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Proton Mail Bridge is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Proton Mail Bridge. If not, see <https://www.gnu.org/licenses/>.
//go:build debug
package vault
import (
"encoding/json"
)
func (vault *Vault) ImportJSON(dec []byte) {
vault.mod(func(data *Data) {
if err := json.Unmarshal(dec, data); err != nil {
panic(err)
}
})
}
func (vault *Vault) ExportJSON() []byte {
enc, err := json.MarshalIndent(vault.get(), "", " ")
if err != nil {
panic(err)
}
return enc
}