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 1 commit
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
14 changes: 14 additions & 0 deletions logical/identity.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
package logical

// Entity represents the inforamtion that is returned to backends when
// querying entity information through the system view
type Entity struct {
// ID is the unique identifier for the entity
ID string `json:"id"`

// Name is a human-friendly unique identifier for the entity.
Name string `json:"name"`

// Aliases contains the unique identifiers assigned by the
// auth methods
Aliases []*Alias `json:"aliases"`
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead have this be a proto message here, that will remove the translations for plugins


// Alias represents the information used by core to create implicit entity.
// Implicit entities get created when a client authenticates successfully from
// any of the authentication backends (except token backend).
Expand Down
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 pb.ProtoEntityToLogicalEntity(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: pb.LogicalEntityToProtoEntity(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