-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathVersionController.cs
More file actions
158 lines (134 loc) · 6.36 KB
/
VersionController.cs
File metadata and controls
158 lines (134 loc) · 6.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.
using System;
using System.Collections.Generic;
using System.Linq;
using EdFi.Common;
using EdFi.Ods.Api.Constants;
using EdFi.Ods.Api.Extensions;
using EdFi.Ods.Common.Configuration;
using EdFi.Ods.Common.Constants;
using EdFi.Ods.Common.Extensions;
using EdFi.Ods.Common.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.FeatureManagement;
// ReSharper disable InconsistentNaming
namespace EdFi.Ods.Api.Controllers
{
[ApiController]
[Produces("application/json")]
[Route("")]
[AllowAnonymous]
public class VersionController : ControllerBase
{
private readonly IFeatureManager _featureManager;
private readonly IApiVersionProvider _apiVersionProvider;
private readonly IDomainModelProvider _domainModelProvider;
private readonly ApiSettings _apiSettings;
public VersionController(
IDomainModelProvider domainModelProvider,
IApiVersionProvider apiVersionProvider,
IFeatureManager featureManager,
ApiSettings apiSettings)
{
_featureManager = Preconditions.ThrowIfNull(featureManager, nameof(featureManager));
_domainModelProvider = Preconditions.ThrowIfNull(domainModelProvider, nameof(domainModelProvider));
_apiVersionProvider = Preconditions.ThrowIfNull(apiVersionProvider, nameof(apiVersionProvider));
_apiSettings = Preconditions.ThrowIfNull(apiSettings, nameof(apiSettings));
}
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult Get()
{
var content = new VersionResponse(
_apiVersionProvider.Version,
_apiVersionProvider.ApplicationName,
_apiVersionProvider.InformationalVersion,
_apiVersionProvider.Suite,
_apiVersionProvider.Build,
_domainModelProvider.GetDomainModel()
.Schemas.Select(s => new DataModelVersion(s.LogicalName, s.Version, s.InformationalVersion))
.ToArray(),
GetUrlsByName());
return Ok(content);
Dictionary<string, string> GetUrlsByName()
{
var urlsByName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
var rootUrl = Request.RootUrl(_apiSettings.GetReverseProxySettings());
if (_featureManager.IsFeatureEnabled(ApiFeature.MultiTenancy))
{
if (HttpContext.Request.RouteValues.TryGetValue("tenantIdentifier", out object tenantIdentifier))
{
rootUrl = $"{rootUrl}/{tenantIdentifier}";
}
else
{
rootUrl = $"{rootUrl}/{{tenantIdentifier}}";
}
}
if (!string.IsNullOrEmpty(_apiSettings.OdsContextRouteTemplate))
{
string odsContextUriTemplatePath = _apiSettings.GetOdsContextRoutePath();
string[] odsContextRouteKeys = _apiSettings.GetOdsContextRouteTemplateKeys();
// Perform URI template replacements from route values, if available on current request
foreach (string odsContextRouteKey in odsContextRouteKeys)
{
if (HttpContext.Request.RouteValues.TryGetValue(odsContextRouteKey, out object odsContextRouteValue))
{
odsContextUriTemplatePath = odsContextUriTemplatePath.Replace(
$"{{{odsContextRouteKey}}}",
(string)odsContextRouteValue);
}
}
rootUrl = $"{rootUrl}/{odsContextUriTemplatePath}";
}
if (_featureManager.IsFeatureEnabled(ApiFeature.AggregateDependencies))
{
urlsByName["dependencies"] = $"{rootUrl}/metadata/data/v{ApiVersionConstants.Ods}/dependencies";
}
if (_featureManager.IsFeatureEnabled(ApiFeature.OpenApiMetadata))
{
urlsByName["openApiMetadata"] = $"{rootUrl}/metadata/";
}
urlsByName["oauth"] = $"{rootUrl}/oauth/token";
urlsByName["oauthTokenIntrospection"] = $"{rootUrl}/oauth/token_info";
urlsByName["dataManagementApi"] = $"{rootUrl}/data/v{ApiVersionConstants.Ods}/";
if (_featureManager.IsFeatureEnabled(ApiFeature.XsdMetadata))
{
urlsByName["xsdMetadata"] = $"{rootUrl}/metadata/xsd";
}
if (_featureManager.IsFeatureEnabled(ApiFeature.ChangeQueries))
{
urlsByName["changeQueries"] = $"{rootUrl}/changeQueries/v{ApiVersionConstants.ChangeQuery}/";
}
if (_featureManager.IsFeatureEnabled(ApiFeature.Composites))
{
urlsByName["composites"] = $"{rootUrl}/composites/v{ApiVersionConstants.Composite}/";
}
if (_featureManager.IsFeatureEnabled(ApiFeature.IdentityManagement))
{
urlsByName["identity"] = $"{rootUrl}/identity/v{ApiVersionConstants.Identity}/";
}
if (_featureManager.IsFeatureEnabled(ApiFeature.OneRoster)
&& !string.IsNullOrEmpty(_apiSettings.OneRosterVersionUrl))
{
urlsByName["oneRoster"] = _apiSettings.OneRosterVersionUrl;
}
return urlsByName;
}
}
public record VersionResponse(
string version,
string applicationName,
string informationalVersion,
string suite,
string build,
DataModelVersion[] dataModels,
Dictionary<string, string> urls);
public record DataModelVersion(string name, string version, string informationalVersion);
}
}