From 8b2ef803366d9ab25e010ccee0ba5df63c062a93 Mon Sep 17 00:00:00 2001 From: acpana <8968914+acpana@users.noreply.github.com> Date: Wed, 27 Jul 2022 11:41:39 -0700 Subject: [PATCH 1/3] sync w ent Signed-off-by: acpana <8968914+acpana@users.noreply.github.com> --- agent/rpc/peering/service.go | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/agent/rpc/peering/service.go b/agent/rpc/peering/service.go index 86a8b11dc3..a30eae21b5 100644 --- a/agent/rpc/peering/service.go +++ b/agent/rpc/peering/service.go @@ -346,8 +346,7 @@ func (s *Server) Establish( return nil, err } - // we don't want to default req.Partition unlike because partitions are empty in OSS - if err := s.validatePeeringInPartition(tok.PeerID, req.Partition); err != nil { + if err := s.validatePeeringInPartition(tok.PeerID, entMeta.PartitionOrDefault()); err != nil { return nil, err } @@ -409,8 +408,15 @@ func (s *Server) validatePeeringInPartition(remotePeerID, partition string) erro return fmt.Errorf("cannot read peering by ID: %w", err) } - if peering != nil && peering.Partition == partition { - return fmt.Errorf("cannot create a peering within the same partition (ENT) or cluster (OSS)") + if peering != nil { + stateStorePart := peering.Partition + if stateStorePart == "" { + stateStorePart = "default" + } + + if stateStorePart == partition { + return fmt.Errorf("cannot create a peering within the same partition (ENT) or cluster (OSS)") + } } return nil From 0351ca5136b4aa70b1fe8a8ef5ff5dff17922528 Mon Sep 17 00:00:00 2001 From: acpana <8968914+acpana@users.noreply.github.com> Date: Wed, 27 Jul 2022 14:28:08 -0700 Subject: [PATCH 2/3] better fix Signed-off-by: acpana <8968914+acpana@users.noreply.github.com> --- agent/rpc/peering/service.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/agent/rpc/peering/service.go b/agent/rpc/peering/service.go index a30eae21b5..3956ba9f65 100644 --- a/agent/rpc/peering/service.go +++ b/agent/rpc/peering/service.go @@ -346,7 +346,7 @@ func (s *Server) Establish( return nil, err } - if err := s.validatePeeringInPartition(tok.PeerID, entMeta.PartitionOrDefault()); err != nil { + if err := s.validatePeeringInPartition(tok.PeerID, entMeta.PartitionOrEmpty()); err != nil { return nil, err } @@ -408,15 +408,8 @@ func (s *Server) validatePeeringInPartition(remotePeerID, partition string) erro return fmt.Errorf("cannot read peering by ID: %w", err) } - if peering != nil { - stateStorePart := peering.Partition - if stateStorePart == "" { - stateStorePart = "default" - } - - if stateStorePart == partition { - return fmt.Errorf("cannot create a peering within the same partition (ENT) or cluster (OSS)") - } + if peering != nil && peering.GetPartition() == partition { + return fmt.Errorf("cannot create a peering within the same partition (ENT) or cluster (OSS)") } return nil From 6033584349ecb29bbd5a04c53926109f53d72b99 Mon Sep 17 00:00:00 2001 From: acpana <8968914+acpana@users.noreply.github.com> Date: Wed, 27 Jul 2022 14:48:30 -0700 Subject: [PATCH 3/3] use EqualPartitions Signed-off-by: acpana <8968914+acpana@users.noreply.github.com> --- agent/rpc/peering/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/agent/rpc/peering/service.go b/agent/rpc/peering/service.go index 3956ba9f65..ae2c3974ae 100644 --- a/agent/rpc/peering/service.go +++ b/agent/rpc/peering/service.go @@ -408,7 +408,7 @@ func (s *Server) validatePeeringInPartition(remotePeerID, partition string) erro return fmt.Errorf("cannot read peering by ID: %w", err) } - if peering != nil && peering.GetPartition() == partition { + if peering != nil && acl.EqualPartitions(peering.GetPartition(), partition) { return fmt.Errorf("cannot create a peering within the same partition (ENT) or cluster (OSS)") }