Skip to content

Commit

Permalink
Add SDKVersion
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Oct 7, 2022
1 parent 76cc991 commit 00fcb3c
Show file tree
Hide file tree
Showing 7 changed files with 840 additions and 594 deletions.
9 changes: 9 additions & 0 deletions plugin/host2plugin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ func (c *GRPCClient) VersionConstraints() (version.Constraints, error) {
return version.NewConstraint(resp.Constraint)
}

// SDKVersion returns the SDK version.
func (c *GRPCClient) SDKVersion() (*version.Version, error) {
resp, err := c.client.GetSDKVersion(context.Background(), &proto.GetSDKVersion_Request{})
if err != nil {
return nil, fromproto.Error(err)
}
return version.NewVersion(resp.Version)
}

// ConfigSchema fetches the config schema from a plugin.
func (c *GRPCClient) ConfigSchema() (*hclext.BodySchema, error) {
resp, err := c.client.GetConfigSchema(context.Background(), &proto.GetConfigSchema_Request{})
Expand Down
13 changes: 13 additions & 0 deletions plugin/host2plugin/host2plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,19 @@ func TestVersionConstraints(t *testing.T) {
}
}

func TestSDKVersion(t *testing.T) {
client := startTestGRPCPluginServer(t, newMockRuleSet("test_ruleset", "0.1.0", mockRuleSetImpl{}))

got, err := client.SDKVersion()
if err != nil {
t.Fatalf("failed to call SDKVersion: %s", err)
}

if got.String() != SDKVersion {
t.Errorf("want: %s, got: %s", SDKVersion, got)
}
}

func TestConfigSchema(t *testing.T) {
// default error check helper
neverHappend := func(err error) bool { return err != nil }
Expand Down
2 changes: 2 additions & 0 deletions plugin/host2plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"google.golang.org/grpc"
)

const SDKVersion = "0.13.0"

// handShakeConfig is used for UX. ProcotolVersion will be updated by incompatible changes.
var handshakeConfig = plugin.HandshakeConfig{
ProtocolVersion: 11,
Expand Down
5 changes: 5 additions & 0 deletions plugin/host2plugin/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ func (s *GRPCServer) GetVersionConstraint(ctx context.Context, req *proto.GetVer
return &proto.GetVersionConstraint_Response{Constraint: s.impl.VersionConstraint()}, nil
}

// GetSDKVersion returns the SDK version.
func (s *GRPCServer) GetSDKVersion(ctx context.Context, req *proto.GetSDKVersion_Request) (*proto.GetSDKVersion_Response, error) {
return &proto.GetSDKVersion_Response{Version: SDKVersion}, nil
}

// GetConfigSchema returns the config schema of the plugin.
func (s *GRPCServer) GetConfigSchema(ctx context.Context, req *proto.GetConfigSchema_Request) (*proto.GetConfigSchema_Response, error) {
return &proto.GetConfigSchema_Response{Schema: toproto.BodySchema(s.impl.ConfigSchema())}, nil
Expand Down
Loading

0 comments on commit 00fcb3c

Please sign in to comment.