Skip to content

Commit cb843d9

Browse files
authored
Add SDKVersion (#203)
1 parent 76cc991 commit cb843d9

File tree

7 files changed

+841
-594
lines changed

7 files changed

+841
-594
lines changed

plugin/host2plugin/client.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,15 @@ func (c *GRPCClient) VersionConstraints() (version.Constraints, error) {
8181
return version.NewConstraint(resp.Constraint)
8282
}
8383

84+
// SDKVersion returns the SDK version.
85+
func (c *GRPCClient) SDKVersion() (*version.Version, error) {
86+
resp, err := c.client.GetSDKVersion(context.Background(), &proto.GetSDKVersion_Request{})
87+
if err != nil {
88+
return nil, fromproto.Error(err)
89+
}
90+
return version.NewVersion(resp.Version)
91+
}
92+
8493
// ConfigSchema fetches the config schema from a plugin.
8594
func (c *GRPCClient) ConfigSchema() (*hclext.BodySchema, error) {
8695
resp, err := c.client.GetConfigSchema(context.Background(), &proto.GetConfigSchema_Request{})

plugin/host2plugin/host2plugin_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,19 @@ func TestVersionConstraints(t *testing.T) {
254254
}
255255
}
256256

257+
func TestSDKVersion(t *testing.T) {
258+
client := startTestGRPCPluginServer(t, newMockRuleSet("test_ruleset", "0.1.0", mockRuleSetImpl{}))
259+
260+
got, err := client.SDKVersion()
261+
if err != nil {
262+
t.Fatalf("failed to call SDKVersion: %s", err)
263+
}
264+
265+
if got.String() != SDKVersion {
266+
t.Errorf("want: %s, got: %s", SDKVersion, got)
267+
}
268+
}
269+
257270
func TestConfigSchema(t *testing.T) {
258271
// default error check helper
259272
neverHappend := func(err error) bool { return err != nil }

plugin/host2plugin/plugin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ import (
99
"google.golang.org/grpc"
1010
)
1111

12+
// SDKVersion is the SDK version.
13+
const SDKVersion = "0.13.0"
14+
1215
// handShakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes.
1316
var handshakeConfig = plugin.HandshakeConfig{
1417
ProtocolVersion: 11,

plugin/host2plugin/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ func (s *GRPCServer) GetVersionConstraint(ctx context.Context, req *proto.GetVer
6868
return &proto.GetVersionConstraint_Response{Constraint: s.impl.VersionConstraint()}, nil
6969
}
7070

71+
// GetSDKVersion returns the SDK version.
72+
func (s *GRPCServer) GetSDKVersion(ctx context.Context, req *proto.GetSDKVersion_Request) (*proto.GetSDKVersion_Response, error) {
73+
return &proto.GetSDKVersion_Response{Version: SDKVersion}, nil
74+
}
75+
7176
// GetConfigSchema returns the config schema of the plugin.
7277
func (s *GRPCServer) GetConfigSchema(ctx context.Context, req *proto.GetConfigSchema_Request) (*proto.GetConfigSchema_Response, error) {
7378
return &proto.GetConfigSchema_Response{Schema: toproto.BodySchema(s.impl.ConfigSchema())}, nil

0 commit comments

Comments
 (0)