2026-01-28 11:05:07 -06:00
|
|
|
// Copyright IBM Corp. 2020, 2025
|
2022-03-09 08:54:18 -05:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-02-02 17:15:17 -08:00
|
|
|
|
2022-03-09 08:54:18 -05:00
|
|
|
package session
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
|
|
|
|
|
"github.com/hashicorp/boundary/internal/errors"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// CloseConnections is a domain service function that:
|
|
|
|
|
// * closes requested connections
|
|
|
|
|
// * uses the sessionId of the connection to see if the session meets conditions for termination
|
|
|
|
|
func CloseConnections(ctx context.Context, sessionRepoFn *Repository, connectionRepoFn *ConnectionRepository,
|
2022-04-19 11:42:54 -04:00
|
|
|
closeWiths []CloseWith,
|
|
|
|
|
) ([]closeConnectionResp, error) {
|
2022-03-09 08:54:18 -05:00
|
|
|
const op = "session.AuthorizeConnection"
|
|
|
|
|
|
|
|
|
|
closeInfos, err := connectionRepoFn.closeConnections(ctx, closeWiths)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, errors.Wrap(ctx, err, op)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attempt to terminate only once per sessionId
|
|
|
|
|
sessionIdsProcessed := make(map[string]bool)
|
|
|
|
|
for _, c := range closeInfos {
|
|
|
|
|
if !sessionIdsProcessed[c.Connection.SessionId] {
|
|
|
|
|
sessionRepoFn.terminateSessionIfPossible(ctx, c.Connection.SessionId)
|
|
|
|
|
sessionIdsProcessed[c.Connection.SessionId] = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return closeInfos, nil
|
|
|
|
|
}
|