Skip to content

Commit

Permalink
Add PluginEnv to SystemView (#5028)
Browse files Browse the repository at this point in the history
  • Loading branch information
kalafut authored Aug 3, 2018
1 parent dbd6691 commit bb180b8
Show file tree
Hide file tree
Showing 10 changed files with 494 additions and 182 deletions.
77 changes: 77 additions & 0 deletions logical/plugin.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions logical/plugin.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

option go_package = "github.com/hashicorp/vault/logical";

package logical;

message PluginEnvironment {
// VaultVersion is the version of the Vault server
string vault_version = 1;
}
21 changes: 21 additions & 0 deletions logical/plugin/grpc_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ func (s *gRPCSystemViewClient) EntityInfo(entityID string) (*logical.Entity, err
return reply.Entity, nil
}

func (s *gRPCSystemViewClient) PluginEnv(ctx context.Context) (*logical.PluginEnvironment, error) {
reply, err := s.client.PluginEnv(ctx, &pb.Empty{})
if err != nil {
return nil, err
}

return reply.PluginEnvironment, nil
}

type gRPCSystemViewServer struct {
impl logical.SystemView
}
Expand Down Expand Up @@ -242,3 +251,15 @@ func (s *gRPCSystemViewServer) EntityInfo(ctx context.Context, args *pb.EntityIn
Entity: entity,
}, nil
}

func (s *gRPCSystemViewServer) PluginEnv(ctx context.Context, _ *pb.Empty) (*pb.PluginEnvReply, error) {
pluginEnv, err := s.impl.PluginEnv(ctx)
if err != nil {
return &pb.PluginEnvReply{
Err: pb.ErrToString(err),
}, nil
}
return &pb.PluginEnvReply{
PluginEnvironment: pluginEnv,
}, nil
}
29 changes: 29 additions & 0 deletions logical/plugin/grpc_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,32 @@ func TestSystem_GRPC_entityInfo(t *testing.T) {
t.Fatalf("expected: %v, got: %v", sys.EntityVal, actual)
}
}

func TestSystem_GRPC_pluginEnv(t *testing.T) {
sys := logical.TestSystemView()
sys.PluginEnvironment = &logical.PluginEnvironment{
VaultVersion: "0.10.42",
}
client, _ := plugin.TestGRPCConn(t, func(s *grpc.Server) {
pb.RegisterSystemViewServer(s, &gRPCSystemViewServer{
impl: sys,
})
})
defer client.Close()

testSystemView := newGRPCSystemView(client)

expected, err := sys.PluginEnv(context.Background())
if err != nil {
t.Fatal(err)
}

actual, err := testSystemView.PluginEnv(context.Background())
if err != nil {
t.Fatal(err)
}

if !proto.Equal(expected, actual) {
t.Fatalf("expected: %v, got: %v", expected, actual)
}
}
Loading

0 comments on commit bb180b8

Please sign in to comment.