Example #1
0
 def __init__(
     self,
     graph=None,
     parameters=None,
     load_mode=None,
     function_uri=None,
     verbose=False,
     version=None,
     functions=None,
     graph_initializer=None,
     error_stream=None,
     track_models=None,
     secret_sources=None,
 ):
     self._graph = None
     self.graph: Union[RouterState, RootFlowState] = graph
     self.function_uri = function_uri
     self.parameters = parameters or {}
     self.verbose = verbose
     self.load_mode = load_mode or "sync"
     self.version = version or "v2"
     self.context = None
     self._current_function = None
     self.functions = functions or {}
     self.graph_initializer = graph_initializer
     self.error_stream = error_stream
     self.track_models = track_models
     self._error_stream_object = None
     self.secret_sources = secret_sources
     self._secrets = SecretsStore.from_list(secret_sources)
     self._db_conn = None
     self.resource_cache = None
Example #2
0
def test_inline_str():
    spec = {
        "secret_sources": [{
            "kind": "inline",
            "source": "{'abc': 'def'}"
        }],
    }

    ss = SecretsStore.from_list(spec["secret_sources"])
    assert ss.get("abc") == "def", "failed on 1st env var secret"
Example #3
0
def test_inline_str():
    spec = {
        'secret_sources': [{
            'kind': 'inline',
            'source': "{'abc': 'def'}"
        }],
    }

    ss = SecretsStore.from_list(spec['secret_sources'])
    assert ss.get('abc') == 'def', 'failed on 1st env var secret'
Example #4
0
def test_load():
    environ['ENV123'] = 'xx'
    environ['ENV456'] = 'yy'
    ss = SecretsStore.from_list(spec['secret_sources'])

    assert ss.get('ENV123') == 'xx', 'failed on 1st env var secret'
    assert ss.get('ENV456') == 'yy', 'failed on 1st env var secret'
    assert ss.get('MYENV') == '123', 'failed on 1st env var secret'
    assert ss.get('MY2NDENV') == '456', 'failed on 1st env var secret'
    assert ss.get('abc') == 'def', 'failed on 1st env var secret'
    print(ss.get_all())
Example #5
0
def test_load():
    environ["ENV123"] = "xx"
    environ["ENV456"] = "yy"
    ss = SecretsStore.from_list(spec["secret_sources"])

    assert ss.get("ENV123") == "xx", "failed on 1st env var secret"
    assert ss.get("ENV456") == "yy", "failed on 1st env var secret"
    assert ss.get("MYENV") == "123", "failed on 1st env var secret"
    assert ss.get("MY2NDENV") == "456", "failed on 1st env var secret"
    assert ss.get("abc") == "def", "failed on 1st env var secret"
    print(ss.items())
Example #6
0
    def init(
        self,
        context,
        namespace,
        resource_cache: ResourceCache = None,
        logger=None,
        is_mock=False,
    ):
        """for internal use, initialize all steps (recursively)"""

        if self.secret_sources:
            self._secrets = SecretsStore.from_list(self.secret_sources)

        if self.error_stream:
            self._error_stream_object = get_stream_pusher(self.error_stream)
        self.resource_cache = resource_cache or ResourceCache()

        context = GraphContext(server=self,
                               nuclio_context=context,
                               logger=logger)
        context.is_mock = is_mock
        context.root = self.graph

        context.stream = _StreamContext(self.track_models, self.parameters,
                                        self.function_uri)
        context.current_function = self._current_function
        context.get_store_resource = self.resource_cache.resource_getter(
            self._get_db(), self._secrets)
        context.get_table = self.resource_cache.get_table
        context.verbose = self.verbose
        self.context = context

        if self.graph_initializer:
            if callable(self.graph_initializer):
                handler = self.graph_initializer
            else:
                handler = get_function(self.graph_initializer, namespace or [])
            handler(self)

        context.root = self.graph
        self.graph.init_object(context, namespace, self.load_mode, reset=True)
        return v2_serving_handler