Skip to content

Commit

Permalink
new: usr: Added new Config source that allows to add arbitrary data d…
Browse files Browse the repository at this point in the history
…irectly from the pipeline definition.
  • Loading branch information
dajose authored and carlos-jenkins committed Aug 23, 2018
1 parent ff0fd1d commit 377ce73
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 2 deletions.
27 changes: 27 additions & 0 deletions examples/config/pipeline.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[[sources]]
type = "config"
id = "config1"

[sources.config.data]
name = "this is a name"

[sources.config.data.embedded]
somefield = 123

[sources.config.data.embedded.morefields]
comment = "This could go forever"


[[sinks]]
type = "print"
id = "print"

[[sinks]]
type = "archive"
id = "archive"

[sinks.config]
output = "data.json"
override = true
create_parents = true
pretty = true
5 changes: 3 additions & 2 deletions lib/flowbber/components/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 KuraLabs S.R.L
# Copyright (C) 2017-2018 KuraLabs S.R.L
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -118,7 +118,7 @@ class Component(metaclass=NamedABCMeta):
That is, it is allowed to fail and the pipeline won't fail.
:var int timeout: Execution timeout for this component, in seconds.
None means no timeout, wait forever.
:var namedtuple config: Frozen configuration after validation.
:var namedtuple Component.config: Frozen configuration after validation.
**Parameters**:
Expand Down Expand Up @@ -147,6 +147,7 @@ def __init__(

configurator = Configurator()
self.declare_config(configurator)

self.config = configurator.validate(config or {})

@property
Expand Down
102 changes: 102 additions & 0 deletions lib/flowbber/plugins/sources/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017-2018 KuraLabs S.R.L
#
# 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.

"""
Config
======
This sources let the user indicate static data to describe current pipeline.
**Data collected:**
*Anything the user entered on the configuration*
**Dependencies:**
.. code-block:: sh
pip3 install flowbber[config]
**Usage:**
.. code-block:: toml
[[sources]]
type = "config"
id = "..."
[sources.config.data]
anydata = "...."
.. code-block:: json
{
"sources": [
{
"type": "config",
"id": "...",
"config": {
"data": {
"anydata": "...."
}
}
}
]
}
data
----
Free off schema data.
- **Default**: ``False``
- **Optional**: ``False``
- **Schema**:
.. code-block:: python3
{
'type': 'dict'
}
- **Secret**: ``False``
""" # noqa

from copy import deepcopy

from flowbber.components import Source


class ConfigSource(Source):

def declare_config(self, config):
config.add_option(
'data',
schema={
'type': 'dict',
'empty': False,
},
)

def collect(self):
return deepcopy(self.config.data.value)


__all__ = ['ConfigSource']
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,8 @@ def find_packages(lib_directory):

# CoberturaSource
'cobertura': ['pycobertura'],
# ConfigSource
'config': [],
# CPUSource
'cpu': ['psutil'],
# EnvSource
Expand Down Expand Up @@ -424,6 +426,7 @@ def find_packages(lib_directory):
entry_points={
'flowbber_plugin_sources_1_0': [
'cobertura = flowbber.plugins.sources.cobertura:CoberturaSource',
'config = flowbber.plugins.sources.config:ConfigSource',
'cpu = flowbber.plugins.sources.cpu:CPUSource',
'env = flowbber.plugins.sources.env:EnvSource',
'git = flowbber.plugins.sources.git:GitSource',
Expand Down
1 change: 1 addition & 0 deletions test/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def setup_module(module):
['test', 'pipeline.toml'],
['lcov', 'pipeline.toml'],
['valgrind', 'pipeline.toml'],
['config', 'pipeline.toml'],
])
def test_pipelines(name, pipelinedef):
# Exceptions ...
Expand Down

0 comments on commit 377ce73

Please sign in to comment.