예제 #1
0
def tanium_wrapper(data: str) -> str:
    """Convert input tanium data (in string format) to OSCAL result (json serlaized as string)."""
    # process
    tanium_tf = transformer_factory.get('tanium')
    output_oscal = tanium_tf.transform(data)
    json_str = output_oscal.oscal_serialize_json()
    return json_str
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     https://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.
"""Basic script to show the use of the transformer factory."""

import logging
import pathlib

from trestle.common import const
from trestle.transforms.transformer_singleton import transformer_factory

logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO)
logger.addHandler(logging.StreamHandler())

sample_data_f = pathlib.Path('small_sample_tanium.json')

if __name__ == '__main__':
    stringed = sample_data_f.open('r', encoding=const.FILE_ENCODING).read()
    tanium_tf = transformer_factory.get('tanium')
    output_oscal = tanium_tf.transform(stringed)
    json_str = output_oscal.oscal_serialize_json()
    logger.info(json_str)
예제 #3
0
def test_transformer_not_registered() -> None:
    """Test basic transformer operations."""
    with pytest.raises(err.TrestleError):
        transformer: TransformerBase = tf.get('foo')
        assert transformer is not None
예제 #4
0
def test_results_transformer() -> None:
    """Test results transformer."""
    tf.register_transformer('dummy', DummyResultsTransformer)
    transformer: ResultsTransformer = tf.get('dummy')
    assert transformer.transform('foo') == Results(__root__=[])
예제 #5
0
def test_basic_transformer_operations() -> None:
    """Test basic transformer operations."""
    tf.register_transformer('dummy', DummyTransformer)
    transformer: TransformerBase = tf.get('dummy')
    assert transformer.transform('foo') == RoleId(__root__='my_string')
예제 #6
0
def tanium_wrapper_oscal(data: str) -> OscalBaseModel:
    """Convert input tanium data (in string format) to OSCAL result."""
    # process
    tanium_tf = transformer_factory.get('tanium')
    output_oscal = tanium_tf.transform(data)
    return output_oscal