Skip to content

Commit 3e7788b

Browse files
Refactor and cleanup
1 parent 053551d commit 3e7788b

File tree

5 files changed

+48
-18
lines changed

5 files changed

+48
-18
lines changed

src/Certify.Models/CertificateAuthorities/CertificateAuthority.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public class CertificateAuthority
110110

111111
public string? Id { get; set; }
112112
public string APIType { get; set; } = CertAuthorityAPIType.ACME_V2.ToString();
113-
public List<string> SupportedFeatures { get; set; } = new();
113+
public List<string> SupportedFeatures { get; set; } = [];
114114
public string Title { get; set; } = string.Empty;
115115
public string Description { get; set; } = string.Empty;
116116
public string WebsiteUrl { get; set; } = string.Empty;
@@ -132,21 +132,21 @@ public class CertificateAuthority
132132
public bool AllowInternalHostnames { get; set; }
133133
public bool SupportsCachedValidations { get; set; } = true;
134134
public string EabInstructions { get; set; } = string.Empty;
135-
public List<string> SupportedKeyTypes { get; set; } = new();
135+
public List<string> SupportedKeyTypes { get; set; } = [];
136136

137137
/// <summary>
138138
/// If set, lists intermediate cert for this CA which should be disabled or removed
139139
/// </summary>
140-
public List<string> DisabledIntermediates { get; set; } = new();
140+
public List<string> DisabledIntermediates { get; set; } = [];
141141

142142
/// <summary>
143143
/// Optional list of Trusted Root certificates to install for chain building and verification
144144
/// </summary>
145-
public Dictionary<string, string> TrustedRoots { get; set; } = new();
145+
public Dictionary<string, string> TrustedRoots { get; set; } = [];
146146

147147
/// <summary>
148148
/// Optional list of Intermediate certificates to install for chain building and verification
149149
/// </summary>
150-
public Dictionary<string, string> Intermediates { get; set; } = new();
150+
public Dictionary<string, string> Intermediates { get; set; } = [];
151151
}
152152
}

src/Certify.Models/Hub/HubInfo.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ public class HubInfo
66

77
public VersionInfo Version { get; set; }
88
}
9+
10+
public class HubHealth
11+
{
12+
public string Status { get; set; }
13+
public string Detail { get; set; }
14+
public string Version { get; set; }
15+
public bool ServiceAvailable { get; set; }
16+
public object env { get; set; }
17+
}
918
}

src/Certify.Server/Certify.Server.Core/Certify.Server.Core/Controllers/AccessController.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ public AccessController(ICertifyManager certifyManager, IDataProtectionProvider
1818
_dataProtectionProvider = dataProtectionProvider;
1919
}
2020

21-
private string GetContextUserId()
22-
{
23-
// TODO: sign passed value provided by public API using public APIs access token
24-
var contextUserId = Request.Headers["X-Context-User-Id"];
25-
26-
return contextUserId;
27-
}
28-
2921
[HttpPost, Route("securityprinciple")]
3022
public async Task<Models.Config.ActionResult> AddSecurityPrinciple([FromBody] SecurityPrinciple principle)
3123
{
@@ -79,7 +71,7 @@ private string GetContextUserId()
7971
}
8072

8173
[HttpGet, Route("securityprinciples")]
82-
public async Task<List<SecurityPrinciple>> GetSecurityPrinciples()
74+
public async Task<ICollection<SecurityPrinciple>> GetSecurityPrinciples()
8375
{
8476
var accessControl = await _certifyManager.GetCurrentAccessControl();
8577

@@ -95,7 +87,7 @@ public async Task<List<SecurityPrinciple>> GetSecurityPrinciples()
9587
}
9688

9789
[HttpGet, Route("roles")]
98-
public async Task<List<Role>> GetRoles()
90+
public async Task<ICollection<Role>> GetRoles()
9991
{
10092
var accessControl = await _certifyManager.GetCurrentAccessControl();
10193
return await accessControl.GetRoles(GetContextUserId());
@@ -118,15 +110,15 @@ public async Task<bool> CheckSecurityPrincipleHasAccess(AccessCheck check)
118110
}
119111

120112
[HttpGet, Route("assignedtoken/list/")]
121-
public async Task<List<AssignedAccessToken>> GetAssignedAccessTokens()
113+
public async Task<ICollection<AssignedAccessToken>> GetAssignedAccessTokens()
122114
{
123115
var accessControl = await _certifyManager.GetCurrentAccessControl();
124116

125117
return await accessControl.GetAssignedAccessTokens(GetContextUserId());
126118
}
127119

128120
[HttpPost, Route("assignedtoken/")]
129-
public async Task<Models.Config.ActionResult> AddAAssignedccessToken([FromBody] AssignedAccessToken token)
121+
public async Task<Models.Config.ActionResult> AddAssignedccessToken([FromBody] AssignedAccessToken token)
130122
{
131123
var accessControl = await _certifyManager.GetCurrentAccessControl();
132124
var addResultOk = await accessControl.AddAssignedAccessToken(GetContextUserId(), token);
@@ -139,7 +131,7 @@ public async Task<List<AssignedAccessToken>> GetAssignedAccessTokens()
139131
}
140132

141133
[HttpGet, Route("securityprinciple/{id}/assignedroles")]
142-
public async Task<List<AssignedRole>> GetSecurityPrincipleAssignedRoles(string id)
134+
public async Task<ICollection<AssignedRole>> GetSecurityPrincipleAssignedRoles(string id)
143135
{
144136
var accessControl = await _certifyManager.GetCurrentAccessControl();
145137

src/Certify.Server/Certify.Server.Core/Certify.Server.Core/Controllers/ControllerBase.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,32 @@ internal void DebugLog(string msg = null,
4747
Console.ForegroundColor = ConsoleColor.White;
4848
#endif
4949
}
50+
51+
Client.AuthContext _currentAuthContext = null;
52+
53+
/// <summary>
54+
/// Set the current auth context for the current request, only used internally when invoking controller outside of an http request
55+
/// </summary>
56+
/// <param name="authContext"></param>
57+
///
58+
[NonAction]
59+
public void SetCurrentAuthContext(Client.AuthContext authContext)
60+
{
61+
_currentAuthContext = authContext;
62+
}
63+
64+
[NonAction]
65+
public string GetContextUserId()
66+
{
67+
if (_currentAuthContext != null)
68+
{
69+
return _currentAuthContext.UserId;
70+
}
71+
72+
// TODO: sign passed value provided by public API using public APIs access token
73+
var contextUserId = Request?.Headers["X-Context-User-Id"];
74+
75+
return contextUserId;
76+
}
5077
}
5178
}

src/Certify.Server/Certify.Server.Hub.Api/Controllers/internal/HubController.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ public async Task<IActionResult> GetHubInfo()
132132

133133
hubInfo.InstanceId = hubprefs.InstanceId;
134134

135+
_mgmtStateProvider.SetManagementHubInstanceId(hubInfo.InstanceId);
136+
135137
var versionInfo = await _client.GetAppVersion();
136138

137139
hubInfo.Version = new Models.Hub.VersionInfo { Version = versionInfo, Product = "Certify Management Hub" };

0 commit comments

Comments
 (0)