-
Notifications
You must be signed in to change notification settings - Fork 24
/
SecurityLogsApiExecutor.cs
116 lines (97 loc) · 4.44 KB
/
SecurityLogsApiExecutor.cs
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
using System.Collections.Generic;
using System.Threading.Tasks;
using Crowdin.Api.Core;
using JetBrains.Annotations;
#nullable enable
namespace Crowdin.Api.SecurityLogs
{
public class SecurityLogsApiExecutor
{
private readonly ICrowdinApiClient _apiClient;
private readonly IJsonParser _jsonParser;
public SecurityLogsApiExecutor(ICrowdinApiClient apiClient)
{
_apiClient = apiClient;
_jsonParser = apiClient.DefaultJsonParser;
}
public SecurityLogsApiExecutor(ICrowdinApiClient apiClient, IJsonParser jsonParser)
{
_apiClient = apiClient;
_jsonParser = jsonParser;
}
/// <summary>
/// List User Security Logs. Documentation:
/// <a href="https://developer.crowdin.com/api/v2/#operation/api.users.security-logs.getMany">Crowdin API</a>
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.security-logs.getMany">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<ResponseList<SecurityLog>> ListUserSecurityLogs(
long userId,
int limit = 25,
int offset = 0,
SecurityLogEventType? eventType = null,
string? ipAddress = null)
{
string url = FormUrl_Logs(userId);
IDictionary<string, string> queryParams = Utils.CreateQueryParamsFromPaging(limit, offset);
queryParams.AddDescriptionEnumValueIfPresent("event", eventType);
queryParams.AddParamIfPresent("ipAddress", ipAddress);
CrowdinApiResult result = await _apiClient.SendGetRequest(url, queryParams);
return _jsonParser.ParseResponseList<SecurityLog>(result.JsonObject);
}
/// <summary>
/// Get User Security Log. Documentation:
/// <a href="https://developer.crowdin.com/api/v2/#operation/api.users.security-logs.get">Crowdin API</a>
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.users.security-logs.get">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<SecurityLog> GetUserSecurityLog(long userId, long securityLogId)
{
string url = FormUrl_LogId(userId, securityLogId);
CrowdinApiResult result = await _apiClient.SendGetRequest(url);
return _jsonParser.ParseResponseObject<SecurityLog>(result.JsonObject);
}
#region Helper methods
private static string FormUrl_Logs(long userId)
{
return $"/users/{userId}/security-logs";
}
private static string FormUrl_LogId(long userId, long securityLogId)
{
return $"/users/{userId}/security-logs/{securityLogId}";
}
#endregion
#region Enterprise API
/// <summary>
/// List Organization Security Logs. Documentation:
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.security-logs.getMany">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<ResponseList<SecurityLog>> ListOrganizationSecurityLogs(
int limit = 25,
int offset = 0,
SecurityLogEventType? eventType = null,
string? ipAddress = null,
long? userId = null)
{
IDictionary<string, string> queryParams = Utils.CreateQueryParamsFromPaging(limit, offset);
queryParams.AddDescriptionEnumValueIfPresent("event", eventType);
queryParams.AddParamIfPresent("ipAddress", ipAddress);
queryParams.AddParamIfPresent("userId", userId);
CrowdinApiResult result = await _apiClient.SendGetRequest("/security-logs", queryParams);
return _jsonParser.ParseResponseList<SecurityLog>(result.JsonObject);
}
/// <summary>
/// Get Organization Security Log. Documentation:
/// <a href="https://developer.crowdin.com/enterprise/api/v2/#operation/api.security-logs.get">Crowdin Enterprise API</a>
/// </summary>
[PublicAPI]
public async Task<SecurityLog> GetOrganizationSecurityLog(long securityLogId)
{
var url = $"/security-logs/{securityLogId}";
CrowdinApiResult result = await _apiClient.SendGetRequest(url);
return _jsonParser.ParseResponseObject<SecurityLog>(result.JsonObject);
}
#endregion
}
}