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

[ODS-5759] Investigate how change query snapshots would work with read-only connection configuration #688

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
using EdFi.Ods.Common.Constants;
using EdFi.Ods.Common.Models.Queries;
using EdFi.Ods.Common.Models.Validation;
using EdFi.Ods.Common.Security.Claims;
using EdFi.Ods.Features.ChangeQueries.Repositories.Snapshots;
using EdFi.Security.DataAccess.Repositories;
using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand All @@ -26,6 +28,8 @@ namespace EdFi.Ods.Features.ChangeQueries.Controllers
[Route("snapshots")]
public class SnapshotsController : ControllerBase
{
private readonly IAuthorizationContextProvider _authorizationContextProvider;
private readonly ISecurityRepository _securityRepository;
private readonly IGetSnapshots _getSnapshots;
private readonly ILog _logger = LogManager.GetLogger(typeof(SnapshotsController));
private readonly bool _isEnabled;
Expand All @@ -36,8 +40,12 @@ public class SnapshotsController : ControllerBase
// when the feature is disabled (and the IGetSnapshots service is not registered).
public SnapshotsController(ApiSettings apiSettings,
IDefaultPageSizeLimitProvider defaultPageSizeLimitProvider,
IAuthorizationContextProvider authorizationContextProvider,
ISecurityRepository securityRepository,
IGetSnapshots getSnapshots = null)
{
_authorizationContextProvider = authorizationContextProvider;
_securityRepository = securityRepository;
_getSnapshots = getSnapshots;
_isEnabled = apiSettings.IsFeatureEnabled(ApiFeature.ChangeQueries.GetConfigKeyName());
_defaultPageLimitSize = defaultPageSizeLimitProvider.GetDefaultPageSizeLimit();
Expand Down Expand Up @@ -67,6 +75,9 @@ public async Task<IActionResult> GetAll([FromQuery] UrlQueryParametersRequest ur
Response.Headers.Add("Total-Count", count.ToString());
}

// Set the authorization context for action (to ensure read-replica connection is used, if defined)
_authorizationContextProvider.SetAction(_securityRepository.GetActionByName("ReadChanges").ActionUri);

var snapshots = await _getSnapshots.GetAllAsync(new QueryParameters(urlQueryParametersRequest));
return Ok(snapshots);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
using EdFi.Ods.Common.Extensions;
using EdFi.Ods.Common.Metadata;
using EdFi.Ods.Common.Metadata.Composites;
using EdFi.Ods.Common.Security.Claims;
using EdFi.Ods.Features.Composites.Infrastructure;
using EdFi.Security.DataAccess.Repositories;
using log4net;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -50,17 +52,23 @@ private static readonly HashSet<string> _standardApiRouteKeys
private readonly ICompositeResourceResponseProvider _compositeResourceResponseProvider;
private readonly ILog _logger = LogManager.GetLogger(typeof(CompositeResourceController));
private readonly IRESTErrorProvider _restErrorProvider;
private readonly IAuthorizationContextProvider _authorizationContextProvider;
private readonly ISecurityRepository _securityRepository;
private readonly bool _isEnabled;

public CompositeResourceController(
ICompositeResourceResponseProvider compositeResourceResponseProvider,
ICompositesMetadataProvider compositeMetadataProvider,
IRESTErrorProvider restErrorProvider,
ApiSettings apiSettings)
ApiSettings apiSettings,
IAuthorizationContextProvider authorizationContextProvider,
ISecurityRepository securityRepository)
{
_compositeResourceResponseProvider = compositeResourceResponseProvider;
_compositeMetadataProvider = compositeMetadataProvider;
_restErrorProvider = restErrorProvider;
_authorizationContextProvider = authorizationContextProvider;
_securityRepository = securityRepository;
_isEnabled = apiSettings.IsFeatureEnabled(ApiFeature.Composites.GetConfigKeyName());
}

Expand Down Expand Up @@ -137,6 +145,9 @@ public virtual IActionResult Get()

AddInherentSupportForIdParameter();

// Set the authorization context for action (to ensure read-replica connection is used, if defined)
_authorizationContextProvider.SetAction(_securityRepository.GetActionByName("Read").ActionUri);

json = _compositeResourceResponseProvider.Get(
compositeDefinition,
specificationParameters,
Expand Down