.rc 文件是 UNIX 系统的标准,但对于 Windows 来说不是。
在这种情况下,我们可以查看cbt命令的代码来查看它是如何找到.cbtrc文件的,它是in this piece of code:
// Filename returns the filename consulted for standard configuration.
func Filename() string {
// TODO(dsymonds): Might need tweaking for Windows.
return filepath.Join(os.Getenv("HOME"), ".cbtrc")
}
代码获取HOME 环境变量,但这在Windows 中不可用(this superuser question 中的一些详细信息)。 windows equivalent 是 %HOMEPATH%。代码上甚至还有一个 TODO 以使其在 Windows 中更好地工作。
这意味着 cbt 命令没有找到配置文件,所以它没有应用它。
您可以在您的机器中设置HOME env 变量,也可以直接在命令上传递命令标志:
cbt -project fake-project -instance fake-instance -admin-endpoint localhost:8086 -data-endpoint localhost:8086 -creds C:\path\to\your\creds -auth-token <TOKEN> createtable my-table
此外,您必须为cbt 设置正确的环境变量才能了解它在模拟器上运行。这意味着设置BIGTABLE_EMULATOR_HOST 环境变量。
在linux机器上,没有设置正确的环境,我得到同样的错误,但设置正确的环境后它可以工作:
$ cbt -project test -instance test -admin-endpoint localhost:8086 -data-endpoint localhost:8086 createtable test
2020/10/13 08:23:13 Creating table: rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: tls: first record does not look like a TLS handshake"
$ $(gcloud beta emulators bigtable env-init)
$ cbt -project test -instance test -admin-endpoint localhost:8086 -data-endpoint localhost:8086 createtable test
$ cbt -project test -instance test -admin-endpoint localhost:8086 -data-endpoint localhost:8086 ls
test
在cbt 代码中,我们还可以看到,如果设置了该环境变量,它会使调用不安全,但如果没有设置,它会尝试使调用安全,因此出现 TLS 错误(本地模拟器不设置安全端点)。
这可以在this piece of code看到:
// DefaultClientOptions returns the default client options to use for the
// client's gRPC connection.
func DefaultClientOptions(endpoint, scope, userAgent string) ([]option.ClientOption, error) {
var o []option.ClientOption
// Check the environment variables for the bigtable emulator.
// Dial it directly and don't pass any credentials.
if addr := os.Getenv("BIGTABLE_EMULATOR_HOST"); addr != "" {
conn, err := grpc.Dial(addr, grpc.WithInsecure())
if err != nil {
return nil, fmt.Errorf("emulator grpc.Dial: %v", err)
}
o = []option.ClientOption{option.WithGRPCConn(conn)}
} else {
o = []option.ClientOption{
option.WithEndpoint(endpoint),
option.WithScopes(scope),
option.WithUserAgent(userAgent),
}
}
return o, nil
}
总结:确保您为cbt 设置了正确的环境变量才能正常工作。对于您看到的具体错误,可能是缺少 BIGTABLE_EMULATOR_HOST 变量。