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+
115using System ;
216using System . Collections ;
317using 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 ) ;
0 commit comments