-
Notifications
You must be signed in to change notification settings - Fork 676
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
MG-2301 - Verify connections during adding of bootstrap config #2371
base: main
Are you sure you want to change the base?
Conversation
things/things.go
Outdated
@@ -33,6 +33,9 @@ type Service interface { | |||
// the provided key. | |||
ListClientsByGroup(ctx context.Context, token, groupID string, pm clients.Page) (clients.MembersPage, error) | |||
|
|||
// VerifyConnections verifies if a list of channels is connected to a list of channels. | |||
VerifyConnections(ctx context.Context, token string, thingID, groupID []string) (clients.ConnectionsPage, error) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of thingID
groupID
we can have like thingIDs
and groupIDs
, since they are slice
auth/service.go
Outdated
func (svc service) VerifyConnections(ctx context.Context, thingsId, channelsId []string) (ConnectionsPage, error) { | ||
uniqueThings := getUniqueValues(thingsId) | ||
uniqueChannels := getUniqueValues(channelsId) | ||
|
||
cp := ConnectionsPage{} | ||
totalConnectionsCount := len(uniqueChannels) * len(uniqueThings) | ||
totalConnectedCount := 0 | ||
|
||
cp.Connections = make([]ConnectionStatus, 0, totalConnectionsCount) | ||
|
||
for _, th := range uniqueThings { | ||
for _, ch := range uniqueChannels { | ||
err := svc.agent.CheckPolicy(ctx, PolicyReq{ | ||
Subject: ch, | ||
SubjectType: GroupType, | ||
Permission: GroupRelation, | ||
Object: th, | ||
ObjectType: ThingType, | ||
}) | ||
var status string | ||
switch { | ||
case err == nil: | ||
status = connected | ||
totalConnectedCount++ | ||
case errors.Contains(err, svcerr.ErrAuthorization): | ||
status = disconnected | ||
default: | ||
return ConnectionsPage{}, errors.Wrap(svcerr.ErrMalformedEntity, err) | ||
} | ||
|
||
cp.Connections = append(cp.Connections, ConnectionStatus{ | ||
ThingId: th, | ||
ChannelId: ch, | ||
Status: status, | ||
}) | ||
} | ||
} | ||
|
||
switch { | ||
case totalConnectedCount == totalConnectionsCount: | ||
cp.Status = allConn | ||
case totalConnectedCount == 0: | ||
cp.Status = allDisConn | ||
default: | ||
cp.Status = partConn | ||
} | ||
|
||
return cp, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can have this logic in Things service,
Like things service will verify connection via auth gRPC connection.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be inefficent if we move this logic to things service, but in future we can have direct grpc connection to spiceDB from things service.
5b81926
to
0928b17
Compare
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
Signed-off-by: nyagamunene <[email protected]>
What type of PR is this?
This is a bug fix because it fixes the following issue: #2301
What does this do?
It adds verify connections in the
add
method in bootstrap.Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
Yes
Did you document any new/modified feature?
N/A
Notes