Skip to content

Feature: add raw key file param #1522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/go/0chain.net/blobber/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
var (
deploymentMode int
keysFile string
keysFileRaw string
mountPoint string
metadataDB string
logDir string
Expand All @@ -24,6 +25,7 @@ var (
func init() {
flag.IntVar(&deploymentMode, "deployment_mode", 2, "deployment mode: 0=dev,1=test, 2=mainnet")
flag.StringVar(&keysFile, "keys_file", "", "keys_file")
flag.StringVar(&keysFileRaw, "keys_file_raw", "", "keys_file_raw")
flag.StringVar(&mountPoint, "files_dir", "", "Mounted partition where all files will be stored")
flag.StringVar(&metadataDB, "db_dir", "", "db_dir")
flag.StringVar(&logDir, "log_dir", "", "log_dir")
Expand Down
31 changes: 23 additions & 8 deletions code/go/0chain.net/blobber/node.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"errors"
"fmt"
"os"
Expand All @@ -18,15 +19,23 @@ var publicKey, privateKey string
func setupNode() error {
fmt.Println("> setup blobber")

err := readKeysFromAws()
if err != nil {
err = readKeysFromFile(&keysFile)
var err error

if keysFileRaw != "" {
err = readKeysFromString(&keysFileRaw)

fmt.Println("using blobber keys from local string")
} else {
err = readKeysFromAws()
if err != nil {
panic(err)
err = readKeysFromFile(&keysFile)
if err != nil {
panic(err)
}
fmt.Println("using blobber keys from local")
} else {
fmt.Println("using blobber keys from aws")
}
fmt.Println("using blobber keys from local")
} else {
fmt.Println("using blobber keys from aws")
}

node.Self.SetKeys(publicKey, privateKey)
Expand Down Expand Up @@ -72,6 +81,12 @@ func readKeysFromAws() error {
return nil
}

func readKeysFromString(keyFileRaw *string) error {
publicKey, privateKey, _, _ = encryption.ReadKeys(
bytes.NewBufferString(*keyFileRaw))
return nil
}

func readKeysFromFile(keysFile *string) error {
reader, err := os.Open(*keysFile)
if err != nil {
Expand All @@ -80,4 +95,4 @@ func readKeysFromFile(keysFile *string) error {
defer reader.Close()
publicKey, privateKey, _, _ = encryption.ReadKeys(reader)
return nil
}
}
Loading