Skip to content

Commit

Permalink
Micro-batching for logs sending, restricted access to internal classe…
Browse files Browse the repository at this point in the history
…s, no op registrar implementation
  • Loading branch information
SergeyBrenko committed Apr 14, 2021
1 parent 2961933 commit 51478a1
Show file tree
Hide file tree
Showing 34 changed files with 424 additions and 142 deletions.
2 changes: 1 addition & 1 deletion Client/Requests/ArtifactReference.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ZafiraIntegration.Client.Requests
{
public class ArtifactReference
internal class ArtifactReference
{
public string Name { get; }
public string Value { get; }
Expand Down
2 changes: 1 addition & 1 deletion Client/Requests/FinishTestRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ZafiraIntegration.Client.Requests
{
public class FinishTestRequest
internal class FinishTestRequest
{
public DateTime EndedAt { get; set; }
public string Result { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Client/Requests/FinishTestRunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ZafiraIntegration.Client.Requests
{
public class FinishTestRunRequest
internal class FinishTestRunRequest
{
public DateTime EndedAt { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions Client/Requests/Label.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace ZafiraIntegration.Client.Requests
{
public class Label
internal class Label
{
public string Key { get; }
public string Value { get; }

public Label(string key, string value)
internal Label(string key, string value)
{
Key = key;
Value = value;
Expand Down
2 changes: 1 addition & 1 deletion Client/Requests/Log.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ZafiraIntegration.Client.Requests
{
public class Log
internal class Log
{
public long TestId { get; set; }
public string Message { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Client/Requests/RefreshAccessTokenRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ZafiraIntegration.Client.Requests
{
public class RefreshAccessTokenRequest
internal class RefreshAccessTokenRequest
{
public string RefreshToken { get; set; }
}
Expand Down
4 changes: 3 additions & 1 deletion Client/Requests/StartTestRequest.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using System;
using System.Collections.Generic;

namespace ZafiraIntegration.Client.Requests
{
public class StartTestRequest
internal class StartTestRequest
{
public string Name { get; set; }
public string CorrelationData { get; set; }
Expand All @@ -11,5 +12,6 @@ public class StartTestRequest
public DateTime StartedAt { get; set; }
public string Maintainer { get; set; }
public string TestCase { get; set; }
public List<Label> Labels { get; set; }
}
}
6 changes: 3 additions & 3 deletions Client/Requests/StartTestRunRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ZafiraIntegration.Client.Requests
{
public class StartTestRunRequest
internal class StartTestRunRequest
{
public string Uuid { get; set; }
public string Name { get; set; }
Expand All @@ -11,13 +11,13 @@ public class StartTestRunRequest
public ConfigDto Config { get; set; }
public JenkinsContextDto JenkinsContext { get; set; }

public class ConfigDto
internal class ConfigDto
{
public string Environment { get; set; }
public string Build { get; set; }
}

public class JenkinsContextDto
internal class JenkinsContextDto
{
public string JobUrl { get; set; }
public string JobNumber { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion Client/Responses/RefreshAccessTokenResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ZafiraIntegration.Client.Responses
{
public class RefreshAccessTokenResponse
internal class RefreshAccessTokenResponse
{
public string AuthToken { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion Client/Responses/SaveTestResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ZafiraIntegration.Client.Responses
{
public class SaveTestResponse
internal class SaveTestResponse
{
public long Id { get; set; }
public string Name { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions Client/Responses/SaveTestRunResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace ZafiraIntegration.Client.Responses
{
public class SaveTestRunResponse
internal class SaveTestRunResponse
{
public long Id { get; set; }
public string Uuid { get; set; }
Expand All @@ -13,7 +13,7 @@ public class SaveTestRunResponse
public string Framework { get; set; }
public ConfigDto Config { get; set; }

public class ConfigDto
internal class ConfigDto
{
public string Environment { get; set; }
public string Build { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions Client/ZebrunnerApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@

namespace ZafiraIntegration.Client
{
public class ZebrunnerApiClient
internal class ZebrunnerApiClient
{
internal static ZebrunnerApiClient Instance { get; } = new ZebrunnerApiClient();
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();

private readonly RestClient _restClient;
private readonly string authenticationToken;
private readonly string _authenticationToken;

private ZebrunnerApiClient()
{
Expand All @@ -33,7 +33,7 @@ private ZebrunnerApiClient()

var response = _restClient.Post<RefreshAccessTokenResponse>(request);
_restClient.Authenticator = new JwtAuthenticator(response.Data.AuthToken);
this.authenticationToken = response.Data.AuthToken;
_authenticationToken = response.Data.AuthToken;
}

private static string Iam(string resourceUri)
Expand Down Expand Up @@ -99,7 +99,7 @@ public void UploadScreenshot(long testRunId, long testId, byte[] bytes, DateTime
{
var httpClient = new HttpClient {BaseAddress = new Uri(Configuration.GetServerHost())};
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", authenticationToken);
new AuthenticationHeaderValue("Bearer", _authenticationToken);

var httpContent = new ByteArrayContent(bytes);
httpContent.Headers.ContentType = new MediaTypeHeaderValue("image/png");
Expand Down
42 changes: 27 additions & 15 deletions Config/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using ZafiraIntegration.Config.Provider;

namespace ZafiraIntegration.Config
{
public static class Configuration
internal static class Configuration
{
private static readonly List<IConfigurationProvider> ConfigurationProviders = new List<IConfigurationProvider>
{
new EnvironmentVariablesConfigurationProvider()
};

public static bool IsReportingEnabled()
internal static bool IsReportingEnabled()
{
return ConfigurationProviders
.Select(provider => provider.IsReportingEnabled())
.First(isReportingEnabled => isReportingEnabled);
.FirstOrDefault(isReportingEnabled => isReportingEnabled);
}

public static string GetServerHost()
internal static string GetServerHost()
{
return ConfigurationProviders
.Select(provider => provider.GetServerHost())
.First(serverHost => serverHost != null && serverHost.Trim().Length != 0);
return GetStringProperty(provider => provider.GetServerHost());
}

public static string GetAccessToken()
internal static string GetAccessToken()
{
return ConfigurationProviders
.Select(provider => provider.GetAccessToken())
.First(accessToken => accessToken != null && accessToken.Trim().Length != 0);
return GetStringProperty(provider => provider.GetAccessToken());
}

internal static string GetProjectKey()
{
return GetStringProperty(provider => provider.GetProjectKey());
}

internal static string GetEnvironment()
{
return GetStringProperty(provider => provider.GetEnvironment());
}

internal static string GetBuild()
{
return GetStringProperty(provider => provider.GetBuild());
}

public static string GetProjectKey()
private static string GetStringProperty(Func<IConfigurationProvider, string> propertyResolver)
{
return ConfigurationProviders
.Select(provider => provider.GetProjectKey())
.First(projectKey => projectKey != null && projectKey.Trim().Length != 0);
.Select(propertyResolver)
.FirstOrDefault(property => property != null && property.Trim().Length != 0);
}
}
}
6 changes: 5 additions & 1 deletion Config/ConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ZafiraIntegration.Config
{
public interface IConfigurationProvider
internal interface IConfigurationProvider
{
bool IsReportingEnabled();

Expand All @@ -9,5 +9,9 @@ public interface IConfigurationProvider
string GetAccessToken();

string GetProjectKey();

string GetEnvironment();

string GetBuild();
}
}
56 changes: 56 additions & 0 deletions Config/Provider/EnvironmentVariablesConfigurationProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System;

namespace ZafiraIntegration.Config.Provider
{
internal class EnvironmentVariablesConfigurationProvider : IConfigurationProvider
{
private const string ReportingEnabledLegacyEnvironmentVariable = "zafira_enabled";
private const string ReportingEnabledEnvironmentVariable = "REPORTING_ENABLED";
private const string ServerHostLegacyEnvironmentVariable = "zafira_service_url";
private const string ServerHostEnvironmentVariable = "REPORTING_SERVER_HOSTNAME";
private const string AccessTokenLegacyEnvironmentVariable = "zafira_access_token";
private const string AccessTokenEnvironmentVariable = "REPORTING_SERVER_ACCESS_TOKEN";
private const string ProjectKeyLegacyEnvironmentVariable = "zafira_project";
private const string ProjectKeyEnvironmentVariable = "REPORTING_PROJECT_KEY";
private const string EnvironmentEnvironmentVariable = "REPORTING_RUN_ENVIRONMENT";
private const string BuildEnvironmentVariable = "REPORTING_RUN_BUILD";

private const string DefaultProjectKey = "UNKNOWN";

public bool IsReportingEnabled()
{
var reportingEnabled = Environment.GetEnvironmentVariable(ReportingEnabledLegacyEnvironmentVariable)
?? Environment.GetEnvironmentVariable(ReportingEnabledEnvironmentVariable);
return string.Compare("true", reportingEnabled, StringComparison.OrdinalIgnoreCase) == 0;
}

public string GetServerHost()
{
return Environment.GetEnvironmentVariable(ServerHostLegacyEnvironmentVariable)
?? Environment.GetEnvironmentVariable(ServerHostEnvironmentVariable);
}

public string GetAccessToken()
{
return Environment.GetEnvironmentVariable(AccessTokenLegacyEnvironmentVariable)
?? Environment.GetEnvironmentVariable(AccessTokenEnvironmentVariable);
}

public string GetProjectKey()
{
return Environment.GetEnvironmentVariable(ProjectKeyLegacyEnvironmentVariable)
?? Environment.GetEnvironmentVariable(ProjectKeyEnvironmentVariable)
?? DefaultProjectKey;
}

public string GetEnvironment()
{
return Environment.GetEnvironmentVariable(EnvironmentEnvironmentVariable);
}

public string GetBuild()
{
return Environment.GetEnvironmentVariable(BuildEnvironmentVariable);
}
}
}
36 changes: 0 additions & 36 deletions Config/provider/EnvironmentVariablesConfigurationProvider.cs

This file was deleted.

Loading

0 comments on commit 51478a1

Please sign in to comment.