Skip to content

Commit

Permalink
feat: release v5.30.0 (#848)
Browse files Browse the repository at this point in the history
* feat: introduce package command (#846)

* feat: introduce package command

* test: fixing unit tests

* refactor: apply stricter mypy rules (#847)

* refactor: GlobalConfig does parsing in __init__ method

* refactor: fix all the mypy's reported issues

* refactor: properly type re.compile variable

* chore: add mypy.ini

* chore: add mypy.ini to licenses configuration

* chore: remove print after previous PR (#849)

* feat: add selected Python version to build output (#850)

* feat: print python version as part of build

* style: formatting

* refactor: move python version identification in its own function

* test: create test for python version identification

* fix: fix exception handling and formatting

---------

Co-authored-by: Artem Rys <rysartem@gmail.com>

* feat: update UCC UI to v1.32.0 (#852)

---------

Co-authored-by: Daniel Federschmidt <dfederschmidt@splunk.com>
  • Loading branch information
artemrys and dfederschmidt authored Oct 1, 2023
1 parent ccdba8d commit fb93601
Show file tree
Hide file tree
Showing 67 changed files with 1,602 additions and 349 deletions.
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ header:
- "splunk_add_on_ucc_framework/commands/import_from_aob.sh"
- "splunk_add_on_ucc_framework/commands/imports.py"
- "scripts/compare_different_ucc_versions_output.sh"
- "mypy.ini"
1 change: 0 additions & 1 deletion docs/entity/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,6 @@ This is how it looks like in the UI:

![image](../images/components/help_link_component_example.png)


## `File`

Underlying `@splunk/react-ui` component: [`File`](https://splunkui.splunk.com/Packages/react-ui/File).
Expand Down
26 changes: 22 additions & 4 deletions docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,20 @@ pip install splunk-add-on-ucc-framework splunk-packaging-toolkit

> Note: `splunk-packaging-toolkit` does not work with Python 3.10+.
* Run `ucc-gen` and package it
> Note: `ucc-gen package` can be used instead of `slim` if UCC `v5.30.0+` is used (more details below).
* Run `ucc-gen build` and package it

> Provide `--ta-version=<version>` parameter if this repository is not version controlled.
```bash
ucc-gen
ucc-gen build
slim package output/<add-on-name>
```

> Please use `ucc-gen build` instead of `ucc-gen` if you are using UCC `v5.19.0` and higher.
Now you should see an archive created in the same level as your
`globalConfig.json` is located.
Now you should see an archive created in the same level as your `globalConfig.json` is located.

Now you can go to Splunk and install this add-on using the generated archive.

Expand Down Expand Up @@ -164,6 +165,23 @@ It takes the following parameters:

* `--addon-name` - [required] add-on name.

### `ucc-gen package`

Available from `v5.30.0`. Packages the add-on so it can be installed.
It mimics the basics of the `slim package` command. This command can be used for most of the simple cases.

It does not support:

* `.slimignore` file
* [dependencies section](https://dev.splunk.com/enterprise/docs/releaseapps/packageapps/packagingtoolkit/#Dependencies-section)

It takes the following parameters:

* `--path` - [required] path to the built add-on (should include `app.manifest` file).
* `-o` / `--output` - [optional] output folder to store packaged add-on in.
By default, it will be saved in the `current directory` folder.
Accepts absolute paths as well.

## What `ucc-gen build` does

* Cleans the output folder.
Expand Down
2 changes: 1 addition & 1 deletion get-ucc-ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
wget https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.31.0/splunk-ucc-ui.tgz
wget https://github.com/splunk/addonfactory-ucc-base-ui/releases/download/v1.32.0/splunk-ucc-ui.tgz
10 changes: 10 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[mypy]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
warn_redundant_casts = true
warn_unused_ignores = true

[mypy-tests.*]
disallow_untyped_defs = false
2 changes: 1 addition & 1 deletion splunk_add_on_ucc_framework/app_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


class AppConf:
def __init__(self):
def __init__(self) -> None:
self._app_conf = conf_parser.TABConfigParser()

def read(self, path: str) -> None:
Expand Down
26 changes: 13 additions & 13 deletions splunk_add_on_ucc_framework/app_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#

import json
from typing import Dict, List, Optional
from typing import Dict, List, Optional, Any

APP_MANIFEST_SCHEMA_VERSION = "2.0.0"
APP_MANIFEST_SUPPORTED_DEPLOYMENTS = frozenset(
Expand Down Expand Up @@ -43,12 +43,20 @@ class AppManifestFormatException(Exception):


class AppManifest:
def __init__(self):
self._manifest = None
def __init__(self, content: str) -> None:
try:
self._manifest = json.loads(content)
except json.JSONDecodeError:
raise AppManifestFormatException(
"Could not parse app.manifest, not a correct JSON file"
)

def get_addon_name(self) -> str:
return self._manifest["info"]["id"]["name"]

def get_addon_version(self) -> str:
return self._manifest["info"]["id"]["version"]

def get_title(self) -> str:
return self._manifest["info"]["title"]

Expand All @@ -74,21 +82,13 @@ def _get_target_workloads(self) -> Optional[List[str]]:
return self._manifest.get("targetWorkloads")

@property
def manifest(self) -> Dict:
def manifest(self) -> Dict[str, Any]:
return self._manifest

def read(self, content: str) -> None:
try:
self._manifest = json.loads(content)
except json.JSONDecodeError:
raise AppManifestFormatException(
"Could not parse app.manifest, not a correct JSON file"
)

def update_addon_version(self, version: str) -> None:
self._manifest["info"]["id"]["version"] = version

def validate(self):
def validate(self) -> None:
schema_version = self._get_schema_version()
if schema_version != APP_MANIFEST_SCHEMA_VERSION:
raise AppManifestFormatException(
Expand Down
48 changes: 37 additions & 11 deletions splunk_add_on_ucc_framework/commands/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
import os
import shutil
import sys
from typing import Optional
from typing import Optional, List
import subprocess

from openapi3 import OpenAPI

Expand Down Expand Up @@ -60,7 +61,7 @@

def _modify_and_replace_token_for_oauth_templates(
ta_name: str, global_config: global_config_lib.GlobalConfig, outputdir: str
):
) -> None:
"""
Rename templates with respect to addon name if OAuth is configured.
Expand Down Expand Up @@ -125,7 +126,7 @@ def _modify_and_replace_token_for_oauth_templates(

def _add_modular_input(
ta_name: str, global_config: global_config_lib.GlobalConfig, outputdir: str
):
) -> None:
for service in global_config.inputs:
input_name = service.get("name")
class_name = input_name.upper()
Expand Down Expand Up @@ -167,7 +168,9 @@ def _add_modular_input(
config.write(configfile)


def _get_ignore_list(addon_name: str, ucc_ignore_path: str, output_directory: str):
def _get_ignore_list(
addon_name: str, ucc_ignore_path: str, output_directory: str
) -> List[str]:
"""
Return path of files/folders to be removed.
Expand All @@ -193,7 +196,7 @@ def _get_ignore_list(addon_name: str, ucc_ignore_path: str, output_directory: st
return ignore_list


def _remove_listed_files(ignore_list):
def _remove_listed_files(ignore_list: List[str]) -> None:
"""
Return path of files/folders to removed in output folder.
Expand All @@ -220,7 +223,7 @@ def generate_data_ui(
addon_name: str,
include_inputs: bool,
include_dashboard: bool,
):
) -> None:
# Create directories in the output folder for add-on's UI nav and views.
os.makedirs(
os.path.join(output_directory, addon_name, "default", "data", "ui", "nav"),
Expand Down Expand Up @@ -289,9 +292,8 @@ def _get_app_manifest(source: str) -> app_manifest_lib.AppManifest:
)
with open(app_manifest_path) as manifest_file:
app_manifest_content = manifest_file.read()
app_manifest = app_manifest_lib.AppManifest()
try:
app_manifest.read(app_manifest_content)
app_manifest = app_manifest_lib.AppManifest(app_manifest_content)
app_manifest.validate()
return app_manifest
except app_manifest_lib.AppManifestFormatException as e:
Expand All @@ -312,15 +314,38 @@ def _get_build_output_path(output_directory: Optional[str] = None) -> str:
return output_directory


def _get_python_version_from_executable(python_binary_name: str) -> str:
try:
python_binary_version = subprocess.run(
[python_binary_name, "--version"], stdout=subprocess.PIPE
).stdout.decode("utf-8")

return python_binary_version.strip()
except (subprocess.CalledProcessError, FileNotFoundError):
raise exceptions.CouldNotIdentifyPythonVersionException(
f"Failed to identify python version for binary {python_binary_name}"
)


def generate(
source: str,
config_path: Optional[str] = None,
addon_version: Optional[str] = None,
output_directory: Optional[str] = None,
python_binary_name: str = "python3",
):
) -> None:
logger.info(f"ucc-gen version {__version__} is used")
logger.info(f"Python binary name to use: {python_binary_name}")

try:
python_binary_version = _get_python_version_from_executable(python_binary_name)
logger.info(f"Python Version: {python_binary_version}")
except exceptions.CouldNotIdentifyPythonVersionException as e:
logger.error(
f"Failed to identify Python version for library installation. Error: {e}"
)
sys.exit(1)

output_directory = _get_build_output_path(output_directory)
logger.info(f"Output folder is {output_directory}")
addon_version = _get_addon_version(addon_version)
Expand All @@ -347,8 +372,9 @@ def generate(

if os.path.isfile(config_path):
logger.info(f"Using globalConfig file located @ {config_path}")
global_config = global_config_lib.GlobalConfig()
global_config.parse(config_path, is_global_config_yaml)
global_config = global_config_lib.GlobalConfig(
config_path, is_global_config_yaml
)
try:
validator = global_config_validator.GlobalConfigValidator(
internal_root_dir, global_config
Expand Down
2 changes: 1 addition & 1 deletion splunk_add_on_ucc_framework/commands/import_from_aob.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
logger = logging.getLogger("ucc_gen")


def import_from_aob(addon_name: str):
def import_from_aob(addon_name: str) -> None:
addon_name_directory = os.path.join(os.getcwd(), addon_name)
if not os.path.isdir(addon_name_directory):
logger.error(f"No such directory {addon_name_directory}")
Expand Down
8 changes: 4 additions & 4 deletions splunk_add_on_ucc_framework/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations
import logging
import os
import sys
import re
from typing import Optional

import shutil

Expand All @@ -34,7 +34,7 @@
ADDON_INPUT_NAME_RE = re.compile(ADDON_INPUT_NAME_RE_STR)


def _is_valid(pattern: re.Pattern, string: str) -> bool:
def _is_valid(pattern: re.Pattern[str], string: str) -> bool:
result = pattern.search(string)
if result is None:
return False
Expand All @@ -60,7 +60,7 @@ def _generate_addon(
addon_display_name: str,
addon_input_name: str,
addon_version: str,
addon_rest_root: Optional[str] = None,
addon_rest_root: str | None = None,
overwrite: bool = False,
) -> str:
generated_addon_path = os.path.join(
Expand Down Expand Up @@ -151,7 +151,7 @@ def init(
addon_display_name: str,
addon_input_name: str,
addon_version: str,
addon_rest_root: Optional[str] = None,
addon_rest_root: str | None = None,
overwrite: bool = False,
) -> str:
if not _is_valid_addon_name(addon_name):
Expand Down
Loading

0 comments on commit fb93601

Please sign in to comment.