-
Notifications
You must be signed in to change notification settings - Fork 66
config: Unify configuration for pull and push agents #1037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or 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
701b6a7
to
24deda0
Compare
/packit retest-failed |
Drop unnecessary options: - DEFAULT_MEASUREDBOOT_ML_PATH - DEFAULT_UEFI_LOGS_BINARY_PATH Drop unnecessary lazy initialization of constants. Organize the default values in base.rs depending on its usage (shared, push-model only, or pull-model only) Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Remove KeylimeConfig structure, making AgentConfig the only configuration structure. The KeylimeConfig structure was just a wrapper around AgentConfig. This also moves the loading of configuration files to the file_config.rs file. A test for overriding options using environment variables is added as a integration test. This is necessary to make it to run in a separate process and not affect other tests. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
The keylime-macros crate provide helper macros. The define_config_view procedural macro allows annotating a structure with the attribute #[define_view_trait(for_struct = "SomeStructure")]. The annotated structure serves as a template to create a Trait which provides a view of the referred structure, restricting the accessible fields through getter methods. The created Trait is named as the annotated name followed by "Trait". For types that are Copy primitives (e.g. u16, u32, etc.), the getter method will return a copy of the value. For other types, the getter method will return a reference to the value, unless it is annotated with the #[copy] attribute. Only types that implement the Copy trait can be annotated with the #[copy] attribute. The annoted structure fields can also be annotated with the attribute `#[transform(using = custom_transform_fn, error = CustomError)]`. The annotated fields getters are generated using the provided transform function which may return an error of the given type. For example: ```rust struct KeylimeConfig { node_id: String, port: u16, api_versions: String, info: CustomCopyType, } \#[define_view_trait(for_struct = KeylimeConfig)] struct KeylimeView { node_id: String, port: u16, #[transform(using = parse_string_list, error = ParsingError)] api_versions: Vec<String>, #[copy] info: CustomCopyType, } ``` Expands into: ```rust pub trait KeylimeViewTrait { fn node_id(&self) -> &str; fn port(&self) -> u16; fn api_versions(&self) -> Result<Vec<String>, ParsingError>; fn info(&self) -> CustomCopyType; } impl KeylimeViewTrait for KeylimeConfig { fn node_id(&self) -> &str { &self.node_id } fn port(&self) -> u16 { self.port } fn api_versions(&self) -> Result<Vec<String>, ParsingError> { parse_string_list(&self.api_versions) } fn info(&self) -> CustomCopyType { self.info } } ``` Assisted-by: Gemini 2.5 Pro Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Use the procedural macro 'define_view_trait' to create a view limited by a trait for the AgentConfig instead of creating a new structure. This removes the PushModelConfig structure. The AgentConfig should be used directly instead, which has the PushModelConfigTrait implemented using the procedural macro. Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
/packit test |
sergio-correia
approved these changes
Jul 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice job, LGTM!
sarroutbi
reviewed
Jul 4, 2025
sarroutbi
approved these changes
Jul 7, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor the configuration code, removing the wrapper structure
KeylimeConfig
and keeping only the internal configuration structureAgentConfig
.The
AgentConfig
structure holds the configuration options for both pull and push agents.A new crate
keylime-macros
is introduced, with the implementation of thedefine_trait_view
procedural macro.The define_config_view procedural macro allows annotating a structure
with the attribute
#[define_view_trait(for_struct = "SomeStructure")]
.The annotated structure serves as a template to create a Trait which
provides a view of the referred structure, restricting the accessible
fields through getter methods. The created Trait is named as the
annotated name followed by "Trait".
For types that are
Copy
primitives (e.g.u16
,u32
, etc.), the gettermethod will return a copy of the value. For other types, the getter
method will return a reference to the value, unless it is annotated with
the
#[copy]
attribute. Only types that implement theCopy
trait can beannotated with the
#[copy]
attribute.The annoted structure fields can also be annotated with the attribute
#[transform(using = custom_transform_fn, error = CustomError)]
.The annotated fields getters are generated using the provided transform
function which may return an error of the given type.
Expands into:
The
PushModelConfigTrait
is implemented using thedefine_view_trait
macro, replacing the previously existing implementation. ThePushModelConfig
is also removed in favor of using the unifiedAgentConfig
, whith the view restricted by the imported trait.Finally, the
AgentConfig
is used in the push model client prototype, adding support to the whole configuration via theagent.conf
file, overrides using configuration snippets, and overrides with environment variables, in the same way it is currently supported by the pull model agent.