Skip to content

Commit 16845ba

Browse files
authored
Style fix1 (#512)
* fix SA1505 and SA1508 * fix SA1116 * fix SA1009 * fix SA1019 * fix SA1127 * fix SA1128 * fix SA1134 * fix indent * allow CA2227 * fix CA1810 * using clean up * fix naming * fix CA1806 * fix await * Revert "fix CA1806" This reverts commit a3b4650. * fix dotnet format * allow SA1009
1 parent 82c8ae0 commit 16845ba

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+212
-179
lines changed

examples/logs/Logs.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System;
2-
using System.IO;
32
using System.Threading.Tasks;
43
using k8s;
54

@@ -22,7 +21,8 @@ private static async Task Main(string[] args)
2221

2322
var pod = list.Items[0];
2423

25-
var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync(pod.Metadata.Name,
24+
var response = await client.ReadNamespacedPodLogWithHttpMessagesAsync(
25+
pod.Metadata.Name,
2626
pod.Metadata.NamespaceProperty, follow: true).ConfigureAwait(false);
2727
var stream = response.Body;
2828
stream.CopyTo(Console.OpenStandardOutput());

kubernetes-client.ruleset

+4-4
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
<Rule Id="SA1314" Action="None" />
107107

108108
<!-- A C# using directive is placed outside of a namespace element. https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1200.md -->
109-
<Rule Id="SA1200" Action="Warning" />
109+
<Rule Id="SA1200" Action="Error" />
110110

111111
<!-- An element within a C# code file is out of order in relation to the other elements in the code. https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1201.md -->
112112
<Rule Id="SA1201" Action="None" />
@@ -175,7 +175,7 @@
175175
<Rule Id="SA1001" Action="Warning" />
176176

177177
<!-- A closing parenthesis within a C# statement is not spaced correctly. https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1009.md -->
178-
<Rule Id="SA1009" Action="Warning" />
178+
<Rule Id="SA1009" Action="None" />
179179

180180
<!-- An opening brace within a C# element is not spaced correctly. https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1012.md -->
181181
<Rule Id="SA1012" Action="Warning" />
@@ -205,10 +205,10 @@
205205
<Rule Id="CA2225" Action="None" />
206206

207207
<!-- Collection properties should be read only https://docs.microsoft.com/en-us/visualstudio/code-quality/CA2227 -->
208-
<Rule Id="CA2227" Action="Warning" />
208+
<Rule Id="CA2227" Action="None" />
209209

210210
<!-- Mark ISerializable types with SerializableAttribute https://docs.microsoft.com/en-us/visualstudio/code-quality/CA2237 -->
211-
<Rule Id="CA2237" Action="Warning" />
211+
<Rule Id="CA2237" Action="None" />
212212

213213
<!-- Do Not Disable Certificate Validation https://docs.microsoft.com/en-us/visualstudio/code-quality/CA5359 -->
214214
<Rule Id="CA5359" Action="None" />

src/KubernetesClient/Authentication/TokenFileAuth.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public TokenFileAuth(string tokenFile)
1818
TokenFile = tokenFile;
1919
}
2020

21-
public async Task<AuthenticationHeaderValue> GetAuthenticationHeaderAsync(CancellationToken cancellationToken)
21+
public Task<AuthenticationHeaderValue> GetAuthenticationHeaderAsync(CancellationToken cancellationToken)
2222
{
2323
if (TokenExpiresAt < DateTime.UtcNow)
2424
{
@@ -32,7 +32,7 @@ public async Task<AuthenticationHeaderValue> GetAuthenticationHeaderAsync(Cancel
3232
TokenExpiresAt = DateTime.UtcNow.AddMinutes(1);
3333
}
3434

35-
return new AuthenticationHeaderValue("Bearer", token);
35+
return Task.FromResult(new AuthenticationHeaderValue("Bearer", token));
3636
}
3737
}
3838
}

src/KubernetesClient/ByteBuffer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ private void Grow(int size)
282282
Array.Copy(this.buffer, 0, newBuffer, 0, this.WriteWaterMark);
283283

284284
int trailingDataLength = this.buffer.Length - this.ReadWaterMark;
285-
Array.Copy(this.buffer,
285+
Array.Copy(
286+
this.buffer,
286287
sourceIndex: this.ReadWaterMark,
287288
destinationArray: newBuffer,
288289
destinationIndex: newBuffer.Length - trailingDataLength,

src/KubernetesClient/CertUtils.cs

-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@
55
using Org.BouncyCastle.Security;
66
using Org.BouncyCastle.X509;
77
using System;
8-
using System.Collections.Generic;
98
using System.IO;
109
using System.Security.Cryptography.X509Certificates;
11-
using System.Text.RegularExpressions;
1210

1311
namespace k8s
1412
{

src/KubernetesClient/Exceptions/KubeConfigException.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
using System;
2+
13
namespace k8s.Exceptions
24
{
3-
using System;
4-
55
/// <summary>
66
/// The exception that is thrown when the kube config is invalid
77
/// </summary>

src/KubernetesClient/Exceptions/KubernetesClientException.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
using System;
2+
13
namespace k8s.Exceptions
24
{
3-
using System;
4-
55
/// <summary>
66
/// The exception that is thrown when there is a client exception
77
/// </summary>

src/KubernetesClient/Extensions.cs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,15 @@
11
using System;
2-
using System.Collections.Concurrent;
3-
using System.Linq;
4-
using System.Net;
5-
using System.Net.Http;
62
using System.Reflection;
73
using System.Text.RegularExpressions;
8-
using System.Threading.Tasks;
94
using k8s.Models;
10-
using Microsoft.Rest;
11-
using Microsoft.Rest.TransientFaultHandling;
12-
using Newtonsoft.Json.Converters;
13-
using VersionConverter = k8s.Versioning.VersionConverter;
145

156
namespace k8s
167
{
178
public static class Extensions
189
{
19-
public static KubernetesEntityAttribute GetKubernetesTypeMetadata<T>(this T obj) where T : IKubernetesObject =>
10+
public static KubernetesEntityAttribute GetKubernetesTypeMetadata<T>(this T obj)
11+
where T : IKubernetesObject
12+
=>
2013
obj.GetType().GetKubernetesTypeMetadata();
2114
public static KubernetesEntityAttribute GetKubernetesTypeMetadata(this Type currentType)
2215
{
@@ -29,7 +22,8 @@ public static KubernetesEntityAttribute GetKubernetesTypeMetadata(this Type curr
2922
return attr;
3023
}
3124

32-
public static T Initialize<T>(this T obj) where T : IKubernetesObject
25+
public static T Initialize<T>(this T obj)
26+
where T : IKubernetesObject
3327
{
3428
var metadata = obj.GetKubernetesTypeMetadata();
3529
obj.ApiVersion = !string.IsNullOrEmpty(metadata.Group) ? $"{metadata.Group}/{metadata.ApiVersion}" : metadata.ApiVersion;

src/KubernetesClient/IntstrIntOrString.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
using System;
22
using Newtonsoft.Json;
3-
using YamlDotNet.Core.Events;
4-
using YamlDotNet.Core.Tokens;
53

64
namespace k8s.Models
75
{

src/KubernetesClient/KubeConfigModels/AuthProvider.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
using System.Collections.Generic;
2+
using YamlDotNet.Serialization;
3+
14
namespace k8s.KubeConfigModels
25
{
3-
using System.Collections.Generic;
4-
using YamlDotNet.RepresentationModel;
5-
using YamlDotNet.Serialization;
6-
76
/// <summary>
87
/// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
98
/// </summary>

src/KubernetesClient/KubeConfigModels/Cluster.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
using YamlDotNet.Serialization;
2+
13
namespace k8s.KubeConfigModels
24
{
3-
using YamlDotNet.Serialization;
4-
55
/// <summary>
66
/// Relates nicknames to cluster information.
77
/// </summary>

src/KubernetesClient/KubeConfigModels/ClusterEndpoint.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using System.Collections.Generic;
2+
using YamlDotNet.Serialization;
3+
14
namespace k8s.KubeConfigModels
25
{
3-
using System.Collections.Generic;
4-
using YamlDotNet.Serialization;
5-
66
/// <summary>
77
/// Contains information about how to communicate with a kubernetes cluster
88
/// </summary>

src/KubernetesClient/KubeConfigModels/Context.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using System;
2+
using YamlDotNet.Serialization;
3+
14
namespace k8s.KubeConfigModels
25
{
3-
using System;
4-
using YamlDotNet.Serialization;
5-
66
/// <summary>
77
/// Relates nicknames to context information.
88
/// </summary>

src/KubernetesClient/KubeConfigModels/ContextDetails.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using System.Collections.Generic;
2+
using YamlDotNet.Serialization;
3+
14
namespace k8s.KubeConfigModels
25
{
3-
using System.Collections.Generic;
4-
using YamlDotNet.Serialization;
5-
66
/// <summary>
77
/// Represents a tuple of references to a cluster (how do I communicate with a kubernetes cluster),
88
/// a user (how do I identify myself), and a namespace (what subset of resources do I want to work with)

src/KubernetesClient/KubeConfigModels/ExecCredentialResponse.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@ namespace k8s.KubeConfigModels
55
{
66
public class ExecCredentialResponse
77
{
8-
[JsonProperty("apiVersion")] public string ApiVersion { get; set; }
9-
[JsonProperty("kind")] public string Kind { get; set; }
10-
[JsonProperty("status")] public IDictionary<string, string> Status { get; set; }
8+
[JsonProperty("apiVersion")]
9+
public string ApiVersion { get; set; }
10+
[JsonProperty("kind")]
11+
public string Kind { get; set; }
12+
[JsonProperty("status")]
13+
public IDictionary<string, string> Status { get; set; }
1114
}
1215
}

src/KubernetesClient/KubeConfigModels/ExternalExecution.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ namespace k8s.KubeConfigModels
55
{
66
public class ExternalExecution
77
{
8-
[YamlMember(Alias = "apiVersion")] public string ApiVersion { get; set; }
8+
[YamlMember(Alias = "apiVersion")]
9+
public string ApiVersion { get; set; }
910

1011
/// <summary>
1112
/// The command to execute. Required.

src/KubernetesClient/KubeConfigModels/K8SConfiguration.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using System.Collections.Generic;
2+
using YamlDotNet.Serialization;
3+
14
namespace k8s.KubeConfigModels
25
{
3-
using System.Collections.Generic;
4-
using YamlDotNet.Serialization;
5-
66
/// <summary>
77
/// kubeconfig configuration model. Holds the information needed to build connect to remote
88
/// Kubernetes clusters as a given user.
@@ -19,9 +19,11 @@ public class K8SConfiguration
1919
[YamlMember(Alias = "preferences")]
2020
public IDictionary<string, object> Preferences { get; set; }
2121

22-
[YamlMember(Alias = "apiVersion")] public string ApiVersion { get; set; }
22+
[YamlMember(Alias = "apiVersion")]
23+
public string ApiVersion { get; set; }
2324

24-
[YamlMember(Alias = "kind")] public string Kind { get; set; }
25+
[YamlMember(Alias = "kind")]
26+
public string Kind { get; set; }
2527

2628
/// <summary>
2729
/// Gets or sets the name of the context that you would like to use by default.

src/KubernetesClient/KubeConfigModels/User.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
using YamlDotNet.Serialization;
2+
13
namespace k8s.KubeConfigModels
24
{
3-
using YamlDotNet.Serialization;
4-
55
/// <summary>
66
/// Relates nicknames to auth information.
77
/// </summary>

src/KubernetesClient/KubeConfigModels/UserCredentials.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1+
using System.Collections.Generic;
2+
using YamlDotNet.Serialization;
3+
14
namespace k8s.KubeConfigModels
25
{
3-
using System.Collections.Generic;
4-
using YamlDotNet.RepresentationModel;
5-
using YamlDotNet.Serialization;
6-
76
/// <summary>
87
/// Contains information that describes identity information. This is use to tell the kubernetes cluster who you are.
98
/// </summary>

src/KubernetesClient/Kubernetes.ConfigInit.cs

+8-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ public partial class Kubernetes
2222
/// <param name="httpClient">
2323
/// The <see cref="HttpClient" /> to use for all requests.
2424
/// </param>
25-
public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient) : this(config, httpClient, false)
25+
public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient)
26+
: this(config, httpClient, false)
2627
{
2728
}
2829

@@ -38,7 +39,8 @@ public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient) :
3839
/// <param name="disposeHttpClient">
3940
/// Whether or not the <see cref="Kubernetes"/> object should own the lifetime of <paramref name="httpClient"/>.
4041
/// </param>
41-
public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient, bool disposeHttpClient) : this(
42+
public Kubernetes(KubernetesClientConfiguration config, HttpClient httpClient, bool disposeHttpClient)
43+
: this(
4244
httpClient, disposeHttpClient)
4345
{
4446
ValidateConfig(config);
@@ -179,12 +181,14 @@ partial void CustomInitialize()
179181
/// <summary>A <see cref="DelegatingHandler"/> that simply forwards a request with no further processing.</summary>
180182
private sealed class ForwardingHandler : DelegatingHandler
181183
{
182-
public ForwardingHandler(HttpMessageHandler handler) : base(handler)
184+
public ForwardingHandler(HttpMessageHandler handler)
185+
: base(handler)
183186
{
184187
}
185188
}
186189

187-
private void AppendDelegatingHandler<T>() where T : DelegatingHandler, new()
190+
private void AppendDelegatingHandler<T>()
191+
where T : DelegatingHandler, new()
188192
{
189193
var cur = FirstMessageHandler as DelegatingHandler;
190194

src/KubernetesClient/Kubernetes.Exec.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public async Task<int> NamespacedPodExecAsync(string name, string @namespace, st
2323

2424
try
2525
{
26-
using (var muxedStream = await this.MuxedStreamNamespacedPodExecAsync(name: name,
26+
using (var muxedStream = await this.MuxedStreamNamespacedPodExecAsync(
27+
name: name,
2728
@namespace: @namespace, command: command, container: container, tty: tty,
2829
cancellationToken: cancellationToken).ConfigureAwait(false))
2930
using (Stream stdIn = muxedStream.GetStream(null, ChannelIndex.StdIn))

src/KubernetesClient/Kubernetes.Watch.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ public async Task<Watcher<T>> WatchObjectAsync<T>(string path, string @continue
9696
uriBuilder.Query =
9797
query.Length == 0
9898
? ""
99-
: query.ToString(1,
99+
: query.ToString(
100+
1,
100101
query.Length - 1); // UriBuilder.Query doesn't like leading '?' chars, so trim it
101102

102103
// Create HTTP transport objects
@@ -145,7 +146,8 @@ public async Task<Watcher<T>> WatchObjectAsync<T>(string path, string @continue
145146
{
146147
string responseContent = string.Empty;
147148

148-
var ex = new HttpOperationException(string.Format("Operation returned an invalid status code '{0}'",
149+
var ex = new HttpOperationException(string.Format(
150+
"Operation returned an invalid status code '{0}'",
149151
httpResponse.StatusCode));
150152
if (httpResponse.Content != null)
151153
{
@@ -160,7 +162,8 @@ public async Task<Watcher<T>> WatchObjectAsync<T>(string path, string @continue
160162
throw ex;
161163
}
162164

163-
return new Watcher<T>(async () =>
165+
return new Watcher<T>(
166+
async () =>
164167
{
165168
var stream = await httpResponse.Content.ReadAsStreamAsync().ConfigureAwait(false);
166169
StreamReader reader = new StreamReader(stream);

src/KubernetesClient/Kubernetes.WebSocket.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ public Task<WebSocket> WebSocketNamespacedPodExecAsync(string name, string @name
3737
}
3838

3939
/// <inheritdoc/>
40-
public virtual async Task<IStreamDemuxer> MuxedStreamNamespacedPodExecAsync(string name,
40+
public virtual async Task<IStreamDemuxer> MuxedStreamNamespacedPodExecAsync(
41+
string name,
4142
string @namespace = "default", IEnumerable<string> command = null, string container = null,
4243
bool stderr = true, bool stdin = true, bool stdout = true, bool tty = true,
4344
string webSocketSubProtol = WebSocketProtocol.V4BinaryWebsocketProtocol,

0 commit comments

Comments
 (0)