Skip to content

Commit

Permalink
feat: generate metadata/default.meta
Browse files Browse the repository at this point in the history
  • Loading branch information
artemrys authored and Artem Rys committed Aug 14, 2021
1 parent e5cce49 commit 629b248
Show file tree
Hide file tree
Showing 10 changed files with 107 additions and 3 deletions.
11 changes: 10 additions & 1 deletion splunk_add_on_ucc_framework/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
GlobalConfigValidator,
GlobalConfigValidatorException,
)
from .meta_conf import MetaConf
from .start_alert_build import alert_build
from .uccrestbuilder import build
from .uccrestbuilder.global_config import (
Expand Down Expand Up @@ -802,9 +803,17 @@ def _generate(source, config, ta_version, outputdir=None):
ta_name, os.path.abspath(os.path.join(source, PARENT_DIR, ".uccignore"))
)
remove_listed_files(ignore_list)
logger.info("Copy package directory ")
logger.info("Copy package directory")
recursive_overwrite(source, os.path.join(outputdir, ta_name))

default_meta_conf_path = os.path.join(
outputdir, ta_name, "metadata", "default.meta"
)
if not os.path.exists(default_meta_conf_path):
os.makedirs(os.path.join(outputdir, ta_name, "metadata"))
with open(default_meta_conf_path, "w") as default_meta_conf_fd:
MetaConf().create_default(default_meta_conf_fd)

# Update app.manifest
with open(os.path.join(outputdir, ta_name, "VERSION"), "w") as version_file:
version_file.write(version_str)
Expand Down
36 changes: 36 additions & 0 deletions splunk_add_on_ucc_framework/meta_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#
# Copyright 2021 Splunk 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
#
# http://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.
#
from typing import IO

from . import conf_parser

DEFAULT = """
# Application-level permissions
[]
owner = admin
access = read : [ * ], write : [ admin ]
export = system
"""


class MetaConf:
def __init__(self):
self._meta_conf = conf_parser.TABConfigParser()

def create_default(self, fd: IO) -> None:
self._meta_conf.read_string(DEFAULT)
self._meta_conf.write(fd)
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@
"apiVersion": "3.2.0",
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.5.9R7f9b7ff7",
"version": "5.6.2R6cc76bdf",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.2"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1026,7 +1026,7 @@
"apiVersion": "3.2.0",
"name": "Splunk_TA_UCCExample",
"restRoot": "splunk_ta_uccexample",
"version": "5.0.1R3b426a46",
"version": "5.6.2R6cc76bdf",
"displayName": "Splunk UCC test Add-on",
"schemaVersion": "0.0.2"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Application-level permissions

[]
owner = admin
access = read : [ * ], write : [ admin ]
export = system
3 changes: 3 additions & 0 deletions tests/data/test_ucc_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def test_ucc_generate_with_inputs_configuration_alerts(self):
("README", "inputs.conf.spec"),
("README", "splunk_ta_uccexample_account.conf.spec"),
("README", "splunk_ta_uccexample_settings.conf.spec"),
("metadata", "default.meta"),
]
for f in files_to_be_equal:
expected_file_path = path.join(expected_folder, *f)
Expand Down Expand Up @@ -110,6 +111,7 @@ def test_ucc_generate_with_configuration(self):
("bin", "splunk_ta_uccexample_rh_settings.py"),
("README", "splunk_ta_uccexample_account.conf.spec"),
("README", "splunk_ta_uccexample_settings.conf.spec"),
("metadata", "default.meta"),
]
for f in files_to_be_equal:
expected_file_path = path.join(expected_folder, *f)
Expand Down Expand Up @@ -148,6 +150,7 @@ def test_ucc_generate_with_configuration_files_only(self):
("default", "eventtypes.conf"),
("default", "props.conf"),
("default", "tags.conf"),
("metadata", "default.meta"),
]
for f in files_to_be_equal:
expected_file_path = path.join(expected_folder, *f)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Application-level permissions

[]
owner = admin
access = read : [ * ], write : [ admin ]
export = system
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Application-level permissions

[]
owner = admin
access = read : [ * ], write : [ admin ]
export = system
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

# Application-level permissions

[]
owner = admin
access = read : [ * ], write : [ admin ]
export = system
28 changes: 28 additions & 0 deletions tests/unit/test_meta_conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#
# Copyright 2021 Splunk 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
#
# http://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 io
import unittest

from splunk_add_on_ucc_framework import meta_conf


class MetaConfTest(unittest.TestCase):
def test_update(self):
meta_config = meta_conf.MetaConf()
actual_output = io.StringIO()
meta_config.create_default(actual_output)
expected_output = meta_conf.DEFAULT
self.assertEqual(expected_output, actual_output.getvalue())

0 comments on commit 629b248

Please sign in to comment.