Skip to content

Commit 6b602ff

Browse files
author
Tomas Urbonaitis
committed
Fixing StyleCop issues
1 parent f8719b2 commit 6b602ff

4 files changed

Lines changed: 59 additions & 52 deletions

File tree

GVFS/GVFS.Common/Git/GitProcess.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ public bool TryGetConfigUrlMatch(string section, string repositoryUrl, out Dicti
313313
configSettings = null;
314314
return false;
315315
}
316+
316317
configSettings = GitConfigHelper.ParseKeyValues(result.Output, ' ');
317318
return true;
318319
}

GVFS/GVFS.Common/Git/GitSslSettings.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,39 @@
22
using System.Linq;
33

44
namespace GVFS.Common.Git
5-
{
5+
{
66
public struct GitSslSettings
77
{
8+
public readonly string SslCertificate;
9+
public readonly bool SslCertPasswordProtected;
10+
811
public GitSslSettings(IDictionary<string, GitConfigSetting> configSettings)
912
{
1013
if (configSettings != null)
1114
{
1215
if (configSettings.TryGetValue(GitConfigSetting.SslCert, out var sslCerts))
1316
{
14-
SslCertificate = sslCerts.Values.Single();
17+
this.SslCertificate = sslCerts.Values.Single();
1518
}
1619
else
1720
{
18-
SslCertificate = default(string);
21+
this.SslCertificate = default(string);
1922
}
2023

2124
if (configSettings.TryGetValue(GitConfigSetting.SslCertPasswordProtected, out var isSslCertPasswordProtected))
2225
{
23-
SslCertPasswordProtected = isSslCertPasswordProtected.Values.Select(bool.Parse).Single();
26+
this.SslCertPasswordProtected = isSslCertPasswordProtected.Values.Select(bool.Parse).Single();
2427
}
2528
else
2629
{
27-
SslCertPasswordProtected = false;
30+
this.SslCertPasswordProtected = false;
2831
}
2932
}
3033
else
3134
{
32-
SslCertificate = default(string);
33-
SslCertPasswordProtected = default(bool);
35+
this.SslCertificate = default(string);
36+
this.SslCertPasswordProtected = default(bool);
3437
}
3538
}
36-
public readonly string SslCertificate;
37-
public readonly bool SslCertPasswordProtected;
3839
}
3940
}

GVFS/GVFS.Common/Http/ConfigHttpRequestor.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ public bool TryQueryGVFSConfig(bool logErrors, out ServerGVFSConfig serverGVFSCo
8888
httpStatus = httpException.StatusCode;
8989
}
9090

91-
this.Tracer.RelatedError(new EventMetadata
92-
{
93-
{"Exception", output.Error}
94-
}, "TryQueryGVFSConfig failed");
91+
this.Tracer.RelatedError(
92+
new EventMetadata
93+
{
94+
{ "Exception", output.Error }
95+
},
96+
"TryQueryGVFSConfig failed");
9597

9698
return false;
9799
}

GVFS/GVFS.Common/Http/HttpRequestor.cs

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public abstract class HttpRequestor : IDisposable
2323

2424
private readonly ProductInfoHeaderValue userAgentHeader;
2525

26-
private HttpClient client;
2726
private readonly GitAuthentication authentication;
2827

2928
private readonly Lazy<X509Store> store = new Lazy<X509Store>(() =>
@@ -33,6 +32,8 @@ public abstract class HttpRequestor : IDisposable
3332
return s;
3433
});
3534

35+
private HttpClient client;
36+
3637
static HttpRequestor()
3738
{
3839
ServicePointManager.SecurityProtocol = ServicePointManager.SecurityProtocol | SecurityProtocolType.Tls12;
@@ -63,9 +64,10 @@ protected HttpRequestor(ITracer tracer, RetryConfig retryConfig, Enlistment enli
6364
string certificatePassword = null;
6465
if (enlistment.GitSslSettings.SslCertPasswordProtected)
6566
{
66-
certificatePassword = LoadCertificatePassword(enlistment.GitSslSettings.SslCertificate, enlistment.CreateGitProcess());
67+
certificatePassword = this.LoadCertificatePassword(enlistment.GitSslSettings.SslCertificate, enlistment.CreateGitProcess());
6768
}
68-
var cert = LoadCertificate(enlistment.GitSslSettings.SslCertificate, certificatePassword);
69+
70+
var cert = this.LoadCertificate(enlistment.GitSslSettings.SslCertificate, certificatePassword);
6971
if (cert != null)
7072
{
7173
httpClientHandler.ClientCertificates.Add(cert);
@@ -80,38 +82,6 @@ protected HttpRequestor(ITracer tracer, RetryConfig retryConfig, Enlistment enli
8082
this.userAgentHeader = new ProductInfoHeaderValue(ProcessHelper.GetEntryClassName(), ProcessHelper.GetCurrentProcessVersion());
8183
}
8284

83-
private string LoadCertificatePassword(string certId, GitProcess git)
84-
{
85-
if (git.TryGetCertificatePassword(this.Tracer, certId, out var password, out var error))
86-
{
87-
return password;
88-
}
89-
90-
return null;
91-
}
92-
93-
private X509Certificate2 LoadCertificate(string certId, string certificatePassword)
94-
{
95-
if (File.Exists(certId))
96-
{
97-
return new X509Certificate2(certId, certificatePassword);
98-
}
99-
#if DEBUG
100-
// Allow invalid (self-signed) client certificates while debugging
101-
var onlyValidCertificates = false;
102-
#else
103-
var onlyValidCertificates = true;
104-
#endif
105-
var findResults = store.Value.Certificates.Find(X509FindType.FindBySubjectName, certId, onlyValidCertificates);
106-
if (findResults?.Count > 0)
107-
{
108-
return findResults[0];
109-
}
110-
111-
this.Tracer.RelatedError("Certificate {0} not found", certId);
112-
return null;
113-
}
114-
11585
public RetryConfig RetryConfig { get; }
11686

11787
protected ITracer Tracer { get; }
@@ -129,9 +99,9 @@ public void Dispose()
12999
this.client = null;
130100
}
131101

132-
if (store.IsValueCreated)
102+
if (this.store.IsValueCreated)
133103
{
134-
store.Value.Close();
104+
this.store.Value.Close();
135105
}
136106
}
137107

@@ -157,6 +127,7 @@ protected GitEndPointResponseData SendRequest(
157127
}
158128

159129
HttpRequestMessage request = new HttpRequestMessage(httpMethod, requestUri);
130+
160131
// By default, VSTS auth failures result in redirects to SPS to reauthenticate.
161132
// To provide more consistent behavior when using the GCM, have them send us 401s instead
162133
request.Headers.Add("X-TFS-FedAuthRedirect", "Suppress");
@@ -311,8 +282,8 @@ protected GitEndPointResponseData SendRequest(
311282
}
312283

313284
return gitEndPointResponseData;
314-
}
315-
285+
}
286+
316287
private static bool ShouldRetry(HttpStatusCode statusCode)
317288
{
318289
// Retry timeout, Unauthorized, and 5xx errors
@@ -337,5 +308,37 @@ private static string GetSingleHeaderOrEmpty(HttpHeaders headers, string headerN
337308

338309
return string.Empty;
339310
}
311+
312+
private string LoadCertificatePassword(string certId, GitProcess git)
313+
{
314+
if (git.TryGetCertificatePassword(this.Tracer, certId, out var password, out var error))
315+
{
316+
return password;
317+
}
318+
319+
return null;
320+
}
321+
322+
private X509Certificate2 LoadCertificate(string certId, string certificatePassword)
323+
{
324+
if (File.Exists(certId))
325+
{
326+
return new X509Certificate2(certId, certificatePassword);
327+
}
328+
#if DEBUG
329+
// Allow invalid (self-signed) client certificates while debugging
330+
var onlyValidCertificates = false;
331+
#else
332+
var onlyValidCertificates = true;
333+
#endif
334+
var findResults = this.store.Value.Certificates.Find(X509FindType.FindBySubjectName, certId, onlyValidCertificates);
335+
if (findResults?.Count > 0)
336+
{
337+
return findResults[0];
338+
}
339+
340+
this.Tracer.RelatedError("Certificate {0} not found", certId);
341+
return null;
342+
}
340343
}
341344
}

0 commit comments

Comments
 (0)