Skip to content

Commit

Permalink
rename Options -> Opts (#120)
Browse files Browse the repository at this point in the history
* rename Options -> Opts

* run dotent format

---------

Signed-off-by: Caleb Lloyd <[email protected]>
  • Loading branch information
caleblloyd authored Aug 31, 2023
1 parent 6922a65 commit 6e68d53
Show file tree
Hide file tree
Showing 43 changed files with 244 additions and 241 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ for (int i = 0; i < 10; i++)
You should also hook your logger to `NatsConnection` to make sure all is working as expected or
to get help diagnosing any issues you might have:
```csharp
var options = NatsOptions.Default with { LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Error) };
var options = NatsOpts.Default with { LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Error) };
await using var nats = new NatsConnection(options);
```

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ for (int i = 0; i < 10; i++)
You should also hook your logger to `NatsConnection` to make sure all is working as expected or
to get help diagnosing any issues you might have:
```csharp
var options = NatsOptions.Default with { LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Error) };
var options = NatsOpts.Default with { LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Error) };
await using var nats = new NatsConnection(options);
```

Expand Down
2 changes: 1 addition & 1 deletion sandbox/BlazorWasm/Client/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddNats(configureOptions: opt => opt with { Url = "ws://localhost:4280", Name = "BlazorClient" });
builder.Services.AddNats(configureOpts: opt => opt with { Url = "ws://localhost:4280", Name = "BlazorClient" });

await builder.Build().RunAsync();
2 changes: 1 addition & 1 deletion sandbox/BlazorWasm/Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// Add services to the container.
builder.Services.AddControllersWithViews();
builder.Services.AddRazorPages();
builder.Services.AddNats(configureOptions: opt => opt with { Url = "localhost:4222", Name = "BlazorServer" });
builder.Services.AddNats(configureOpts: opt => opt with { Url = "localhost:4222", Name = "BlazorServer" });
builder.Services.AddHostedService<WeatherForecastService>();

var app = builder.Build();
Expand Down
4 changes: 2 additions & 2 deletions sandbox/ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
var builder = ConsoleApp.CreateBuilder(args);
builder.ConfigureServices(services =>
{
services.AddNats(poolSize: 4, configureOptions: opt => opt with { Url = "localhost:4222", Name = "MyClient" });
services.AddNats(poolSize: 4, configureOpts: opt => opt with { Url = "localhost:4222", Name = "MyClient" });
});

// create connection(default, connect to nats://localhost:4222)
Expand Down Expand Up @@ -58,7 +58,7 @@
Url = "nats://127.0.0.1:9999",
LoggerFactory = new MinimumConsoleLoggerFactory(LogLevel.Information),
Echo = true,
AuthOptions = NatsAuthOptions.Default with
AuthOpts = NatsAuthOpts.Default with
{
Username = "foo",
Password = "bar",
Expand Down
8 changes: 4 additions & 4 deletions sandbox/ConsoleApp2/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
var natsKey1 = new NatsKey("subject1");
var natsKey2 = new NatsKey("subject2");

await using var subConnection1 = new NatsConnection(NatsOptions.Default with
await using var subConnection1 = new NatsConnection(NatsOpts.Default with
{
Url = "localhost:4222"
});
Expand All @@ -20,7 +20,7 @@
Console.WriteLine($"\tSUB1:{x}");
});

await using var subConnection2 = new NatsConnection(NatsOptions.Default with
await using var subConnection2 = new NatsConnection(NatsOpts.Default with
{
Url = "localhost:4222"
});
Expand All @@ -41,14 +41,14 @@

Task.Run(async () =>
{
await using var pubConnection1 = new NatsConnection(NatsOptions.Default with
await using var pubConnection1 = new NatsConnection(NatsOpts.Default with
{
Url = "localhost:4222"
});
await pubConnection1.ConnectAsync();
await using var pubConnection2 = new NatsConnection(NatsOptions.Default with
await using var pubConnection2 = new NatsConnection(NatsOpts.Default with
{
Url = "localhost:4222"
});
Expand Down
7 changes: 5 additions & 2 deletions sandbox/Example.JetStream.PullConsumer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Diagnostics;
using System.Diagnostics;
using Example.JetStream.PullConsumer;
using Microsoft.Extensions.Logging;
using NATS.Client.Core;
Expand Down Expand Up @@ -62,7 +62,10 @@ void Report(int i, Stopwatch sw, string data)

var nextOpts = new NatsJSNextOpts
{
Expires = expires, IdleHeartbeat = idle, Serializer = new RawDataSerializer(), ErrorHandler = ErrorHandler,
Expires = expires,
IdleHeartbeat = idle,
Serializer = new RawDataSerializer(),
ErrorHandler = ErrorHandler,
};

var stopwatch = Stopwatch.StartNew();
Expand Down
2 changes: 1 addition & 1 deletion sandbox/Example.JetStream.PullConsumer/RawData.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Text;
using System.Text;

namespace Example.JetStream.PullConsumer;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Buffers;
using System.Buffers;
using NATS.Client.Core;

namespace Example.JetStream.PullConsumer;
Expand Down
10 changes: 5 additions & 5 deletions src/NATS.Client.Core/Commands/ConnectCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ namespace NATS.Client.Core.Commands;

internal sealed class AsyncConnectCommand : AsyncCommandBase<AsyncConnectCommand>
{
private ClientOptions? _clientOptions;
private ClientOpts? _clientOpts;

private AsyncConnectCommand()
{
}

public static AsyncConnectCommand Create(ObjectPool pool, ClientOptions connectOptions, CancellationTimer timer)
public static AsyncConnectCommand Create(ObjectPool pool, ClientOpts connectOpts, CancellationTimer timer)
{
if (!TryRent(pool, out var result))
{
result = new AsyncConnectCommand();
}

result._clientOptions = connectOptions;
result._clientOpts = connectOpts;
result.SetCancellationTimer(timer);

return result;
}

public override void Write(ProtocolWriter writer)
{
writer.WriteConnect(_clientOptions!);
writer.WriteConnect(_clientOpts!);
}

protected override void Reset()
{
_clientOptions = null;
_clientOpts = null;
}
}
4 changes: 2 additions & 2 deletions src/NATS.Client.Core/Commands/ProtocolWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public ProtocolWriter(FixedArrayBufferWriter writer)

// https://docs.nats.io/reference/reference-protocols/nats-protocol#connect
// CONNECT {["option_name":option_value],...}
public void WriteConnect(ClientOptions options)
public void WriteConnect(ClientOpts opts)
{
WriteConstant(CommandConstants.ConnectWithPadding);

var jsonWriter = new Utf8JsonWriter(_writer);
JsonSerializer.Serialize(jsonWriter, options, JsonContext.Default.ClientOptions);
JsonSerializer.Serialize(jsonWriter, opts, JsonContext.Default.ClientOpts);

WriteConstant(CommandConstants.NewLine);
}
Expand Down
8 changes: 4 additions & 4 deletions src/NATS.Client.Core/INatsConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public interface INatsConnection
/// <remarks>
/// Response can be (null) or one <see cref="NatsMsg"/>.
/// Reply option's max messages will be set to 1.
/// if reply option's timeout is not defined then it will be set to NatsOptions.RequestTimeout.
/// if reply option's timeout is not defined then it will be set to NatsOpts.RequestTimeout.
/// </remarks>
ValueTask<NatsMsg<TReply?>?> RequestAsync<TRequest, TReply>(
string subject,
Expand All @@ -114,7 +114,7 @@ public interface INatsConnection
/// <remarks>
/// Response can be (null) or one <see cref="NatsMsg"/>.
/// Reply option's max messages will be set to 1 (one).
/// if reply option's timeout is not defined then it will be set to NatsOptions.RequestTimeout.
/// if reply option's timeout is not defined then it will be set to NatsOpts.RequestTimeout.
/// </remarks>
ValueTask<NatsMsg?> RequestAsync(
string subject,
Expand All @@ -136,7 +136,7 @@ public interface INatsConnection
/// <returns>An asynchronous enumerable of <see cref="NatsMsg"/> objects</returns>
/// <exception cref="OperationCanceledException">Raised when cancellation token is used</exception>
/// <remarks>
/// if reply option's timeout is not defined then it will be set to NatsOptions.RequestTimeout.
/// if reply option's timeout is not defined then it will be set to NatsOpts.RequestTimeout.
/// </remarks>
IAsyncEnumerable<NatsMsg<TReply?>> RequestManyAsync<TRequest, TReply>(
string subject,
Expand All @@ -156,7 +156,7 @@ public interface INatsConnection
/// <returns>An asynchronous enumerable of <see cref="NatsMsg"/> objects</returns>
/// <exception cref="OperationCanceledException">Raised when cancellation token is used</exception>
/// <remarks>
/// if reply option's timeout is not defined then it will be set to NatsOptions.RequestTimeout.
/// if reply option's timeout is not defined then it will be set to NatsOpts.RequestTimeout.
/// </remarks>
IAsyncEnumerable<NatsMsg> RequestManyAsync(
string subject,
Expand Down
2 changes: 1 addition & 1 deletion src/NATS.Client.Core/INatsConnectionPool.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace NATS.Client.Core;
namespace NATS.Client.Core;

public interface INatsConnectionPool : IAsyncDisposable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@

namespace NATS.Client.Core.Internal;

// SYSLIB1037: The type 'ClientOptions' defines init-only properties,
// SYSLIB1037: The type 'ClientOpts' defines init-only properties,
// deserialization of which is currently not supported in source generation mode
#pragma warning disable SYSLIB1037

// These connections options are serialized and sent to the server.
// https://github.com/nats-io/nats-server/blob/a23b1b7/server/client.go#L536
internal sealed class ClientOptions
internal sealed class ClientOpts
{
private ClientOptions(NatsOpts opts)
private ClientOpts(NatsOpts opts)
{
Name = opts.Name;
Echo = opts.Echo;
Verbose = opts.Verbose;
Headers = opts.Headers;
Username = opts.AuthOptions.Username;
Password = opts.AuthOptions.Password;
AuthToken = opts.AuthOptions.Token;
JWT = opts.AuthOptions.Jwt;
Username = opts.AuthOpts.Username;
Password = opts.AuthOpts.Password;
AuthToken = opts.AuthOpts.Token;
JWT = opts.AuthOpts.Jwt;
}

/// <summary>Optional boolean. If set to true, the server (version 1.2.0+) will not send originating messages from this connection to its own subscriptions. Clients should set this to true only for server supporting this feature, which is when proto in the INFO protocol is set to at least 1.</summary>
Expand Down Expand Up @@ -90,14 +90,14 @@ private ClientOptions(NatsOpts opts)
[JsonPropertyName("no_responders")]
public bool NoResponders { get; init; } = false;

public static ClientOptions Create(NatsOpts opts)
public static ClientOpts Create(NatsOpts opts)
{
return new ClientOptions(opts);
return new ClientOpts(opts);
}

private static string GetAssemblyVersion()
{
var asm = typeof(ClientOptions);
var asm = typeof(ClientOpts);
var version = "1.0.0";
var infoVersion = asm!.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
if (infoVersion != null)
Expand Down
2 changes: 1 addition & 1 deletion src/NATS.Client.Core/Internal/JsonContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ namespace NATS.Client.Core.Internal;

[JsonSourceGenerationOptions(DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(ServerInfo), GenerationMode = JsonSourceGenerationMode.Metadata)]
[JsonSerializable(typeof(ClientOptions), GenerationMode = JsonSourceGenerationMode.Serialization)]
[JsonSerializable(typeof(ClientOpts), GenerationMode = JsonSourceGenerationMode.Serialization)]
internal sealed partial class JsonContext : JsonSerializerContext
{
}
10 changes: 5 additions & 5 deletions src/NATS.Client.Core/Internal/SslStreamConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ internal sealed class SslStreamConnection : ISocketConnection
{
private readonly SslStream _sslStream;
private readonly TaskCompletionSource<Exception> _waitForClosedSource;
private readonly TlsOptions _tlsOptions;
private readonly NatsTlsOpts _tlsOpts;
private readonly TlsCerts? _tlsCerts;
private readonly CancellationTokenSource _closeCts = new();
private int _disposed;

public SslStreamConnection(SslStream sslStream, TlsOptions tlsOptions, TlsCerts? tlsCerts, TaskCompletionSource<Exception> waitForClosedSource)
public SslStreamConnection(SslStream sslStream, NatsTlsOpts tlsOpts, TlsCerts? tlsCerts, TaskCompletionSource<Exception> waitForClosedSource)
{
_sslStream = sslStream;
_tlsOptions = tlsOptions;
_tlsOpts = tlsOpts;
_tlsCerts = tlsCerts;
_waitForClosedSource = waitForClosedSource;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ private bool RcsCbCaCertChain(

private SslClientAuthenticationOptions SslClientAuthenticationOptions(string targetHost)
{
if (_tlsOptions.Disabled)
if (_tlsOpts.Disabled)
{
throw new InvalidOperationException("TLS is not permitted when TlsOptions.Disabled is set");
}
Expand All @@ -137,7 +137,7 @@ private SslClientAuthenticationOptions SslClientAuthenticationOptions(string tar
}

RemoteCertificateValidationCallback? rcsCb = default;
if (_tlsOptions.InsecureSkipVerify)
if (_tlsOpts.InsecureSkipVerify)
{
rcsCb = RcsCbInsecureSkipVerify;
}
Expand Down
4 changes: 2 additions & 2 deletions src/NATS.Client.Core/Internal/TcpConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,13 @@ public void SignalDisconnected(Exception exception)

// NetworkStream will own the Socket, so mark as disposed
// in order to skip socket.Dispose() in DisposeAsync
public SslStreamConnection UpgradeToSslStreamConnection(TlsOptions tlsOptions, TlsCerts? tlsCerts)
public SslStreamConnection UpgradeToSslStreamConnection(NatsTlsOpts tlsOpts, TlsCerts? tlsCerts)
{
if (Interlocked.Increment(ref _disposed) == 1)
{
return new SslStreamConnection(
new SslStream(new NetworkStream(_socket, true)),
tlsOptions,
tlsOpts,
tlsCerts,
_waitForClosedSource);
}
Expand Down
18 changes: 9 additions & 9 deletions src/NATS.Client.Core/Internal/TlsCerts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,28 @@ namespace NATS.Client.Core.Internal;

internal class TlsCerts
{
public TlsCerts(TlsOptions tlsOptions)
public TlsCerts(NatsTlsOpts tlsOpts)
{
if (tlsOptions.Disabled)
if (tlsOpts.Disabled)
{
return;
}

if ((tlsOptions.CertFile != default && tlsOptions.KeyFile == default) ||
(tlsOptions.KeyFile != default && tlsOptions.CertFile == default))
if ((tlsOpts.CertFile != default && tlsOpts.KeyFile == default) ||
(tlsOpts.KeyFile != default && tlsOpts.CertFile == default))
{
throw new ArgumentException("TlsOptions.CertFile and TlsOptions.KeyFile must both be set");
throw new ArgumentException("NatsTlsOpts.CertFile and NatsTlsOpts.KeyFile must both be set");
}

if (tlsOptions.CaFile != default)
if (tlsOpts.CaFile != default)
{
CaCerts = new X509Certificate2Collection();
CaCerts.ImportFromPemFile(tlsOptions.CaFile);
CaCerts.ImportFromPemFile(tlsOpts.CaFile);
}

if (tlsOptions.CertFile != default && tlsOptions.KeyFile != default)
if (tlsOpts.CertFile != default && tlsOpts.KeyFile != default)
{
ClientCerts = new X509Certificate2Collection(X509Certificate2.CreateFromPemFile(tlsOptions.CertFile, tlsOptions.KeyFile));
ClientCerts = new X509Certificate2Collection(X509Certificate2.CreateFromPemFile(tlsOpts.CertFile, tlsOpts.KeyFile));
}
}

Expand Down
Loading

0 comments on commit 6e68d53

Please sign in to comment.