-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed export type issues * Test coverage * Test coverage
- Loading branch information
Showing
12 changed files
with
251 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) The NATS Authors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using NATS.Jwt.Models; | ||
|
||
namespace NATS.Jwt.Internal; | ||
|
||
/// <inheritdoc /> | ||
internal class NatsExportComparer : IComparer<NatsExport> | ||
{ | ||
/// <inheritdoc /> | ||
public int Compare(NatsExport? x, NatsExport? y) | ||
{ | ||
return string.Compare(x?.Subject, y?.Subject, StringComparison.Ordinal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) The NATS Authors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using NATS.Jwt.Models; | ||
|
||
namespace NATS.Jwt.Internal; | ||
|
||
/// <inheritdoc /> | ||
internal class NatsImportComparer : IComparer<NatsImport> | ||
{ | ||
/// <inheritdoc /> | ||
public int Compare(NatsImport? x, NatsImport? y) | ||
{ | ||
return string.Compare(x?.Subject, y?.Subject, StringComparison.Ordinal); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) The NATS Authors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
using System; | ||
using System.Text.Json; | ||
using System.Text.Json.Serialization; | ||
using NATS.Jwt.Models; | ||
|
||
namespace NATS.Jwt.Internal; | ||
|
||
/// <inheritdoc /> | ||
internal class NatsJsonStringEnumConverter<TEnum> : JsonConverter<TEnum> | ||
where TEnum : struct, Enum | ||
{ | ||
/// <inheritdoc /> | ||
public override TEnum Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
{ | ||
if (reader.TokenType != JsonTokenType.String) | ||
{ | ||
throw new InvalidOperationException(); | ||
} | ||
|
||
var stringValue = reader.GetString(); | ||
|
||
if (typeToConvert == typeof(NatsExportType)) | ||
{ | ||
switch (stringValue) | ||
{ | ||
case "unknown": | ||
return (TEnum)(object)NatsExportType.Unknown; | ||
case "stream": | ||
return (TEnum)(object)NatsExportType.Stream; | ||
case "service": | ||
return (TEnum)(object)NatsExportType.Service; | ||
} | ||
} | ||
|
||
throw new InvalidOperationException($"Reading unknown enum type {typeToConvert.Name} or value {stringValue}"); | ||
} | ||
|
||
/// <inheritdoc /> | ||
public override void Write(Utf8JsonWriter writer, TEnum value, JsonSerializerOptions options) | ||
{ | ||
if (value is NatsExportType consumerConfigDeliverPolicy) | ||
{ | ||
switch (consumerConfigDeliverPolicy) | ||
{ | ||
case NatsExportType.Unknown: | ||
writer.WriteStringValue("unknown"); | ||
return; | ||
case NatsExportType.Stream: | ||
writer.WriteStringValue("stream"); | ||
return; | ||
case NatsExportType.Service: | ||
writer.WriteStringValue("service"); | ||
return; | ||
} | ||
} | ||
|
||
throw new InvalidOperationException($"Writing unknown enum value {value.GetType().Name}.{value}"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) The NATS Authors. | ||
// Licensed under the Apache License, Version 2.0. | ||
|
||
namespace NATS.Jwt.Models; | ||
|
||
/// <summary> | ||
/// Defines the type of export. | ||
/// </summary> | ||
public enum NatsExportType | ||
{ | ||
/// <summary> | ||
/// Unknown is used if we don't know the type. | ||
/// </summary> | ||
Unknown = 0, | ||
|
||
/// <summary> | ||
/// Stream defines the type field value for a stream "stream". | ||
/// </summary> | ||
Stream = 1, | ||
|
||
/// <summary> | ||
/// Service defines the type field value for a service "service". | ||
/// </summary> | ||
Service = 2, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters