Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

host2plugin: Add SDKVersion #203

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
3 changes: 3 additions & 0 deletions plugin/host2plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import (
"google.golang.org/grpc"
)

// SDKVersion is the SDK version.
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