diff --git a/.python-version b/.python-version index 57986c1cc..b21f0b76c 100644 --- a/.python-version +++ b/.python-version @@ -1,2 +1 @@ -3.7.4 -2.7.18 +3.7.8 \ No newline at end of file diff --git a/README.md b/README.md index 0d0f0b93d..570dc8a22 100644 --- a/README.md +++ b/README.md @@ -69,4 +69,4 @@ splunk-add-on-ucc-framework supports the following params: |------------|----------------------------------------------------------------------------------------------------------| | source | Folder containing the app.manifest and app source | | config | Path to the configuration file, Defaults to GlobalConfig.json in the parent directory of source provided | -| ta-version | Current version of TA, Default version is version specified in globalConfig.json | \ No newline at end of file +| ta-version | Optional override Current version of TA, Default version is version specified in globalConfig.json a Splunkbase compatible version of SEMVER will be used by default | \ No newline at end of file diff --git a/poetry.lock b/poetry.lock index e97e28bd9..61e617bf3 100644 --- a/poetry.lock +++ b/poetry.lock @@ -78,12 +78,12 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" version = "0.4.3" [[package]] -category = "dev" +category = "main" description = "Dynamic version generation" name = "dunamai" optional = false python-versions = ">=3.5,<4.0" -version = "1.3.0" +version = "1.3.1" [[package]] category = "dev" @@ -105,7 +105,7 @@ description = "Faker is a Python package that generates fake data for you." name = "faker" optional = false python-versions = ">=3.5" -version = "4.1.3" +version = "4.1.8" [package.dependencies] python-dateutil = ">=2.4" @@ -269,7 +269,7 @@ description = "Pytest testing utilities with docker containers." name = "lovely-pytest-docker" optional = false python-versions = "*" -version = "0.1.0" +version = "0.2.0" [package.dependencies] pytest = "*" @@ -756,14 +756,14 @@ marker = "python_version < \"3.8\"" name = "zipp" optional = false python-versions = ">=3.6" -version = "3.2.0" +version = "3.3.0" [package.extras] docs = ["sphinx", "jaraco.packaging (>=3.2)", "rst.linker (>=1.9)"] testing = ["pytest (>=3.5,<3.7.3 || >3.7.3)", "pytest-checkdocs (>=1.2.3)", "pytest-flake8", "pytest-cov", "jaraco.test (>=3.2.0)", "jaraco.itertools", "func-timeout", "pytest-black (>=0.3.7)", "pytest-mypy"] [metadata] -content-hash = "cd7060498049ad156a7f3b3f44d34c5886ff7fb78e55674feaf6066705ca3541" +content-hash = "7cfefdae221f76708870271629f137c9afe1caaf04e02b957236d9a7cd58c590" lock-version = "1.0" python-versions = "^3.7" @@ -802,16 +802,16 @@ colorama = [ {file = "colorama-0.4.3.tar.gz", hash = "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1"}, ] dunamai = [ - {file = "dunamai-1.3.0-py3-none-any.whl", hash = "sha256:6f7b313a3e817ed08069147f0e25fbc7e85cf1c1394709d896cb76e552cabbff"}, - {file = "dunamai-1.3.0.tar.gz", hash = "sha256:5685cfe8c69fda7a4cf6e1f33de6ce5f0655c1e53c5caf8a680dfc81cd53f6b8"}, + {file = "dunamai-1.3.1-py3-none-any.whl", hash = "sha256:8eaac70fef958a2cbbff9be5250edff8a815f8f8edb030219d4203da1a978b1c"}, + {file = "dunamai-1.3.1.tar.gz", hash = "sha256:879653e60fd0c9667bf48cb563bed668c498be48ce33628b5f140909579ada7b"}, ] execnet = [ {file = "execnet-1.7.1-py2.py3-none-any.whl", hash = "sha256:d4efd397930c46415f62f8a31388d6be4f27a91d7550eb79bc64a756e0056547"}, {file = "execnet-1.7.1.tar.gz", hash = "sha256:cacb9df31c9680ec5f95553976c4da484d407e85e41c83cb812aa014f0eddc50"}, ] faker = [ - {file = "Faker-4.1.3-py3-none-any.whl", hash = "sha256:80bab8d46035a7393de827210c5d39c17109d3346d131946bde622137120c496"}, - {file = "Faker-4.1.3.tar.gz", hash = "sha256:075a95ac4c95765370919d787dcd958acfaea635005ad5af4d926cb0973800db"}, + {file = "Faker-4.1.8-py3-none-any.whl", hash = "sha256:edffca9d8106fffc23ccef15797665fa8aebec4c0eeb3fd6d43cd23540978d5b"}, + {file = "Faker-4.1.8.tar.gz", hash = "sha256:179418909da04b04000eab5463c403895faed2849d36ef8d9cbda72cc44797a0"}, ] filelock = [ {file = "filelock-3.0.12-py3-none-any.whl", hash = "sha256:929b7d63ec5b7d6b71b0fa5ac14e030b3f70b75747cef1b10da9b879fef15836"}, @@ -867,8 +867,7 @@ logutils = [ {file = "logutils-0.3.5.tar.gz", hash = "sha256:bc058a25d5c209461f134e1f03cab637d66a7a5ccc12e593db56fbb279899a82"}, ] lovely-pytest-docker = [ - {file = "lovely-pytest-docker-0.1.0.tar.gz", hash = "sha256:f471f442daad56f26660e8c31a075a82c28f5196ecc2d58658cf6516d9eb2cd0"}, - {file = "lovely_pytest_docker-0.1.0-py3-none-any.whl", hash = "sha256:7694a0194b082665edd5729c62513ea38f4320d6268d6f5f9485e878966f93be"}, + {file = "lovely-pytest-docker-0.2.0.tar.gz", hash = "sha256:665d85166fe67777efb1c85cbbdd19dea279c53fd464598adb33257664eca96c"}, ] lxml = [ {file = "lxml-4.5.1-cp27-cp27m-macosx_10_9_x86_64.whl", hash = "sha256:ee2be8b8f72a2772e72ab926a3bccebf47bb727bda41ae070dc91d1fb759b726"}, @@ -1119,6 +1118,6 @@ wheel = [ {file = "wheel-0.35.1.tar.gz", hash = "sha256:99a22d87add3f634ff917310a3d87e499f19e663413a52eb9232c447aa646c9f"}, ] zipp = [ - {file = "zipp-3.2.0-py3-none-any.whl", hash = "sha256:43f4fa8d8bb313e65d8323a3952ef8756bf40f9a5c3ea7334be23ee4ec8278b6"}, - {file = "zipp-3.2.0.tar.gz", hash = "sha256:b52f22895f4cfce194bc8172f3819ee8de7540aa6d873535a8668b730b8b411f"}, + {file = "zipp-3.3.0-py3-none-any.whl", hash = "sha256:eed8ec0b8d1416b2ca33516a37a08892442f3954dee131e92cfd92d8fe3e7066"}, + {file = "zipp-3.3.0.tar.gz", hash = "sha256:64ad89efee774d1897a58607895d80789c59778ea02185dd846ac38394a8642b"}, ] diff --git a/pyproject.toml b/pyproject.toml index 6a10ba7da..351eb6273 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -49,6 +49,7 @@ lxml = "^4.3" future = "^0" splunktaucclib = "^4.0" wheel = "*" +dunamai = "*" [tool.poetry.dev-dependencies] pytest = "^5.4" diff --git a/script/packagingScript.sh b/script/packagingScript.sh deleted file mode 100644 index 9baeeada2..000000000 --- a/script/packagingScript.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/sh - -echo "Initializing Packaging tool" - -echo "Checking for python 3" -if ! python3 -v &> /dev/null -then - echo "Python3 could not be found" - echo "Installing python 3" - pwd_var=`pwd` - echo "Getting dependencies" - # sudo yum -y install gcc openssl-devel bzip2-devel libffi-devel - sudo apt-get -qq update > /dev/null - sudo apt-get -qq install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev curl libbz2-dev > /dev/null - cd /usr/src - echo "Getting Python 3.7 binaries" - sudo wget https://www.python.org/ftp/python/3.7.9/Python-3.7.9.tgz > /dev/null - sudo tar xzf Python-3.7.9.tgz > /dev/null - cd Python-3.7.9 - sudo ./configure --enable-optimizations > /dev/null - sudo make altinstall > /dev/null - sudo rm -f /usr/src/Python-3.7.9.tgz - echo "Generating alias" - alias python3='python3.7' - alias pip3='pip3.7' - . ~/.bashrc - if python3 -v &> /dev/null - then - echo "Python Installed" - fi - cd $pwd_var -fi - -echo "Installing Virtual Environment" -pip3 install virtualenv > /dev/null -python3 -m virtualenv .venv -p python3 > /dev/null -. .venv/bin/activate -echo "Virtual Environment Installed and Activated" - -echo "Installing Dependencies" -sudo apt-get -qq install python-pip > /dev/null -sudo apt-get -qq install -y libxml2-dev libxslt-dev lib32z1-dev python-lxml > /dev/null -pip2 install "virtualenv<17.0.0,>=16.7.9" --upgrade > /dev/null - -pip3 install splunk_add_on_ucc_framework-0.1.0.tar.gz -ucc-gen diff --git a/splunk_add_on_ucc_framework/__init__.py b/splunk_add_on_ucc_framework/__init__.py index dd8856c1b..ef5478863 100644 --- a/splunk_add_on_ucc_framework/__init__.py +++ b/splunk_add_on_ucc_framework/__init__.py @@ -1,7 +1,7 @@ __version__ = "0.0.0" import logging -import os +import os, time import glob from os import system import shutil @@ -16,6 +16,8 @@ from .start_alert_build import alert_build from jinja2 import Environment, FileSystemLoader +from dunamai import Version, Style +import configparser outputdir = os.path.join(os.getcwd(), "output") sourcedir = os.path.dirname(os.path.realpath(__file__)) @@ -473,10 +475,20 @@ def main(): help="Path to configuration file, Defaults to GlobalConfig.json in parent directory of source provided", default=None ) + version = Version.from_git() + if not version.stage: + stage = 'R' + else: + stage = version.stage[:1] + + version_str = version.serialize(metadata=True) + version_splunk = f"{version.base}-{stage}{version.commit}" + parser.add_argument( "--ta-version", type=str, - help="Version of TA, Deafult version is version specified in globalConfig.json", + help="Version of TA, Deafult version is version specified in the package such as app.manifest, app.conf, and globalConfig.json", + default = version_splunk ) args = parser.parse_args() @@ -564,3 +576,43 @@ def main(): ignore_list = get_ignore_list(ta_name, os.path.abspath(os.path.join(args.source, PARENT_DIR, ".uccignore"))) remove_listed_files(ignore_list) copy_package_source(args, ta_name) + + #Update app.manifest + with open(os.path.join(outputdir, ta_name,'VERSION'), 'w') as version_file: + version_file.write(version_str) + version_file.write("\n") + version_file.write(version_splunk) + + + manifest= None + with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "r") as manifest_file: + manifest = json.load(manifest_file) + manifest['info']['id']['version'] = version_splunk + + + with open(os.path.abspath(os.path.join(outputdir, ta_name, "app.manifest")), "w") as manifest_file: + manifest_file.write(json.dumps(manifest, indent=4, sort_keys=True)) + + app_config = configparser.ConfigParser() + app_config.read_file(open(os.path.join(outputdir, ta_name,'default', "app.conf"))) + if not 'launcher' in app_config: + app_config.add_section('launcher') + if not 'id' in app_config: + app_config.add_section('id') + if not 'package' in app_config: + app_config.add_section('package') + if not 'ui' in app_config: + app_config.add_section('ui') + + app_config['launcher']['version']=version_splunk + app_config['launcher']['description']=manifest['info']['description'] + + app_config['id']['version']=version_splunk + + app_config['package']['build']=str(int(time.time())) + app_config['package']['id']=manifest['info']['id']['name'] + + app_config['ui']['label']=manifest['info']['title'] + + with open(os.path.join(outputdir, ta_name,'default', "app.conf"), 'w') as configfile: + app_config.write(configfile) \ No newline at end of file