Skip to content

Commit d9ee3a5

Browse files
committed
fix: hashicorp python does not support rpc
1 parent 08e5720 commit d9ee3a5

2 files changed

Lines changed: 17 additions & 16 deletions

File tree

docs/logs/hashicorp_rpc_go.log

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
[INFO] fungo: init plugin: path=fungo/examples/debugtalk.bin
33
[INFO] hc-rpc-go: launch the plugin process
44
[DEBUG] hc-rpc-go: starting plugin: path=fungo/examples/debugtalk.bin args=["fungo/examples/debugtalk.bin"]
5-
[DEBUG] hc-rpc-go: plugin started: path=fungo/examples/debugtalk.bin pid=72483
5+
[DEBUG] hc-rpc-go: plugin started: path=fungo/examples/debugtalk.bin pid=56263
66
[DEBUG] hc-rpc-go: waiting for RPC address: path=fungo/examples/debugtalk.bin
7-
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/07 00:15:33 plugin init function called
7+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/10 16:54:04 plugin init function called
88
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_ints
99
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum_two_int
1010
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=sum
@@ -14,19 +14,19 @@
1414
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=setup_hook_example
1515
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: register plugin function: funcName=teardown_hook_example
1616
[INFO] hc-rpc-go.debugtalk.bin: [INFO] fungo: start plugin server in RPC mode
17+
[DEBUG] hc-rpc-go.debugtalk.bin: plugin address: address=/var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin3244638032 network=unix timestamp="2023-08-10T16:54:04.356+0800"
1718
[DEBUG] hc-rpc-go: using plugin: version=1
18-
[DEBUG] hc-rpc-go.debugtalk.bin: plugin address: address=/var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin4148870767 network=unix timestamp="2023-08-07T00:15:33.267+0800"
1919
[INFO] hc-rpc-go: load hashicorp go plugin success: path=fungo/examples/debugtalk.bin
2020
[DEBUG] hc-rpc-go: check if plugin has function: funcName=sum_ints
2121
[DEBUG] fungo: rpc_client GetNames() start
2222
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() start
23-
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sum_ints", "sum_strings", "sumstrings", "concatenate", "sumints", "sum_two_string", "setuphookexample", "sumtwoint", "setup_hook_example", "teardownhookexample", "sum_two_int", "sum", "sumtwostring", "teardown_hook_example"]
23+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sumtwoint", "sum_two_string", "sumtwostring", "teardown_hook_example", "sumstrings", "setup_hook_example", "setuphookexample", "sum_ints", "sumints", "sum_two_int", "sum", "sum_strings", "concatenate", "teardownhookexample"]
2424
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() success
2525
[DEBUG] fungo: rpc_client GetNames() success
2626
[DEBUG] hc-rpc-go: check if plugin has function: funcName=concatenate
2727
[DEBUG] fungo: rpc_client GetNames() start
2828
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() start
29-
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sumtwoint", "setup_hook_example", "teardownhookexample", "sum_two_int", "sum", "sumtwostring", "teardown_hook_example", "sum_ints", "sum_strings", "sumstrings", "concatenate", "sumints", "sum_two_string", "setuphookexample"]
29+
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo.func_exec: get registered plugin functions: names=["sum_ints", "sum_strings", "concatenate", "teardownhookexample", "sumints", "sum_two_int", "sum", "teardown_hook_example", "sumtwoint", "sum_two_string", "sumtwostring", "sumstrings", "setup_hook_example", "setuphookexample"]
3030
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server GetNames() success
3131
[DEBUG] fungo: rpc_client GetNames() success
3232
[INFO] fungo: rpc_client Call() start: funcName=sum_ints funcArgs=[1, 2, 3, 4]
@@ -60,7 +60,7 @@
6060
[DEBUG] hc-rpc-go.debugtalk.bin: [DEBUG] fungo: rpc_server Call() success
6161
[INFO] fungo: rpc_client Call() success: result=a2c3.4
6262
[INFO] hc-rpc-go: quit hashicorp plugin process
63-
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/07 00:15:33 [DEBUG] plugin: plugin server: accept unix /var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin4148870767: use of closed network connection
64-
[INFO] hc-rpc-go: plugin process exited: path=fungo/examples/debugtalk.bin pid=72483
63+
[DEBUG] hc-rpc-go.debugtalk.bin: 2023/08/10 16:54:04 [DEBUG] plugin: plugin server: accept unix /var/folders/nm/6prc3p4s2tg_27_3fwfv22vh0000gp/T/plugin3244638032: use of closed network connection
64+
[INFO] hc-rpc-go: plugin process exited: path=fungo/examples/debugtalk.bin pid=56263
6565
[DEBUG] hc-rpc-go: plugin exited
6666
[INFO] fungo: close log file

hashicorp_plugin.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,27 @@ func newHashicorpPlugin(path string, option *pluginOption) (*hashicorpPlugin, er
3939
option: option,
4040
}
4141

42-
// plugin type, grpc or rpc
43-
p.rpcType = rpcType(os.Getenv(fungo.PluginTypeEnvName))
44-
if p.rpcType != rpcTypeRPC {
45-
p.rpcType = rpcTypeGRPC // default
46-
}
47-
48-
// logger
49-
logger = logger.ResetNamed(fmt.Sprintf("hc-%v-%v", p.rpcType, p.option.langType))
50-
5142
// cmd
5243
var cmd *exec.Cmd
5344
if p.option.langType == langTypePython {
5445
// hashicorp python plugin
5546
cmd = exec.Command(p.option.python3, path)
47+
// hashicorp python plugin only supports gRPC
48+
p.rpcType = rpcTypeGRPC
5649
} else {
5750
// hashicorp go plugin
5851
cmd = exec.Command(path)
52+
// hashicorp go plugin supports grpc and rpc
53+
p.rpcType = rpcType(os.Getenv(fungo.PluginTypeEnvName))
54+
if p.rpcType != rpcTypeRPC {
55+
p.rpcType = rpcTypeGRPC // default
56+
}
5957
}
6058
cmd.Env = append(os.Environ(), fmt.Sprintf("%s=%s", fungo.PluginTypeEnvName, p.rpcType))
6159

60+
// logger
61+
logger = logger.ResetNamed(fmt.Sprintf("hc-%v-%v", p.rpcType, p.option.langType))
62+
6263
// launch the plugin process
6364
logger.Info("launch the plugin process")
6465
p.client = plugin.NewClient(&plugin.ClientConfig{

0 commit comments

Comments
 (0)