Commit c6a9d55d authored by suyanlong's avatar suyanlong

Add config information

parent dec3580b
Pipeline #8250 failed with stages
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"github.com/BurntSushi/toml"
"github.com/urfave/cli" "github.com/urfave/cli"
"gitlab.33.cn/link33/sidecar/internal/repo" "gitlab.33.cn/link33/sidecar/internal/repo"
...@@ -21,17 +22,42 @@ var initCMD = cli.Command{ ...@@ -21,17 +22,42 @@ var initCMD = cli.Command{
return err return err
} }
if tool.Exist(filepath.Join(repoRoot, repo.ConfigName)) { path := filepath.Join(repoRoot, repo.ConfigName)
if tool.Exist(path) {
fmt.Println("sidecar configuration file already exists") fmt.Println("sidecar configuration file already exists")
fmt.Println("reinitializing would overwrite your configuration, Y/N?") fmt.Println("reinitializing would overwrite your configuration, Y/N?")
input := bufio.NewScanner(os.Stdin) input := bufio.NewScanner(os.Stdin)
input.Scan() input.Scan()
if input.Text() == "Y" || input.Text() == "y" { if input.Text() == "Y" || input.Text() == "y" {
return repo.Initialize(repoRoot) err = repo.Initialize(repoRoot)
} }
return nil } else {
err = repo.Initialize(repoRoot)
} }
if err != nil {
return repo.Initialize(repoRoot) return err
}
return afterWork(ctx, path)
}, },
} }
func afterWork(ctx *cli.Context, path string) error {
id, err := LoadID(ctx)
if err != nil {
return err
}
config := &repo.Config{}
_, err = toml.DecodeFile(path, config)
if err != nil {
return err
}
if len(config.Peer.Peers) == 0 {
config.Peer.Peers = make([]string, 1)
}
config.Peer.Peers[0] = fmt.Sprintf("/ip4/127.0.0.1/tcp/4000/p2p/%s", id)
file, err := os.OpenFile(path, os.O_RDWR|os.O_TRUNC|os.O_CREATE, os.FileMode(0766))
if err != nil {
return err
}
return toml.NewEncoder(file).Encode(config)
}
...@@ -24,31 +24,34 @@ var p2pCMD = cli.Command{ ...@@ -24,31 +24,34 @@ var p2pCMD = cli.Command{
} }
func p2pID(ctx *cli.Context) error { func p2pID(ctx *cli.Context) error {
id, err := LoadID(ctx)
fmt.Println(id)
return err
}
func LoadID(ctx *cli.Context) (string, error) {
repoRoot, err := repo.PathRootWithDefault(ctx.GlobalString("repo")) repoRoot, err := repo.PathRootWithDefault(ctx.GlobalString("repo"))
if err != nil { if err != nil {
return err return "", err
} }
privKey, err := repo.LoadNodePrivateKey(repoRoot) privKey, err := repo.LoadNodePrivateKey(repoRoot)
if err != nil { if err != nil {
return err return "", err
} }
stdKey, err := asym.PrivKeyToStdKey(privKey) stdKey, err := asym.PrivKeyToStdKey(privKey)
if err != nil { if err != nil {
return err return "", err
} }
_, pk, err := crypto2.KeyPairFromStdKey(&stdKey) _, pk, err := crypto2.KeyPairFromStdKey(&stdKey)
if err != nil { if err != nil {
return err return "", err
} }
id, err := peer.IDFromPublicKey(pk) id, err := peer.IDFromPublicKey(pk)
if err != nil { if err != nil {
return err return "", err
} }
return id.String(), nil
fmt.Println(id)
return nil
} }
...@@ -3,6 +3,7 @@ module gitlab.33.cn/link33/sidecar ...@@ -3,6 +3,7 @@ module gitlab.33.cn/link33/sidecar
go 1.17 go 1.17
require ( require (
github.com/BurntSushi/toml v0.3.1
github.com/Rican7/retry v0.1.0 github.com/Rican7/retry v0.1.0
github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de
github.com/bits-and-blooms/bitset v1.2.1 github.com/bits-and-blooms/bitset v1.2.1
...@@ -29,8 +30,11 @@ require ( ...@@ -29,8 +30,11 @@ require (
github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd github.com/hashicorp/go-hclog v0.0.0-20180709165350-ff2cf002a8dd
github.com/hashicorp/go-multierror v1.1.0 github.com/hashicorp/go-multierror v1.1.0
github.com/hashicorp/go-plugin v1.3.0 github.com/hashicorp/go-plugin v1.3.0
github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e
github.com/huandu/skiplist v1.2.0 github.com/huandu/skiplist v1.2.0
github.com/huandu/xstrings v1.3.2 github.com/huandu/xstrings v1.3.2
github.com/hyperledger/fabric v2.0.1+incompatible
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986
github.com/imdario/mergo v0.3.12 github.com/imdario/mergo v0.3.12
github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-cid v0.0.7
github.com/jinzhu/copier v0.3.2 github.com/jinzhu/copier v0.3.2
...@@ -57,6 +61,7 @@ require ( ...@@ -57,6 +61,7 @@ require (
github.com/urfave/cli v1.22.1 github.com/urfave/cli v1.22.1
github.com/vmihailenco/msgpack/v5 v5.3.4 github.com/vmihailenco/msgpack/v5 v5.3.4
github.com/wangjia184/sortedset v0.0.0-20210325043434-64dd27e173e2 github.com/wangjia184/sortedset v0.0.0-20210325043434-64dd27e173e2
github.com/wasmerio/go-ext-wasm v0.3.1
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.33.1 google.golang.org/grpc v1.33.1
) )
...@@ -81,11 +86,8 @@ require ( ...@@ -81,11 +86,8 @@ require (
github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb // indirect
github.com/herumi/bls-eth-go-binary v0.0.0-20210917013441-d37c07cfda4e // indirect
github.com/huin/goupnp v1.0.0 // indirect github.com/huin/goupnp v1.0.0 // indirect
github.com/hyperledger/fabric v2.0.1+incompatible // indirect
github.com/hyperledger/fabric-amcl v0.0.0-20200424173818-327c9e2cf77a // indirect github.com/hyperledger/fabric-amcl v0.0.0-20200424173818-327c9e2cf77a // indirect
github.com/hyperledger/fabric-protos-go v0.0.0-20200330074707-cfe579e86986 // indirect
github.com/ipfs/go-datastore v0.4.4 // indirect github.com/ipfs/go-datastore v0.4.4 // indirect
github.com/ipfs/go-ipfs-util v0.0.1 // indirect github.com/ipfs/go-ipfs-util v0.0.1 // indirect
github.com/ipfs/go-ipns v0.0.2 // indirect github.com/ipfs/go-ipns v0.0.2 // indirect
...@@ -140,7 +142,6 @@ require ( ...@@ -140,7 +142,6 @@ require (
github.com/looplab/fsm v0.2.0 // indirect github.com/looplab/fsm v0.2.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect github.com/mattn/go-isatty v0.0.14 // indirect
github.com/meshplus/bitxhub-model v1.2.1-0.20210524063354-5d48e2fee178 // indirect
github.com/miekg/pkcs11 v1.0.3 // indirect github.com/miekg/pkcs11 v1.0.3 // indirect
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
github.com/minio/sha256-simd v0.1.1 // indirect github.com/minio/sha256-simd v0.1.1 // indirect
...@@ -171,14 +172,12 @@ require ( ...@@ -171,14 +172,12 @@ require (
github.com/spf13/jwalterweatherman v1.0.0 // indirect github.com/spf13/jwalterweatherman v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect github.com/subosito/gotenv v1.2.0 // indirect
github.com/supranational/blst v0.3.6 // indirect
github.com/sykesm/zap-logfmt v0.0.3 // indirect github.com/sykesm/zap-logfmt v0.0.3 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect github.com/syndtr/goleveldb v1.0.1-0.20210305035536-64b5b1c73954 // indirect
github.com/tidwall/match v1.0.3 // indirect github.com/tidwall/match v1.0.3 // indirect
github.com/tidwall/pretty v1.0.2 // indirect github.com/tidwall/pretty v1.0.2 // indirect
github.com/ugorji/go/codec v1.1.7 // indirect github.com/ugorji/go/codec v1.1.7 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/wasmerio/go-ext-wasm v0.3.1 // indirect
github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect github.com/whyrusleeping/go-keyspace v0.0.0-20160322163242-5b898ac5add1 // indirect
github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect github.com/whyrusleeping/multiaddr-filter v0.0.0-20160516205228-e903e4adabd7 // indirect
go.opencensus.io v0.22.3 // indirect go.opencensus.io v0.22.3 // indirect
......
...@@ -937,8 +937,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc ...@@ -937,8 +937,6 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s= github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw= github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
github.com/supranational/blst v0.3.6 h1:a24cPQB0qYpXPMZx177aapCM50/YrTMt/TKAUa7TzdM=
github.com/supranational/blst v0.3.6/go.mod h1:jZJtfjgudtNl4en1tzwPIV3KjUnQUvG3/j+w+fVonLw=
github.com/sykesm/zap-logfmt v0.0.3 h1:3Wrhf7+I9JEUD8B6KPtDAr9j2jrS0/EPLy7GCE1t/+U= github.com/sykesm/zap-logfmt v0.0.3 h1:3Wrhf7+I9JEUD8B6KPtDAr9j2jrS0/EPLy7GCE1t/+U=
github.com/sykesm/zap-logfmt v0.0.3/go.mod h1:AuBd9xQjAe3URrWT1BBDk2v2onAZHkZkWRMiYZXiZWA= github.com/sykesm/zap-logfmt v0.0.3/go.mod h1:AuBd9xQjAe3URrWT1BBDk2v2onAZHkZkWRMiYZXiZWA=
github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ= github.com/syndtr/goleveldb v1.0.0/go.mod h1:ZVVdQEZoIme9iO1Ch2Jdy24qqXrMMOU6lpPAyBWyWuQ=
......
...@@ -110,22 +110,22 @@ func DefaultConfig() *Config { ...@@ -110,22 +110,22 @@ func DefaultConfig() *Config {
Connectors: []string{}, Connectors: []string{},
Providers: 1, Providers: 1,
}, },
//Appchains: Appchains{[]Appchain{ Appchains: []Appchain{
// { {
// Enable: true, Enable: true,
// Type: "appchain", Type: "appchain",
// DID: "did:bitxhub:appchain:.", DID: "did:bitxhub:appchain:.",
// Plugin: "appchain_plugin", Plugin: "appchain_plugin",
// Config: "fabric", Config: "fabric",
// }, },
// { {
// Enable: true, Enable: true,
// Type: "hub", Type: "hub",
// DID: "did:bitxhub:chain33:.", DID: "did:bitxhub:chain33:.",
// Plugin: "appchain_plugin", Plugin: "appchain_plugin",
// Config: "chain33", Config: "chain33",
// }, },
//}}, },
} }
} }
......
...@@ -71,3 +71,6 @@ func Exist(path string) bool { ...@@ -71,3 +71,6 @@ func Exist(path string) bool {
// https://github.com/golang/groupcache // https://github.com/golang/groupcache
// https://github.com/bluele/gcache // https://github.com/bluele/gcache
// https://github.com/goburrow/cache // https://github.com/goburrow/cache
//Scan git repos (or files) for secrets using regex and entropy 🔑
//https://github.com/zricethezav/gitleaks
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment