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

Add entity information request to system view #4681

Merged
merged 9 commits into from
Jun 4, 2018
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ proto:
protoc -I helper/forwarding -I vault -I ../../.. vault/*.proto --go_out=plugins=grpc:vault
protoc -I helper/storagepacker helper/storagepacker/types.proto --go_out=plugins=grpc:helper/storagepacker
protoc -I helper/forwarding -I vault -I ../../.. helper/forwarding/types.proto --go_out=plugins=grpc:helper/forwarding
protoc logical/*.proto --go_out=plugins=grpc:$(GOPATH)/src
protoc -I physical physical/types.proto --go_out=plugins=grpc:physical
protoc -I helper/identity -I ../../.. helper/identity/types.proto --go_out=plugins=grpc:helper/identity
protoc builtin/logical/database/dbplugin/*.proto --go_out=plugins=grpc:.
Expand Down
16 changes: 0 additions & 16 deletions logical/identity.go

This file was deleted.

159 changes: 159 additions & 0 deletions logical/identity.pb.go

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

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

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

package logical;

message Entity {
// ID is the unique identifier for the entity
string ID = 1;

// Name is the human-friendly unique identifier for the entity
string name = 2;

// Aliases contains thhe alias mappings for the given entity
repeated Alias aliases = 3;
}

message Alias {
// MountType is the backend mount's type to which this identity belongs
string mount_type = 1;

// MountAccessor is the identifier of the mount entry to which this
// identity belongs
string mount_accessor = 2;

// Name is the identifier of this identity in its authentication source
string name = 3;
}

26 changes: 26 additions & 0 deletions logical/plugin/grpc_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,20 @@ func (s *gRPCSystemViewClient) LocalMount() bool {
return reply.Local
}

func (s *gRPCSystemViewClient) EntityInfo(entityID string) (*logical.Entity, error) {
reply, err := s.client.EntityInfo(context.Background(), &pb.EntityInfoArgs{
EntityID: entityID,
})
if err != nil {
return nil, err
}
if reply.Err != "" {
return nil, errors.New(reply.Err)
}

return reply.Entity, nil
}

type gRPCSystemViewServer struct {
impl logical.SystemView
}
Expand Down Expand Up @@ -216,3 +230,15 @@ func (s *gRPCSystemViewServer) LocalMount(ctx context.Context, _ *pb.Empty) (*pb
Local: local,
}, nil
}

func (s *gRPCSystemViewServer) EntityInfo(ctx context.Context, args *pb.EntityInfoArgs) (*pb.EntityInfoReply, error) {
entity, err := s.impl.EntityInfo(args.EntityID)
if err != nil {
return &pb.EntityInfoReply{
Err: pb.ErrToString(err),
}, nil
}
return &pb.EntityInfoReply{
Entity: entity,
}, nil
}
23 changes: 23 additions & 0 deletions logical/plugin/grpc_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,26 @@ func TestSystem_GRPC_mlockEnabled(t *testing.T) {
t.Fatalf("expected: %v, got: %v", expected, actual)
}
}

func TestSystem_GRPC_entityInfo(t *testing.T) {
sys := logical.TestSystemView()
sys.EntityVal = &logical.Entity{
ID: "id",
Name: "name",
}
client, _ := plugin.TestGRPCConn(t, func(s *grpc.Server) {
pb.RegisterSystemViewServer(s, &gRPCSystemViewServer{
impl: sys,
})
})
defer client.Close()
testSystemView := newGRPCSystemView(client)

actual, err := testSystemView.EntityInfo("")
if err != nil {
t.Fatal(err)
}
if sys.EntityVal.ID != actual.ID || sys.EntityVal.Name != actual.Name {
t.Fatalf("expected: %v, got: %v", sys.EntityVal, actual)
}
}
Loading