-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Idempotent config states (pt1) (#221)
This is part of a series of PRs that will move Santa to using configuration "views" that provide a snapshot of configuration state that can be used while processing some event or flow so that config changes occur "atomically" and never partially apply during event processing. This first part sets up some initial infrastructure needed to support this change. Namely it creates the new `SNTConfigState` object which initially only captures `clientMode`. This also begins some of the work of getting this object passed around to various components that will need it in the future. Finally, this PR addresses a UI-only issue that could result in the wrong buttons being displayed if the client mode was changed to or from Standalone mode via the sync server
- Loading branch information
Showing
18 changed files
with
217 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/// Copyright 2025 North Pole Security, Inc. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
|
||
#ifndef SANTA__COMMON__CODERMACROS_H | ||
#define SANTA__COMMON__CODERMACROS_H | ||
|
||
// Encode the property keyed by the property name. | ||
#define ENCODE(c, o) \ | ||
do { \ | ||
if (self.o) { \ | ||
[c encodeObject:self.o forKey:@(#o)]; \ | ||
} \ | ||
} while (0) | ||
|
||
// Encode the property (by first boxing the value) keyed | ||
// by the property name. | ||
#define ENCODE_BOXABLE(c, o) \ | ||
do { \ | ||
id local_obj__ = @(self.o); \ | ||
[c encodeObject:local_obj__ forKey:@(#o)]; \ | ||
} while (0) | ||
|
||
// Decode a property of a given type and assign the value to | ||
// the named property. | ||
#define DECODE(d, o, c) \ | ||
do { \ | ||
_##o = [d decodeObjectOfClass:[c class] forKey:@(#o)]; \ | ||
} while (0) | ||
|
||
// Decode a property of a given type and calls a method on that | ||
// type before assigning the value to the named property | ||
#define DECODE_SELECTOR(d, o, c, s) \ | ||
do { \ | ||
_##o = [[d decodeObjectOfClass:[c class] forKey:@(#o)] s]; \ | ||
} while (0) | ||
|
||
// Decode a property of an array of objects of the given type | ||
// and assign the value to the named property. | ||
#define DECODEARRAY(d, o, c) \ | ||
do { \ | ||
_##o = [d decodeObjectOfClasses:[NSSet setWithObjects:[NSArray class], [c class], nil] \ | ||
forKey:@(#o)]; \ | ||
} while (0) | ||
|
||
#endif |
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,29 @@ | ||
/// Copyright 2025 North Pole Security, Inc. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "Source/common/SNTCommonEnums.h" | ||
#import "Source/common/SNTConfigurator.h" | ||
|
||
@interface SNTConfigState : NSObject <NSSecureCoding> | ||
|
||
// | ||
// Properties here mirror the SNTConfigurator at a point in time | ||
// | ||
@property(readonly) SNTClientMode clientMode; | ||
|
||
- (instancetype)initWithConfig:(SNTConfigurator *)config; | ||
|
||
@end |
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,46 @@ | ||
/// Copyright 2025 North Pole Security, Inc. | ||
/// | ||
/// Licensed under the Apache License, Version 2.0 (the "License"); | ||
/// you may not use this file except in compliance with the License. | ||
/// You may obtain a copy of the License at | ||
/// | ||
/// https://www.apache.org/licenses/LICENSE-2.0 | ||
/// | ||
/// Unless required by applicable law or agreed to in writing, software | ||
/// distributed under the License is distributed on an "AS IS" BASIS, | ||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
/// See the License for the specific language governing permissions and | ||
/// limitations under the License. | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
#import "Source/common/CoderMacros.h" | ||
#import "Source/common/SNTConfigState.h" | ||
|
||
@implementation SNTConfigState | ||
|
||
- (instancetype)initWithConfig:(SNTConfigurator *)config { | ||
self = [super init]; | ||
if (self) { | ||
_clientMode = config.clientMode; | ||
} | ||
return self; | ||
} | ||
|
||
+ (BOOL)supportsSecureCoding { | ||
return YES; | ||
} | ||
|
||
- (void)encodeWithCoder:(NSCoder *)coder { | ||
ENCODE_BOXABLE(coder, clientMode); | ||
} | ||
|
||
- (instancetype)initWithCoder:(NSCoder *)decoder { | ||
self = [super init]; | ||
if (self) { | ||
DECODE_SELECTOR(decoder, clientMode, NSNumber, integerValue); | ||
} | ||
return self; | ||
}; | ||
|
||
@end |
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
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
Oops, something went wrong.