Add env unlocker (#350)

This commit is contained in:
Pietralberto Mazza
2024-10-05 16:33:55 +02:00
committed by GitHub
parent 0d39bb6b9f
commit bc8df6802e
4 changed files with 33 additions and 1 deletions

View File

@@ -81,6 +81,7 @@ func mainAction(_ *cli.Context) error {
BoardingExitDelay: cfg.BoardingExitDelay,
UnlockerType: cfg.UnlockerType,
UnlockerFilePath: cfg.UnlockerFilePath,
UnlockerPassword: cfg.UnlockerPassword,
}
svc, err := grpcservice.NewService(svcConfig, appConfig)
if err != nil {

View File

@@ -12,6 +12,7 @@ import (
timescheduler "github.com/ark-network/ark/server/internal/infrastructure/scheduler/gocron"
txbuilder "github.com/ark-network/ark/server/internal/infrastructure/tx-builder/covenant"
cltxbuilder "github.com/ark-network/ark/server/internal/infrastructure/tx-builder/covenantless"
envunlocker "github.com/ark-network/ark/server/internal/infrastructure/unlocker/env"
fileunlocker "github.com/ark-network/ark/server/internal/infrastructure/unlocker/file"
btcwallet "github.com/ark-network/ark/server/internal/infrastructure/wallet/btc-embedded"
liquidwallet "github.com/ark-network/ark/server/internal/infrastructure/wallet/liquid-standalone"
@@ -41,6 +42,7 @@ var (
"btcwallet": {},
}
supportedUnlockers = supportedType{
"env": {},
"file": {},
}
supportedNetworks = supportedType{
@@ -77,7 +79,8 @@ type Config struct {
BitcoindRpcHost string
UnlockerType string
UnlockerFilePath string
UnlockerFilePath string // file unlocker
UnlockerPassword string // env unlocker
repo ports.RepoManager
svc application.Service
@@ -394,6 +397,8 @@ func (c *Config) unlockerService() error {
switch c.UnlockerType {
case "file":
svc, err = fileunlocker.NewService(c.UnlockerFilePath)
case "env":
svc, err = envunlocker.NewService(c.UnlockerPassword)
default:
err = fmt.Errorf("unknown unlocker type")
}

View File

@@ -38,6 +38,7 @@ type Config struct {
TLSExtraDomains []string
UnlockerType string
UnlockerFilePath string
UnlockerPassword string
}
var (
@@ -69,6 +70,7 @@ var (
TLSExtraDomain = "TLS_EXTRA_DOMAIN"
UnlockerType = "UNLOCKER_TYPE"
UnlockerFilePath = "UNLOCKER_FILE_PATH"
UnlockerPassword = "UNLOCKER_PASSWORD"
defaultDatadir = common.AppDataDir("arkd", false)
defaultRoundInterval = 5
@@ -148,6 +150,7 @@ func LoadConfig() (*Config, error) {
TLSExtraDomains: viper.GetStringSlice(TLSExtraDomain),
UnlockerType: viper.GetString(UnlockerType),
UnlockerFilePath: viper.GetString(UnlockerFilePath),
UnlockerPassword: viper.GetString(UnlockerPassword),
}, nil
}

View File

@@ -0,0 +1,23 @@
package envunlocker
import (
"context"
"fmt"
"github.com/ark-network/ark/server/internal/core/ports"
)
type service struct {
password string
}
func NewService(password string) (ports.Unlocker, error) {
if len(password) <= 0 {
return nil, fmt.Errorf("missing password in env")
}
return &service{password}, nil
}
func (s *service) GetPassword(_ context.Context) (string, error) {
return s.password, nil
}