Skip to content

Commit 7f4e543

Browse files
committed
Fix exception when writing connection.apiKey values
1 parent 26ffcad commit 7f4e543

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

src/SeqCli/Config/EnvironmentOverrides.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System;
2-
using System.Collections;
316
using System.Collections.Generic;
417
using System.Linq;
518

@@ -30,7 +43,7 @@ internal static void Apply(string prefix, SeqCliConfig config, Dictionary<string
3043
}
3144
}
3245

33-
internal static string ToEnvironmentVariableName(string prefix, string key)
46+
static string ToEnvironmentVariableName(string prefix, string key)
3447
{
3548
return prefix + key.Replace(".", "_").ToUpperInvariant();
3649
}

src/SeqCli/Config/KeyValueSettings.cs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System;
216
using System.Collections;
317
using System.Collections.Generic;
@@ -24,7 +38,7 @@ public static void Set(SeqCliConfig config, string key, string? value)
2438
for (var i = 0; i < steps.Length - 1; ++i)
2539
{
2640
var nextStep = receiver.GetType().GetTypeInfo().DeclaredProperties
27-
.Where(p => p.CanRead && p.GetMethod!.IsPublic && !p.GetMethod.IsStatic && p.GetCustomAttribute<ObsoleteAttribute>() == null)
41+
.Where(p => p.CanRead && p.GetMethod!.IsPublic && !p.GetMethod.IsStatic && p.GetCustomAttribute<ObsoleteAttribute>() == null && p.GetCustomAttribute<JsonIgnoreAttribute>() == null)
2842
.SingleOrDefault(p => Camelize(GetUserFacingName(p)) == steps[i]);
2943

3044
if (nextStep == null)
@@ -38,10 +52,13 @@ public static void Set(SeqCliConfig config, string key, string? value)
3852
throw new InvalidOperationException("Intermediate configuration object is null.");
3953
}
4054

55+
// FUTURE: the use of `p.Name` and lack of `JsonIgnoreAttribute` checks here mean that sensitive values can
56+
// intercept writes through hidden properties, triggering encoding where supported. A type-based solution
57+
// would be more robust.
4158
var targetProperty = receiver.GetType().GetTypeInfo().DeclaredProperties
4259
.Where(p => p is { CanRead: true, CanWrite: true } && p.GetMethod!.IsPublic && p.SetMethod!.IsPublic &&
4360
!p.GetMethod.IsStatic && p.GetCustomAttribute<ObsoleteAttribute>() == null)
44-
.SingleOrDefault(p => Camelize(GetUserFacingName(p)) == steps[^1]);
61+
.SingleOrDefault(p => Camelize(p.Name) == steps[^1]);
4562

4663
if (targetProperty == null)
4764
throw new ArgumentException("The key could not be found; run `seqcli config list` to view all keys.");
@@ -56,7 +73,7 @@ public static void Set(SeqCliConfig config, string key, string? value)
5673
return value?.Split(',').Select(e => e.Trim()).ToArray() ?? [];
5774

5875
if (propertyType == typeof(int[]))
59-
return value?.Split(',').Select(e => int.Parse(e.Trim(), CultureInfo.InvariantCulture)).ToArray() ?? Array.Empty<int>();
76+
return value?.Split(',').Select(e => int.Parse(e.Trim(), CultureInfo.InvariantCulture)).ToArray() ?? [];
6077

6178
if (propertyType.IsGenericType && propertyType.GetGenericTypeDefinition() == typeof(Nullable<>))
6279
{
@@ -98,7 +115,7 @@ public static bool TryGetValue(object config, string key, out string? value, [No
98115
{
99116
foreach (var nextStep in receiver.GetType().GetTypeInfo().DeclaredProperties
100117
.Where(p => p.CanRead && p.GetMethod!.IsPublic &&
101-
!p.GetMethod.IsStatic && p.GetCustomAttribute<ObsoleteAttribute>() == null)
118+
!p.GetMethod.IsStatic && p.GetCustomAttribute<ObsoleteAttribute>() == null && p.GetCustomAttribute<JsonIgnoreAttribute>() == null)
102119
.OrderBy(GetUserFacingName))
103120
{
104121
var camel = Camelize(GetUserFacingName(nextStep));
@@ -131,6 +148,7 @@ public static bool TryGetValue(object config, string key, out string? value, [No
131148
else if (nextStep.CanRead && nextStep.GetMethod!.IsPublic &&
132149
nextStep.CanWrite && nextStep.SetMethod!.IsPublic &&
133150
!nextStep.SetMethod.IsStatic &&
151+
nextStep.GetCustomAttribute<ObsoleteAttribute>() == null &&
134152
nextStep.GetCustomAttribute<JsonIgnoreAttribute>() == null)
135153
{
136154
var value = nextStep.GetValue(receiver);

src/SeqCli/Config/RuntimeConfigurationLoader.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
// Copyright © Datalust Pty Ltd
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
using System;
216
using System.IO;
317

src/SeqCli/Config/SeqCliConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static void WriteToFile(SeqCliConfig data, string filename)
5454
{
5555
if (!data._exportable)
5656
throw new InvalidOperationException("The provided configuration is not exportable.");
57-
57+
5858
var content = JsonConvert.SerializeObject(data, Formatting.Indented, SerializerSettings);
5959
File.WriteAllText(filename, content);
6060
}

src/SeqCli/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"profiles": {
44
"SeqCli": {
55
"commandName": "Project",
6-
"commandLineArgs": "signal update --json-stdin"
6+
"commandLineArgs": "config -k connection.apiKey -v test"
77
}
88
}
99
}

0 commit comments

Comments
 (0)