func (s *Server) EntityCreate(ctx context.Context, r *pb.EntityRequest) (*pb.Empty, error) {
	if err := s.mutablePrequisitesMet(ctx, types.Capability_CREATE_ENTITY); err != nil {
		return &pb.Empty{}, err
	}
	e := r.GetEntity()
	switch err := s.CreateEntity(e.GetID(), e.GetNumber(), e.GetSecret()); err {
	case tree.ErrDuplicateEntityID, tree.ErrDuplicateNumber:
		s.log.Warn("Attempt to create duplicate entity",
			"entity", e.GetID(),
			"authority", getTokenClaims(ctx).EntityID,
			"service", getServiceName(ctx),
			"client", getClientName(ctx),
			"error", err,
		)
		return &pb.Empty{}, ErrExists
	case nil:
		s.log.Info("Entity Created",
			"entity", e.GetID(),
			"authority", getTokenClaims(ctx).EntityID,
			"service", getServiceName(ctx),
			"client", getClientName(ctx),
			"error", err,
		)
		return &pb.Empty{}, nil
	default:
		s.log.Warn("Error Creating Entity",
			"entity", e.GetID(),
			"authority", getTokenClaims(ctx).EntityID,
			"service", getServiceName(ctx),
			"client", getClientName(ctx),
			"error", err,
		)
		return &pb.Empty{}, ErrInternal
	}
}
EntityCreate creates entities.  This call will validate that a
correct token is held, which must contain either CREATE_ENTITY or
GLOBAL_ROOT permissions.
package rpc2
import (
	"context"
	"github.com/netauth/netauth/internal/db"
	"github.com/netauth/netauth/internal/tree"
	types "github.com/netauth/protocol"
	pb "github.com/netauth/protocol/v2"
)