From 7e8cde11a3896677419511b50000f6553fd0f3ae Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 16:27:47 +0800 Subject: [PATCH 01/28] Add osusergo build tag --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 54ab5bef7..34a2a0e4a 100644 --- a/Makefile +++ b/Makefile @@ -126,8 +126,8 @@ endif version := $(branch)-$(GIT_COMMIT)-$(builddate) -tags := $(platform) sqlite_omit_load_extension -testtags := $(platform) sqlite_omit_load_extension testbinary +tags := $(platform) sqlite_omit_load_extension osusergo +testtags := $(tags) testbinary test_flags := -coverpkg github.com/CovenantSQL/CovenantSQL/... -cover -race -c ldflags_role_bp := -X main.version=$(version) -X github.com/CovenantSQL/CovenantSQL/conf.RoleTag=B $$GOLDFLAGS From 15ea0a0df68f92574dae1619cd51dbaf4776c3db Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 16:40:08 +0800 Subject: [PATCH 02/28] Add HomeDirExpand func in utils for home dir(~) expand --- utils/path.go | 14 ++++++++++++++ utils/path_test.go | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/utils/path.go b/utils/path.go index 3b2e44192..624d7dab8 100644 --- a/utils/path.go +++ b/utils/path.go @@ -19,7 +19,9 @@ package utils import ( "io" "os" + "os/user" "path/filepath" + "strings" ) // CopyFile copies from src to dst until either EOF is reached @@ -46,3 +48,15 @@ func CopyFile(src, dst string) (int64, error) { defer df.Close() return io.Copy(df, sf) } + +// HomeDirExpand expands the tilde (~) in the front of a path to a the supplied +// directory. +func HomeDirExpand(u *user.User, path string) string { + if path == "~" { + return u.HomeDir + } else if strings.HasPrefix(path, "~/") { + return filepath.Join(u.HomeDir, strings.TrimPrefix(path, "~/")) + } + + return path +} diff --git a/utils/path_test.go b/utils/path_test.go index b0c4fa8b3..62016f528 100644 --- a/utils/path_test.go +++ b/utils/path_test.go @@ -19,6 +19,7 @@ package utils import ( "io/ioutil" "os" + "os/user" "testing" . "github.com/smartystreets/goconvey/convey" @@ -47,3 +48,19 @@ func TestCopyFile(t *testing.T) { So(n, ShouldBeZeroValue) }) } + +func TestHomeDirExpand(t *testing.T) { + Convey("expand ~ dir", t, func() { + usr, err := user.Current() + So(err, ShouldBeNil) + + homeDir := HomeDirExpand(usr, "~") + So(homeDir, ShouldEqual, usr.HomeDir) + + fullFilepathWithHome := HomeDirExpand(usr, "~/.local") + So(fullFilepathWithHome, ShouldEqual, usr.HomeDir+"/.local") + + fullFilepathRaw := HomeDirExpand(usr, "/dev/null") + So(fullFilepathRaw, ShouldEqual, "/dev/null") + }) +} From fe4c4e955b507f9700526cf93163b2ac28783241 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 17:15:28 +0800 Subject: [PATCH 03/28] Remove user params in HomeDirExpand func. --- utils/path.go | 15 ++++++++++----- utils/path_test.go | 6 +++--- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/utils/path.go b/utils/path.go index 624d7dab8..e0ad6f19c 100644 --- a/utils/path.go +++ b/utils/path.go @@ -49,13 +49,18 @@ func CopyFile(src, dst string) (int64, error) { return io.Copy(df, sf) } -// HomeDirExpand expands the tilde (~) in the front of a path to a the supplied -// directory. -func HomeDirExpand(u *user.User, path string) string { +// HomeDirExpand tries to expand the tilde (~) in the front of a path +// to a fullpath directory. +func HomeDirExpand(path string) string { + usr, err := user.Current() + if err != nil { + return path + } + if path == "~" { - return u.HomeDir + return usr.HomeDir } else if strings.HasPrefix(path, "~/") { - return filepath.Join(u.HomeDir, strings.TrimPrefix(path, "~/")) + return filepath.Join(usr.HomeDir, strings.TrimPrefix(path, "~/")) } return path diff --git a/utils/path_test.go b/utils/path_test.go index 62016f528..04ff56d6f 100644 --- a/utils/path_test.go +++ b/utils/path_test.go @@ -54,13 +54,13 @@ func TestHomeDirExpand(t *testing.T) { usr, err := user.Current() So(err, ShouldBeNil) - homeDir := HomeDirExpand(usr, "~") + homeDir := HomeDirExpand("~") So(homeDir, ShouldEqual, usr.HomeDir) - fullFilepathWithHome := HomeDirExpand(usr, "~/.local") + fullFilepathWithHome := HomeDirExpand("~/.local") So(fullFilepathWithHome, ShouldEqual, usr.HomeDir+"/.local") - fullFilepathRaw := HomeDirExpand(usr, "/dev/null") + fullFilepathRaw := HomeDirExpand("/dev/null") So(fullFilepathRaw, ShouldEqual, "/dev/null") }) } From fd58b891626e36c2d6fa185c367d0505e3cc1cd8 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 17:33:32 +0800 Subject: [PATCH 04/28] Remove unreachable code. --- client/driver.go | 1 - 1 file changed, 1 deletion(-) diff --git a/client/driver.go b/client/driver.go index 5af1ace39..09b2a93d9 100644 --- a/client/driver.go +++ b/client/driver.go @@ -410,7 +410,6 @@ func WaitTxConfirmation( return } } - return } func getNonce(addr proto.AccountAddress) (nonce interfaces.AccountNonce, err error) { From cd71df90b55b0e4358b092b30e4d94c96fdca882 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 19:53:28 +0800 Subject: [PATCH 05/28] Change cql-utils use ~/.cql as config.yaml/private.key default location. --- cmd/cql-utils/confgen.go | 4 +++- cmd/cql-utils/main.go | 8 ++++++-- utils/path_test.go | 3 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/cql-utils/confgen.go b/cmd/cql-utils/confgen.go index cc7aa8ee6..940b19f18 100644 --- a/cmd/cql-utils/confgen.go +++ b/cmd/cql-utils/confgen.go @@ -27,6 +27,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/conf/testnet" "github.com/CovenantSQL/CovenantSQL/proto" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" yaml "gopkg.in/yaml.v2" ) @@ -36,10 +37,11 @@ var ( ) func init() { - flag.StringVar(&workingRoot, "root", "conf", "confgen root is the working root directory containing all auto-generating keys and certifications") + flag.StringVar(&workingRoot, "root", "~/.cql", "confgen root is the working root directory containing all auto-generating keys and certifications") } func runConfgen() { + workingRoot = utils.HomeDirExpand(workingRoot) if workingRoot == "" { log.Error("root directory is required for confgen") os.Exit(1) diff --git a/cmd/cql-utils/main.go b/cmd/cql-utils/main.go index ce94a3dd8..3c027fd4b 100644 --- a/cmd/cql-utils/main.go +++ b/cmd/cql-utils/main.go @@ -23,6 +23,7 @@ import ( "runtime" "syscall" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "golang.org/x/crypto/ssh/terminal" ) @@ -44,8 +45,8 @@ func init() { flag.StringVar(&tool, "tool", "", "tool type, miner, keygen, keytool, rpc, nonce, confgen, addrgen, adapterconfgen") flag.StringVar(&publicKeyHex, "public", "", "public key hex string to mine node id/nonce") - flag.StringVar(&privateKeyFile, "private", "private.key", "private key file to generate/show") - flag.StringVar(&configFile, "config", "config.yaml", "config file to use") + flag.StringVar(&privateKeyFile, "private", "~/.cql/private.key", "private key file to generate/show") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "config file to use") flag.BoolVar(&skipMasterKey, "skip-master-key", false, "use empty master key") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") } @@ -59,6 +60,9 @@ func main() { } log.Infof("cql-utils build: %#v\n", version) + configFile = utils.HomeDirExpand(configFile) + privateKeyFile = utils.HomeDirExpand(privateKeyFile) + switch tool { case "miner": if publicKeyHex == "" && privateKeyFile == "" { diff --git a/utils/path_test.go b/utils/path_test.go index 04ff56d6f..fe1cad44a 100644 --- a/utils/path_test.go +++ b/utils/path_test.go @@ -62,5 +62,8 @@ func TestHomeDirExpand(t *testing.T) { fullFilepathRaw := HomeDirExpand("/dev/null") So(fullFilepathRaw, ShouldEqual, "/dev/null") + + emptyPath := HomeDirExpand("") + So(emptyPath, ShouldEqual, "") }) } From a948f2429a868c9524d01b6652bf00403fea8cbf Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 20:51:51 +0800 Subject: [PATCH 06/28] Update cql-utils docs. Disable keygen params --- cmd/cql-utils/README-zh.md | 8 ++++---- cmd/cql-utils/README.md | 8 ++++---- cmd/cql-utils/confgen.go | 6 +++++- cmd/cql-utils/main.go | 17 +++++++++-------- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/cmd/cql-utils/README-zh.md b/cmd/cql-utils/README-zh.md index cb36fd688..37a78bb72 100644 --- a/cmd/cql-utils/README-zh.md +++ b/cmd/cql-utils/README-zh.md @@ -11,19 +11,19 @@ $ go get github.com/CovenantSQL/CovenantSQL/cmd/cql-utils ### 生成公私钥对 ``` -$ cql-utils -tool keygen +$ cql-utils -tool confgen Enter master key(press Enter for default: ""): ⏎ Private key file: private.key Public key's hex: 03bc9e90e3301a2f5ae52bfa1f9e033cde81b6b6e7188b11831562bf5847bff4c0 ``` -生成的 private.key 文件即是使用主密码加密过的私钥文件,而输出到屏幕上的字符串就是使用十六进制进行编码的公钥。 +生成的 ~/.cql/private.key 文件即是使用主密码加密过的私钥文件,而输出到屏幕上的字符串就是使用十六进制进行编码的公钥。 ### 使用私钥文件或公钥生成钱包地址 ``` -$ cql-utils -tool addrgen -private private.key +$ cql-utils -tool addrgen Enter master key(default: ""): ⏎ wallet address: 4jXvNvPHKNPU8Sncz5u5F5WSGcgXmzC1g8RuAXTCJzLsbF9Dsf9 @@ -31,4 +31,4 @@ $ cql-utils -tool addrgen -public 02f2707c1c6955a9019cd9d02ade37b931fbfa286a1163 wallet address: 4jXvNvPHKNPU8Sncz5u5F5WSGcgXmzC1g8RuAXTCJzLsbF9Dsf9 ``` -你可以通过指定私钥文件,或者把上述的公钥十六进制编码字符串作为命令行参数来直接生成钱包地址。 \ No newline at end of file +你也可以通过-private指定私钥文件,或者把上述的公钥十六进制编码字符串作为命令行参数来直接生成钱包地址。 diff --git a/cmd/cql-utils/README.md b/cmd/cql-utils/README.md index b66ea80b7..d9da3a7ad 100644 --- a/cmd/cql-utils/README.md +++ b/cmd/cql-utils/README.md @@ -11,19 +11,19 @@ $ go get github.com/CovenantSQL/CovenantSQL/cmd/cql-utils ### Generate Key Pair ``` -$ cql-utils -tool keygen +$ cql-utils -tool confgen Enter master key(press Enter for default: ""): ⏎ Private key file: private.key Public key's hex: 03bc9e90e3301a2f5ae52bfa1f9e033cde81b6b6e7188b11831562bf5847bff4c0 ``` -The private.key is your encrypted private key file, and the pubkey hex is your public key's hex. +The ~/.cql/private.key is your encrypted private key file, and the pubkey hex is your public key's hex. ### Generate Wallet Address from existing Key ``` -$ cql-utils -tool addrgen -private private.key +$ cql-utils -tool addrgen Enter master key(default: ""): ⏎ wallet address: 4jXvNvPHKNPU8Sncz5u5F5WSGcgXmzC1g8RuAXTCJzLsbF9Dsf9 @@ -31,4 +31,4 @@ $ cql-utils -tool addrgen -public 02f2707c1c6955a9019cd9d02ade37b931fbfa286a1163 wallet address: 4jXvNvPHKNPU8Sncz5u5F5WSGcgXmzC1g8RuAXTCJzLsbF9Dsf9 ``` -You can generate your *wallet* address for test net according to your private key or public key. +You can generate your *wallet* address for test net according to your private key(default ~/.cql/private) or public key. diff --git a/cmd/cql-utils/confgen.go b/cmd/cql-utils/confgen.go index 940b19f18..304a9b5d4 100644 --- a/cmd/cql-utils/confgen.go +++ b/cmd/cql-utils/confgen.go @@ -62,7 +62,11 @@ func runConfgen() { os.Exit(1) } if strings.Compare(t, "y") == 0 || strings.Compare(t, "yes") == 0 { - os.RemoveAll(workingRoot) + err = os.RemoveAll(workingRoot) + if err != nil { + log.WithError(err).Error("unexpected error") + os.Exit(1) + } } else { os.Exit(0) } diff --git a/cmd/cql-utils/main.go b/cmd/cql-utils/main.go index 3c027fd4b..a7129c453 100644 --- a/cmd/cql-utils/main.go +++ b/cmd/cql-utils/main.go @@ -43,7 +43,7 @@ const name = "cql-utils" func init() { log.SetLevel(log.InfoLevel) - flag.StringVar(&tool, "tool", "", "tool type, miner, keygen, keytool, rpc, nonce, confgen, addrgen, adapterconfgen") + flag.StringVar(&tool, "tool", "", "tool type, miner, keytool, rpc, nonce, confgen, addrgen, adapterconfgen") flag.StringVar(&publicKeyHex, "public", "", "public key hex string to mine node id/nonce") flag.StringVar(&privateKeyFile, "private", "~/.cql/private.key", "private key file to generate/show") flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "config file to use") @@ -71,13 +71,14 @@ func main() { os.Exit(1) } runMiner() - case "keygen": - if privateKeyFile == "" { - // error - log.Error("privateKey path is required for keygen") - os.Exit(1) - } - runKeygen() + // Disable keygen independent call + //case "keygen": + // if privateKeyFile == "" { + // // error + // log.Error("privateKey path is required for keygen") + // os.Exit(1) + // } + // runKeygen() case "keytool": if privateKeyFile == "" { // error From 7d6369d5f8996ac92d263c5b4a43c29f100b5503 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:06:40 +0800 Subject: [PATCH 07/28] Change cql to use ~/.cql as config.yaml default location. --- cmd/cql/README-zh.md | 6 +++--- cmd/cql/README.md | 6 +++--- cmd/cql/main.go | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/cmd/cql/README-zh.md b/cmd/cql/README-zh.md index b4ca69a3a..a591243b3 100644 --- a/cmd/cql/README-zh.md +++ b/cmd/cql/README-zh.md @@ -19,7 +19,7 @@ $ go get github.com/CovenantSQL/CovenantSQL/cmd/cql 使用 `cql` 命令来检查钱包余额: ```bash -$ cql -config conf/config.yaml -get-balance +$ cql -get-balance INFO[0000] ### Public Key ### 0388954cf083bb6bb2b9c7248849b57c76326296fcc0d69764fc61eedb5b8d820c @@ -36,7 +36,7 @@ INFO[0000] covenant coin balance is: 0 caller="main.go:247 mai ```bash # if a non-default password applied on master key, use `-password` to pass it -$ cql -config conf/config.yaml -create 1 +$ cql -create 1 INFO[0000] ### Public Key ### 039bc931161383c994ab9b81e95ddc1494b0efeb1cb735bb91e1043a1d6b98ebfd @@ -48,7 +48,7 @@ INFO[0000] the newly created database is: covenantsql://0e9103318821b027f35b96c4 这里 `-create 1` 表示创建一个单节点的 SQLChain。 ```bash -$ cql -config conf/config.yaml -dsn covenantsql://address +$ cql -dsn covenantsql://address ``` `address` 就是你的数据库 ID。 diff --git a/cmd/cql/README.md b/cmd/cql/README.md index 4d3ec5074..ab5b3c9f5 100644 --- a/cmd/cql/README.md +++ b/cmd/cql/README.md @@ -19,7 +19,7 @@ See: [cql-utils doc](https://github.com/CovenantSQL/CovenantSQL/tree/develop/cmd Use `cql` to check your wallet balance: ```bash -$ cql -config conf/config.yaml -get-balance +$ cql -get-balance INFO[0000] ### Public Key ### 0388954cf083bb6bb2b9c7248849b57c76326296fcc0d69764fc61eedb5b8d820c @@ -37,7 +37,7 @@ You can get a database id when create a new SQL Chain: ```bash # if a non-default password applied on master key, use `-password` to pass it -$ cql -config conf/config.yaml -create 1 +$ cql -create 1 INFO[0000] ### Public Key ### 039bc931161383c994ab9b81e95ddc1494b0efeb1cb735bb91e1043a1d6b98ebfd @@ -49,7 +49,7 @@ INFO[0000] the newly created database is: covenantsql://0e9103318821b027f35b96c4 Here, `-create 1` refers that there is only one node in SQL Chain. ```bash -$ cql -config conf/config.yaml -dsn covenantsql://address +$ cql -dsn covenantsql://address ``` `address` is database id. diff --git a/cmd/cql/main.go b/cmd/cql/main.go index 8e4eabc76..cf820e163 100644 --- a/cmd/cql/main.go +++ b/cmd/cql/main.go @@ -39,6 +39,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/crypto/hash" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/types" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" sqlite3 "github.com/CovenantSQL/go-sqlite3-encrypt" "github.com/xo/dburl" @@ -216,7 +217,7 @@ func init() { flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") flag.StringVar(&outFile, "out", "", "Record stdout to file") - flag.StringVar(&configFile, "config", "config.yaml", "Config file for covenantsql") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file for covenantsql") flag.StringVar(&password, "password", "", "Master key password for covenantsql") flag.BoolVar(&singleTransaction, "single-transaction", false, "Execute as a single transaction (if non-interactive)") flag.Var(&variables, "variable", "Set variable") @@ -238,6 +239,9 @@ func main() { name, version, runtime.GOOS, runtime.GOARCH, runtime.Version()) os.Exit(0) } + log.Infof("cql build: %#v\n", version) + + configFile = utils.HomeDirExpand(configFile) var err error From 0f1fdd857763b1b67e2f74c316e0a6c679992903 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:07:23 +0800 Subject: [PATCH 08/28] Update testnet client test. Format cql-utils command help --- cmd/cql-utils/main.go | 10 +++++----- test/testnet_client/run.sh | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cmd/cql-utils/main.go b/cmd/cql-utils/main.go index a7129c453..9099daeff 100644 --- a/cmd/cql-utils/main.go +++ b/cmd/cql-utils/main.go @@ -43,11 +43,11 @@ const name = "cql-utils" func init() { log.SetLevel(log.InfoLevel) - flag.StringVar(&tool, "tool", "", "tool type, miner, keytool, rpc, nonce, confgen, addrgen, adapterconfgen") - flag.StringVar(&publicKeyHex, "public", "", "public key hex string to mine node id/nonce") - flag.StringVar(&privateKeyFile, "private", "~/.cql/private.key", "private key file to generate/show") - flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "config file to use") - flag.BoolVar(&skipMasterKey, "skip-master-key", false, "use empty master key") + flag.StringVar(&tool, "tool", "", "Tool type, miner, keytool, rpc, nonce, confgen, addrgen, adapterconfgen") + flag.StringVar(&publicKeyHex, "public", "", "Public key hex string to mine node id/nonce") + flag.StringVar(&privateKeyFile, "private", "~/.cql/private.key", "Private key file to generate/show") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file to use") + flag.BoolVar(&skipMasterKey, "skip-master-key", false, "Use empty master key") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") } diff --git a/test/testnet_client/run.sh b/test/testnet_client/run.sh index 13b71f7b8..a17511d0c 100755 --- a/test/testnet_client/run.sh +++ b/test/testnet_client/run.sh @@ -13,7 +13,7 @@ echo ${PROJECT_DIR} cd ${TEST_WD} echo -ne "y\n" | ${PROJECT_DIR}/bin/cql-utils -tool confgen -skip-master-key -${PROJECT_DIR}/bin/cql-utils -tool addrgen -private ./conf/private.key -skip-master-key | tee wallet.txt +${PROJECT_DIR}/bin/cql-utils -tool addrgen -skip-master-key | tee wallet.txt #get wallet addr wallet=$(awk '{print $3}' wallet.txt) @@ -22,17 +22,17 @@ wallet=$(awk '{print $3}' wallet.txt) ${PROJECT_DIR}/bin/cql -config ${PROJECT_DIR}/conf/testnet/config.yaml -transfer \ '{"addr":"'${wallet}'", "amount":"100000000 Particle"}' -wait-tx-confirm -${PROJECT_DIR}/bin/cql -config conf/config.yaml -get-balance +${PROJECT_DIR}/bin/cql -get-balance -${PROJECT_DIR}/bin/cql -config conf/config.yaml -create 2 -wait-tx-confirm | tee dsn.txt +${PROJECT_DIR}/bin/cql -create 2 -wait-tx-confirm | tee dsn.txt #get dsn dsn=$(cat dsn.txt) -${PROJECT_DIR}/bin/cql -config conf/config.yaml -dsn ${dsn} \ +${PROJECT_DIR}/bin/cql -dsn ${dsn} \ -command 'create table test_for_new_account(column1 int);' -${PROJECT_DIR}/bin/cql -config conf/config.yaml -dsn ${dsn} \ +${PROJECT_DIR}/bin/cql -dsn ${dsn} \ -command 'show tables;' | tee result.log grep "1 row" result.log From 3cdc4e94f6794221a32294ba16315f4550c455b3 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:27:57 +0800 Subject: [PATCH 09/28] Change cql-adapter to use ~/.cql as config.yaml default location. --- cmd/cql-adapter/README.md | 10 ++++++---- cmd/cql-adapter/main.go | 5 ++++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/cmd/cql-adapter/README.md b/cmd/cql-adapter/README.md index dbc4a3b2e..3787a4ed2 100644 --- a/cmd/cql-adapter/README.md +++ b/cmd/cql-adapter/README.md @@ -42,12 +42,14 @@ Created a new certificate valid for the following names 📜 - "server" The certificate is at "./server.pem" and the key at "./server-key.pem" ✅ + +And move them to ~/.cql/ dir. `````` You can use following interactive command to generate adapter config. ```shell -$ cql-utils -tool adapterconfgen -config config.yaml +$ cql-utils -tool adapterconfgen ListenAddr (default: 0.0.0.0:4661): ⏎ CertificatePath (default: server.pem): ⏎ PrivateKeyPath (default: server-key.pem): ⏎ @@ -58,7 +60,7 @@ WriteCerts (default:): ⏎ StorageDriver (default: covenantsql): ⏎ StorageRoot (default:): ⏎ -$ tail -n 20 config.yaml +$ tail -n 20 ~/.cql/config.yaml ... skipping irrelevant configuration Adapter: ListenAddr: 0.0.0.0:4661 @@ -79,7 +81,7 @@ Adapter: Start the adapter by following commands: ```shell -$ cql-adapter -config config.yaml +$ cql-adapter ``` ### API @@ -266,4 +268,4 @@ curl -v https://e.morenodes.com:11108/v1/query --insecure \ ###### Parameters -**database:** database id \ No newline at end of file +**database:** database id diff --git a/cmd/cql-adapter/main.go b/cmd/cql-adapter/main.go index 100a5b552..3b28f522e 100644 --- a/cmd/cql-adapter/main.go +++ b/cmd/cql-adapter/main.go @@ -26,6 +26,7 @@ import ( "time" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "golang.org/x/sys/unix" ) @@ -40,7 +41,7 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "./config.yaml", "config file for adapter") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "config file for adapter") flag.StringVar(&password, "password", "", "master key password") flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") @@ -55,6 +56,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From e142bcc9ca32a6595cf623e96916b82916092188 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:34:45 +0800 Subject: [PATCH 10/28] Change cql-mysql-adapter to use ~/.cql as config.yaml default location. --- cmd/cql-adapter/main.go | 4 ++-- cmd/cql-mysql-adapter/README.md | 6 +++--- cmd/cql-mysql-adapter/main.go | 15 +++++++++------ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cmd/cql-adapter/main.go b/cmd/cql-adapter/main.go index 3b28f522e..7866fefb6 100644 --- a/cmd/cql-adapter/main.go +++ b/cmd/cql-adapter/main.go @@ -41,8 +41,8 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "config file for adapter") - flag.StringVar(&password, "password", "", "master key password") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file for adapter") + flag.StringVar(&password, "password", "", "Master key password") flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") diff --git a/cmd/cql-mysql-adapter/README.md b/cmd/cql-mysql-adapter/README.md index 73eeaa4b3..2cf2aca53 100644 --- a/cmd/cql-mysql-adapter/README.md +++ b/cmd/cql-mysql-adapter/README.md @@ -22,7 +22,7 @@ Generate the main configuration file. Same as [Generating Default Config File in Start the mysql adapter by following commands: ```shell -$ cql-mysql-adapter -config config.yaml +$ cql-mysql-adapter ``` The default mysql user is ```root``` and the default mysql password is ```calvin```, which can be modified as optional arguments of mysql adapter. @@ -36,7 +36,7 @@ Usage of ./cql-mysql-adapter: -bypass-signature Disable signature sign and verify, for testing -config string - config file for mysql adapter (default "./config.yaml") + config file for mysql adapter (default "~/.cql/config.yaml") -listen string listen address for mysql adapter (default "127.0.0.1:4664") -mysql-password string @@ -82,4 +82,4 @@ mysql> show tables; mysql> quit Bye -``` \ No newline at end of file +``` diff --git a/cmd/cql-mysql-adapter/main.go b/cmd/cql-mysql-adapter/main.go index aad7ce4b0..0ec23e2b3 100644 --- a/cmd/cql-mysql-adapter/main.go +++ b/cmd/cql-mysql-adapter/main.go @@ -25,6 +25,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/client" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "golang.org/x/sys/unix" ) @@ -44,16 +45,16 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "./config.yaml", "config file for mysql adapter") - flag.StringVar(&password, "password", "", "master key password") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file for mysql adapter") + flag.StringVar(&password, "password", "", "Master key password") flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") - flag.StringVar(&listenAddr, "listen", "127.0.0.1:4664", "listen address for mysql adapter") - flag.StringVar(&mysqlUser, "mysql-user", "root", "mysql user for adapter server") - flag.StringVar(&mysqlPassword, "mysql-password", "calvin", "mysql password for adapter server") - flag.StringVar(&logLevel, "log-level", "", "service log level") + flag.StringVar(&listenAddr, "listen", "127.0.0.1:4664", "Listen address for mysql adapter") + flag.StringVar(&mysqlUser, "mysql-user", "root", "MySQL user for adapter server") + flag.StringVar(&mysqlPassword, "mysql-password", "calvin", "MySQL password for adapter server") + flag.StringVar(&logLevel, "log-level", "", "Service log level") } func main() { @@ -65,6 +66,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From a9cdb897b8f3558748ffc22312519324728e1827 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:40:12 +0800 Subject: [PATCH 11/28] Change cql-faucet to use ~/.cql as config.yaml default location. --- cmd/cql-faucet/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/cql-faucet/main.go b/cmd/cql-faucet/main.go index 14496f3f7..83362c39d 100644 --- a/cmd/cql-faucet/main.go +++ b/cmd/cql-faucet/main.go @@ -28,6 +28,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/client" "github.com/CovenantSQL/CovenantSQL/crypto/asymmetric" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "golang.org/x/sys/unix" ) @@ -42,8 +43,8 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "config.yaml", "configuration file for covenantsql") - flag.StringVar(&password, "password", "", "master key password for covenantsql") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Configuration file for covenantsql") + flag.StringVar(&password, "password", "", "Master key password for covenantsql") flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") @@ -57,6 +58,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From 2e8a8f202238c1cb50a21b6b807d007629343961 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:52:46 +0800 Subject: [PATCH 12/28] Change cql-explorer to use ~/.cql as config.yaml default location. --- cmd/cql-explorer/README.md | 12 ++++++------ cmd/cql-explorer/main.go | 11 +++++++---- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/cql-explorer/README.md b/cmd/cql-explorer/README.md index 6bce4872e..c321918ba 100644 --- a/cmd/cql-explorer/README.md +++ b/cmd/cql-explorer/README.md @@ -21,7 +21,7 @@ Generate the main configuration file. Same as [Generating Default Config File in Start the explorer by following commands: ```shell -$ cql-explorer -config config.yaml +$ cql-explorer ``` The available options are: @@ -30,13 +30,13 @@ The available options are: $ cql-explorer --help Usage of cql-explorer: -config string - config file path (default "./config.yaml") + Config file path (default "~/.cql/config.yaml") -interval duration - new block check interval for explorer (default 2s) + New block check interval for explorer (default 2s) -listen string - listen address for http explorer api (default "127.0.0.1:4665") + Listen address for http explorer api (default "127.0.0.1:4665") -password string - master key password for covenantsql + Master key password for covenantsql ``` ### API @@ -179,4 +179,4 @@ __hash__: hash of specified tx } } } -``` \ No newline at end of file +``` diff --git a/cmd/cql-explorer/main.go b/cmd/cql-explorer/main.go index 318764389..b1fbca26f 100644 --- a/cmd/cql-explorer/main.go +++ b/cmd/cql-explorer/main.go @@ -28,6 +28,7 @@ import ( "time" "github.com/CovenantSQL/CovenantSQL/client" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" ) @@ -47,10 +48,10 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "./config.yaml", "config file path") - flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "listen address for http explorer api") - flag.DurationVar(&checkInterval, "interval", time.Second*2, "new block check interval for explorer") - flag.StringVar(&password, "password", "", "master key password for covenantsql") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file path") + flag.StringVar(&listenAddr, "listen", "127.0.0.1:4665", "Listen address for http explorer api") + flag.DurationVar(&checkInterval, "interval", time.Second*2, "New block check interval for explorer") + flag.StringVar(&password, "password", "", "Master key password for covenantsql") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") } @@ -65,6 +66,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From 9f0b86d2901e425d2202e2ccfac946ca1323fdae Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 21:58:02 +0800 Subject: [PATCH 13/28] Change cql-fuse to use ~/.cql as config.yaml default location. --- cmd/cql-fuse/main.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/cql-fuse/main.go b/cmd/cql-fuse/main.go index 6d6738d18..a89986dd7 100644 --- a/cmd/cql-fuse/main.go +++ b/cmd/cql-fuse/main.go @@ -76,6 +76,7 @@ import ( "bazil.org/fuse/fs" _ "bazil.org/fuse/fs/fstestutil" "github.com/CovenantSQL/CovenantSQL/client" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" ) @@ -87,23 +88,25 @@ var usage = func() { func main() { var ( - config string + configFile string dsn string mountPoint string password string readOnly bool ) - flag.StringVar(&config, "config", "./conf/config.yaml", "config file path") - flag.StringVar(&mountPoint, "mount", "./", "dir to mount") - flag.StringVar(&dsn, "dsn", "", "database url") - flag.StringVar(&password, "password", "", "master key password for covenantsql") - flag.BoolVar(&readOnly, "readonly", false, "mount read only volume") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file path") + flag.StringVar(&mountPoint, "mount", "./", "Dir to mount") + flag.StringVar(&dsn, "dsn", "", "Database url") + flag.StringVar(&password, "password", "", "Master key password for covenantsql") + flag.BoolVar(&readOnly, "readonly", false, "Mount read only volume") flag.Usage = usage flag.Parse() log.SetLevel(log.InfoLevel) - err := client.Init(config, []byte(password)) + configFile = utils.HomeDirExpand(configFile) + + err := client.Init(configFile, []byte(password)) if err != nil { log.Fatal(err) } From 88fbd891a5146e9427abe19446fa7cd2bfa9d890 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 22:07:12 +0800 Subject: [PATCH 14/28] Change cql-observer to use ~/.cql as config.yaml default location. --- cmd/cql-observer/main.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/cmd/cql-observer/main.go b/cmd/cql-observer/main.go index 620ca8068..34162cbc3 100644 --- a/cmd/cql-observer/main.go +++ b/cmd/cql-observer/main.go @@ -31,6 +31,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/crypto/kms" "github.com/CovenantSQL/CovenantSQL/proto" "github.com/CovenantSQL/CovenantSQL/rpc" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" ) @@ -49,14 +50,14 @@ var ( ) func init() { - flag.StringVar(&configFile, "config", "./config.yaml", "config file path") - flag.StringVar(&dbID, "database", "", "database to listen for observation") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file path") + flag.StringVar(&dbID, "database", "", "Database to listen for observation") flag.BoolVar(&showVersion, "version", false, "Show version information and exit") flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") - flag.StringVar(&resetPosition, "reset", "", "reset subscribe position") - flag.StringVar(&listenAddr, "listen", "127.0.0.1:4663", "listen address for http explorer api") - flag.StringVar(&logLevel, "log-level", "", "service log level") + flag.StringVar(&resetPosition, "reset", "", "Reset subscribe position") + flag.StringVar(&listenAddr, "listen", "127.0.0.1:4663", "Listen address for http explorer api") + flag.StringVar(&logLevel, "log-level", "", "Service log level") } func main() { @@ -70,6 +71,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From dd26565a9049a7eb06636be09c43ea3d117344f0 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 22:58:21 +0800 Subject: [PATCH 15/28] Set errexit pipefail for compatibility-testnet. --- .gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a8ac0214e..9353d2a66 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -29,7 +29,9 @@ test-my-project: compatibility-testnet: stage: test script: + - set -o errexit + - set -o pipefail - make clean - make -j8 client - go test -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ - - bash test/testnet_client/run.sh + - bash -x test/testnet_client/run.sh From 1fd9871432de026ad38078dbc8cea7f5e413c285 Mon Sep 17 00:00:00 2001 From: laodouya Date: Wed, 23 Jan 2019 23:00:02 +0800 Subject: [PATCH 16/28] Remove osusergo build tags. Add build tags for unittest. --- .gitlab-ci.yml | 3 ++- Makefile | 2 +- alltest.sh | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 9353d2a66..d37c880ec 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,6 +4,7 @@ variables: REVIEWDOG_VERSION: 0.9.11 REVIEWDOG_GITLAB_API_TOKEN: $REVIEWDOG_TOKEN CODECOV_TOKEN: $CODECOV_TOKEN + UNITTESTTAGS: -tags "linux sqlite_omit_load_extension" before_script: # Setup dependency management tool @@ -33,5 +34,5 @@ compatibility-testnet: - set -o pipefail - make clean - make -j8 client - - go test -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ + - go test $UNITTESTTAGS -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ - bash -x test/testnet_client/run.sh diff --git a/Makefile b/Makefile index 34a2a0e4a..da0c10c0d 100644 --- a/Makefile +++ b/Makefile @@ -126,7 +126,7 @@ endif version := $(branch)-$(GIT_COMMIT)-$(builddate) -tags := $(platform) sqlite_omit_load_extension osusergo +tags := $(platform) sqlite_omit_load_extension testtags := $(tags) testbinary test_flags := -coverpkg github.com/CovenantSQL/CovenantSQL/... -cover -race -c diff --git a/alltest.sh b/alltest.sh index b2f74d45f..f837347d2 100755 --- a/alltest.sh +++ b/alltest.sh @@ -14,7 +14,7 @@ test::package() { local coverage_file="${package//\//.}.cover.out" echo "[TEST] package=${package}, coverage=${coverage_file}" - go test -race -failfast -parallel 16 -cpu 16 -coverpkg="github.com/CovenantSQL/CovenantSQL/..." -coverprofile "${coverage_file}" "${package}" + go test $UNITTESTTAGS -race -failfast -parallel 16 -cpu 16 -coverpkg="github.com/CovenantSQL/CovenantSQL/..." -coverprofile "${coverage_file}" "${package}" } main() { @@ -30,9 +30,9 @@ main() { bash <(curl -s https://codecov.io/bash) # some benchmarks - go test -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/ + go test $UNITTESTTAGS -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/ bash cleanupDB.sh || true - go test -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ + go test $UNITTESTTAGS -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ bash cleanupDB.sh || true } From db9753687988b611a704610662f379e7aaceccb0 Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 10:23:54 +0800 Subject: [PATCH 17/28] Set -x for gitlabci process. --- .gitlab-ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d37c880ec..e73b48302 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -25,11 +25,14 @@ before_script: test-my-project: stage: test - script: ./alltest.sh + script: + - set -x + - ./alltest.sh compatibility-testnet: stage: test script: + - set -x - set -o errexit - set -o pipefail - make clean From 682f729bb462ca6c7f809f17b18b2453a3fdc0cb Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 10:30:40 +0800 Subject: [PATCH 18/28] Fix go test unit test tags quote err. --- .gitlab-ci.yml | 4 ++-- alltest.sh | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index e73b48302..b2da8381e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -4,7 +4,7 @@ variables: REVIEWDOG_VERSION: 0.9.11 REVIEWDOG_GITLAB_API_TOKEN: $REVIEWDOG_TOKEN CODECOV_TOKEN: $CODECOV_TOKEN - UNITTESTTAGS: -tags "linux sqlite_omit_load_extension" + UNITTESTTAGS: linux sqlite_omit_load_extension before_script: # Setup dependency management tool @@ -37,5 +37,5 @@ compatibility-testnet: - set -o pipefail - make clean - make -j8 client - - go test $UNITTESTTAGS -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ + - go test -tags "$UNITTESTTAGS" -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ - bash -x test/testnet_client/run.sh diff --git a/alltest.sh b/alltest.sh index f837347d2..e7d3a6170 100755 --- a/alltest.sh +++ b/alltest.sh @@ -14,7 +14,7 @@ test::package() { local coverage_file="${package//\//.}.cover.out" echo "[TEST] package=${package}, coverage=${coverage_file}" - go test $UNITTESTTAGS -race -failfast -parallel 16 -cpu 16 -coverpkg="github.com/CovenantSQL/CovenantSQL/..." -coverprofile "${coverage_file}" "${package}" + go test -tags "$UNITTESTTAGS" -race -failfast -parallel 16 -cpu 16 -coverpkg="github.com/CovenantSQL/CovenantSQL/..." -coverprofile "${coverage_file}" "${package}" } main() { @@ -30,9 +30,9 @@ main() { bash <(curl -s https://codecov.io/bash) # some benchmarks - go test $UNITTESTTAGS -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/ + go test -tags "$UNITTESTTAGS" -bench=^BenchmarkPersistentCaller_Call$ -run ^$ ./rpc/ bash cleanupDB.sh || true - go test $UNITTESTTAGS -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ + go test -tags "$UNITTESTTAGS" -bench=^BenchmarkMinerTwo$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ bash cleanupDB.sh || true } From 48753cb7e325ac97636c1b6a6a15ea01383eba86 Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 10:39:32 +0800 Subject: [PATCH 19/28] Set -x for alltest.sh --- .gitlab-ci.yml | 4 ++-- alltest.sh | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b2da8381e..b42fa3cbc 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,10 +32,10 @@ test-my-project: compatibility-testnet: stage: test script: - - set -x - set -o errexit - set -o pipefail - make clean - make -j8 client - go test -tags "$UNITTESTTAGS" -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ - - bash -x test/testnet_client/run.sh + - set -x + - ./test/testnet_client/run.sh diff --git a/alltest.sh b/alltest.sh index e7d3a6170..b7e39220a 100755 --- a/alltest.sh +++ b/alltest.sh @@ -3,6 +3,7 @@ set -o errexit set -o pipefail set -o nounset +set -x test::package() { local package="${1:-notset}" From c5e317cbc93d6120aa0b3a9812f5b6cd44e9a7ff Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 11:09:25 +0800 Subject: [PATCH 20/28] Move set -x location in alltest.sh --- alltest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/alltest.sh b/alltest.sh index b7e39220a..27a419cdf 100755 --- a/alltest.sh +++ b/alltest.sh @@ -3,7 +3,6 @@ set -o errexit set -o pipefail set -o nounset -set -x test::package() { local package="${1:-notset}" @@ -27,6 +26,7 @@ main() { test::package "${package}" done + set -x gocovmerge *.cover.out $(find cmd -name "*.cover.out") | grep -F -v '_gen.go' > coverage.txt && rm -f *.cover.out bash <(curl -s https://codecov.io/bash) From 9d2c7005c85ec09fabb4e9e9a4b455d3df069f28 Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 11:42:44 +0800 Subject: [PATCH 21/28] Change cql-minerd to use ~/.cql as config.yaml default location. --- cmd/cql-minerd/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/cql-minerd/main.go b/cmd/cql-minerd/main.go index 62e9f1739..c78b84af9 100644 --- a/cmd/cql-minerd/main.go +++ b/cmd/cql-minerd/main.go @@ -96,7 +96,7 @@ func init() { flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") - flag.StringVar(&configFile, "config", "./config.yaml", "Config file path") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file path") flag.StringVar(&profileServer, "profile-server", "", "Profile server address, default not started") flag.StringVar(&cpuProfile, "cpu-profile", "", "Path to file for CPU profiling information") @@ -132,6 +132,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From 54b5d50946e120ce8f8e3ad72492422bf462c1f8 Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 11:48:07 +0800 Subject: [PATCH 22/28] Change cqld to use ~/.cql as config.yaml default location. --- cmd/cqld/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/cqld/main.go b/cmd/cqld/main.go index 68c0a19f5..ca4d92bd1 100644 --- a/cmd/cqld/main.go +++ b/cmd/cqld/main.go @@ -71,7 +71,7 @@ func init() { flag.BoolVar(&showVersion, "version", false, "Show version information and exit") flag.BoolVar(&asymmetric.BypassSignature, "bypass-signature", false, "Disable signature sign and verify, for testing") - flag.StringVar(&configFile, "config", "./config.yaml", "Config file path") + flag.StringVar(&configFile, "config", "~/.cql/config.yaml", "Config file path") flag.StringVar(&cpuProfile, "cpu-profile", "", "Path to file for CPU profiling information") flag.StringVar(&memProfile, "mem-profile", "", "Path to file for memory profiling information") @@ -106,6 +106,8 @@ func main() { os.Exit(0) } + configFile = utils.HomeDirExpand(configFile) + flag.Visit(func(f *flag.Flag) { log.Infof("args %#v : %s", f.Name, f.Value) }) From 6be50794674f6124ff0c12161a27686c14438504 Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 13:58:12 +0800 Subject: [PATCH 23/28] Use default config file path(~/.cql/config.yaml) if driver not call Init. --- client/driver.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/client/driver.go b/client/driver.go index 09b2a93d9..ece39b3a0 100644 --- a/client/driver.go +++ b/client/driver.go @@ -37,6 +37,7 @@ import ( "github.com/CovenantSQL/CovenantSQL/route" "github.com/CovenantSQL/CovenantSQL/rpc" "github.com/CovenantSQL/CovenantSQL/types" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" "github.com/pkg/errors" ) @@ -63,12 +64,15 @@ var ( connIDAvail []uint64 globalSeqNo uint64 randSource = rand.New(rand.NewSource(time.Now().UnixNano())) + + defaultConfigFile = "~/.cql/config.yaml" ) func init() { d := new(covenantSQLDriver) sql.Register(DBScheme, d) sql.Register(DBSchemeAlias, d) + log.Debug("CovenantSQL driver registered.") } // covenantSQLDriver implements sql.Driver interface. @@ -83,8 +87,10 @@ func (d *covenantSQLDriver) Open(dsn string) (conn driver.Conn, err error) { } if atomic.LoadUint32(&driverInitialized) == 0 { - err = ErrNotInitialized - return + err = defaultInit() + if err != nil && err != ErrAlreadyInitialized { + return + } } return newConn(cfg) @@ -97,6 +103,18 @@ type ResourceMeta struct { AdvancePayment uint64 } +func defaultInit() (err error) { + configFile := utils.HomeDirExpand(defaultConfigFile) + if configFile == defaultConfigFile { + //System not support ~ dir, need Init manually. + log.Debugf("Could not find CovenantSQL default config location: %v", configFile) + return ErrNotInitialized + } + + log.Debugf("Using CovenantSQL default config location: %v", configFile) + return Init(configFile, []byte("")) +} + // Init defines init process for client. func Init(configFile string, masterKey []byte) (err error) { if !atomic.CompareAndSwapUint32(&driverInitialized, 0, 1) { From aea44af93204534bbfb01d04b05b2a57db61af92 Mon Sep 17 00:00:00 2001 From: laodouya Date: Thu, 24 Jan 2019 14:16:17 +0800 Subject: [PATCH 24/28] Update client example --- .../_example/{ => gdpaverage}/gdpaverage.go | 5 ++- client/_example/simple.go | 32 ++++++++----------- 2 files changed, 17 insertions(+), 20 deletions(-) rename client/_example/{ => gdpaverage}/gdpaverage.go (97%) diff --git a/client/_example/gdpaverage.go b/client/_example/gdpaverage/gdpaverage.go similarity index 97% rename from client/_example/gdpaverage.go rename to client/_example/gdpaverage/gdpaverage.go index f3a1e098e..4d1577061 100644 --- a/client/_example/gdpaverage.go +++ b/client/_example/gdpaverage/gdpaverage.go @@ -21,6 +21,7 @@ import ( "flag" "github.com/CovenantSQL/CovenantSQL/client" + "github.com/CovenantSQL/CovenantSQL/utils" "github.com/CovenantSQL/CovenantSQL/utils/log" ) @@ -28,11 +29,13 @@ func main() { log.SetLevel(log.DebugLevel) var config, password, dsn string - flag.StringVar(&config, "config", "./conf/config.yaml", "config file path") + flag.StringVar(&config, "config", "~/.cql/config.yaml", "config file path") flag.StringVar(&dsn, "dsn", "", "database url") flag.StringVar(&password, "password", "", "master key password for covenantsql") flag.Parse() + config = utils.HomeDirExpand(config) + err := client.Init(config, []byte(password)) if err != nil { log.Fatal(err) diff --git a/client/_example/simple.go b/client/_example/simple.go index 6b24f4690..75ca77305 100644 --- a/client/_example/simple.go +++ b/client/_example/simple.go @@ -21,33 +21,27 @@ import ( "flag" "fmt" - "github.com/CovenantSQL/CovenantSQL/client" + _ "github.com/CovenantSQL/CovenantSQL/client" "github.com/CovenantSQL/CovenantSQL/utils/log" ) func main() { log.SetLevel(log.InfoLevel) - var config, password, dsn string + var dsn string - flag.StringVar(&config, "config", "./conf/config.yaml", "config file path") - flag.StringVar(&dsn, "dsn", "", "database url") - flag.StringVar(&password, "password", "", "master key password for covenantsql") + flag.StringVar(&dsn, "dsn", "", "Database url") flag.Parse() - err := client.Init(config, []byte(password)) - if err != nil { - log.Fatal(err) - } - - if dsn == "" { - meta := client.ResourceMeta{} - meta.Node = 2 - dsn, err = client.Create(meta) - if err != nil { - log.Fatal(err) - } - defer client.Drop(dsn) - } + // If your CovenantSQL config.yaml is not in ~/.cql/config.yaml + // Uncomment and edit following code + /* + config := "/data/myconfig/config.yaml" + password := "mypassword" + err := client.Init(config, []byte(password)) + if err != nil { + log.Fatal(err) + } + */ db, err := sql.Open("covenantsql", dsn) if err != nil { From 9b8114c0b24f08e9867ad5c1e5db2fcfb9c955ee Mon Sep 17 00:00:00 2001 From: laodouya Date: Mon, 28 Jan 2019 10:34:19 +0800 Subject: [PATCH 25/28] Fix missing 'linux' building tags. --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index da0c10c0d..e1bf36bce 100644 --- a/Makefile +++ b/Makefile @@ -120,8 +120,8 @@ builddate := $(shell date +%Y%m%d%H%M%S) unamestr := $(shell uname) -ifeq ($(unamestr),"Linux") -platform := "linux" +ifeq ($(unamestr),Linux) +platform := linux endif version := $(branch)-$(GIT_COMMIT)-$(builddate) From b3e28cf8e699dc13d613a4fdcf6d5fa59d3996a5 Mon Sep 17 00:00:00 2001 From: auxten Date: Mon, 28 Jan 2019 14:42:45 +0800 Subject: [PATCH 26/28] Fix typo --- cmd/cql-explorer/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/cql-explorer/README.md b/cmd/cql-explorer/README.md index c321918ba..3062e854d 100644 --- a/cmd/cql-explorer/README.md +++ b/cmd/cql-explorer/README.md @@ -36,7 +36,7 @@ Usage of cql-explorer: -listen string Listen address for http explorer api (default "127.0.0.1:4665") -password string - Master key password for covenantsql + Master key password for covenantsql ``` ### API From 520d72503c41e6c2bf685959b8a5596f2c704582 Mon Sep 17 00:00:00 2001 From: laodouya Date: Mon, 28 Jan 2019 16:30:44 +0800 Subject: [PATCH 27/28] Skip compatibility test if branch name contains '/beta_' --- .gitlab-ci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b42fa3cbc..2ae123e4b 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -34,6 +34,9 @@ compatibility-testnet: script: - set -o errexit - set -o pipefail + - commit=$(git rev-parse --short HEAD) + - branch=$(git branch -rv |grep $commit | awk '{print $1}') + - if [[ $branch =~ "/beta_" ]]; then exit 0; fi - make clean - make -j8 client - go test -tags "$UNITTESTTAGS" -bench=^BenchmarkTestnetMiner2$ -benchtime=5s -run ^$ ./cmd/cql-minerd/ From 733418f9e6fafc3d2eb6b84d46e5b83843e163d6 Mon Sep 17 00:00:00 2001 From: laodouya Date: Mon, 28 Jan 2019 17:33:19 +0800 Subject: [PATCH 28/28] Remove '-x' for test_my_project in gitlabci. --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2ae123e4b..cec6a3234 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -26,7 +26,6 @@ before_script: test-my-project: stage: test script: - - set -x - ./alltest.sh compatibility-testnet: