-
Notifications
You must be signed in to change notification settings - Fork 35
feat: create minimal global config using app.manifest and app.conf #1625
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
Closed
Closed
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
61f3a20
feat: generate minimal globalConfig
hetangmodi-crest db9ddbb
tests: add test cases
hetangmodi-crest b3f9548
docs: updated docs regarding generated conf, xml and html files
srv-rr-github-token c1225ce
chore: updated class names
hetangmodi-crest 9ce8468
docs: update doc_generator logic
hetangmodi-crest b0020db
chore: updated encoding logic
hetangmodi-crest fcb7825
tests: add unit test cases and updated coverage percentage
hetangmodi-crest 70a0c32
chore: updating coverage for Python3.10
hetangmodi-crest 46ea73c
Merge branch 'develop' into feat/create-minimal-globalConfig
vtsvetkov-splunk 0f4975e
Merge branch 'develop' into feat/create-minimal-globalConfig
hetangmodi-crest 73c687b
refactor: shifted implementation from FileGenerator to GlobalConfig c…
hetangmodi-crest e959ada
docs: updated docs regarding generated conf, xml and html files
srv-rr-github-token 8ac87e8
test(unit): add test to increase coverage
hetangmodi-crest c7d552a
chore: merge branch 'develop' into feat/create-minimal-globalConfig
hetangmodi-crest 9506c10
chore: remove unwanted code
hetangmodi-crest eabca2b
chore: update min coverage
hetangmodi-crest a0485fd
refactor: updated the generation of minimal globalConfig
hetangmodi-crest 57d7a85
chore: leverage dump method of GlobalConfig
hetangmodi-crest File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,4 +6,4 @@ omit = | |
| splunk_add_on_ucc_framework/templates/input.module-template | ||
|
|
||
| [report] | ||
| fail_under = 81.5 | ||
| fail_under = 84.60 | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,8 @@ | |
| from dataclasses import dataclass, field, fields | ||
|
|
||
| import yaml | ||
| import os | ||
| from splunk_add_on_ucc_framework import app_manifest as app_manifest_lib | ||
|
|
||
| from splunk_add_on_ucc_framework import utils | ||
| from splunk_add_on_ucc_framework.commands.rest_builder.user_defined_rest_handlers import ( | ||
|
|
@@ -60,20 +62,65 @@ def from_dict(cls, **kwargs: Any) -> "OSDependentLibraryConfig": | |
|
|
||
|
|
||
| class GlobalConfig: | ||
| def __init__(self, global_config_path: str) -> None: | ||
| with open(global_config_path) as f_config: | ||
| config_raw = f_config.read() | ||
| self._is_global_config_yaml = ( | ||
| True if global_config_path.endswith(".yaml") else False | ||
| ) | ||
| self._content = ( | ||
| yaml_load(config_raw) | ||
| if self._is_global_config_yaml | ||
| else json.loads(config_raw) | ||
| ) | ||
| def __init__(self, global_config_path: str, **kwargs: Any) -> None: | ||
| if global_config_path == "": | ||
| global_config_path = self.from_app_conf_and_app_manifest( | ||
| kwargs["source"], kwargs["app_manifest"], kwargs["app_conf_content"] | ||
| ) | ||
| else: | ||
| with open(global_config_path) as f_config: | ||
| config_raw = f_config.read() | ||
| self._is_global_config_yaml = ( | ||
| True if global_config_path.endswith(".yaml") else False | ||
| ) | ||
| self._content = ( | ||
| yaml_load(config_raw) | ||
| if self._is_global_config_yaml | ||
| else json.loads(config_raw) | ||
| ) | ||
| self._original_path = global_config_path | ||
| self.user_defined_handlers = UserDefinedRestHandlers() | ||
|
|
||
| def from_app_conf_and_app_manifest( | ||
| self, | ||
| source_dir: str, | ||
| app_manifest: app_manifest_lib.AppManifest, | ||
| app_conf_content: Dict[str, Any], | ||
| ) -> str: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be a
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And please make it a separate PR after #1655 is merged. |
||
| check_for_update = app_conf_content.get("package", {}).get( | ||
| "check_for_updates", "true" | ||
| ) | ||
| # checkForUpdates is by default set to 'true' | ||
| check_for_update = check_for_update.lower() in ("true", "1", "t", "y", "yes") | ||
| supported_themes = app_conf_content.get("ui", {}).get("supported_themes", "") | ||
| if supported_themes: | ||
| supported_themes = [item.strip() for item in supported_themes.split(",")] | ||
| minimal_gc_path = os.path.join(source_dir, os.pardir, "globalConfig.json") | ||
| self._is_global_config_yaml = False | ||
|
|
||
| def create_globalConfig( | ||
| app_manifest: app_manifest_lib.AppManifest, | ||
| check_for_update: bool, | ||
| supported_themes: List[str], | ||
| ) -> Dict[str, Any]: | ||
| minimal_gc = { | ||
| "meta": { | ||
| "name": f"{app_manifest.get_addon_name()}", | ||
| "restRoot": f"{app_manifest.get_addon_name()}", | ||
| "displayName": f"{app_manifest.get_title()}", | ||
| "version": f"{app_manifest.get_addon_version()}", | ||
| "checkForUpdates": check_for_update, | ||
| } | ||
| } | ||
| if supported_themes: | ||
| minimal_gc["meta"]["supportedThemes"] = supported_themes | ||
| return minimal_gc | ||
|
|
||
| self._content = create_globalConfig( | ||
| app_manifest, check_for_update, supported_themes | ||
| ) | ||
| return minimal_gc_path | ||
|
|
||
| def parse_user_defined_handlers(self) -> None: | ||
| """Parse user-defined REST handlers from globalConfig["options"]["restHandlers"]""" | ||
| rest_handlers = self._content.get("options", {}).get("restHandlers", []) | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
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.
@hetangmodi-crest this conflicts with https://github.com/splunk/addonfactory-ucc-generator/pull/1655/files, please review that PR first and let's merge it.
I'd like to keep the
__init__method how it is in that PR.