MCPcopy Create free account
hub / github.com/aws/aws-cli / ChainProvider

Class ChainProvider

awscli/botocore/configprovider.py:540–583  ·  view source on GitHub ↗

This provider wraps one or more other providers. Each provider in the chain is called, the first one returning a non-None value is then returned.

Source from the content-addressed store, hash-verified

538
539
540class ChainProvider(BaseProvider):
541 """This provider wraps one or more other providers.
542
543 Each provider in the chain is called, the first one returning a non-None
544 value is then returned.
545 """
546
547 def __init__(self, providers=None, conversion_func=None):
548 """Initalize a ChainProvider.
549
550 :type providers: list
551 :param providers: The initial list of providers to check for values
552 when invoked.
553
554 :type conversion_func: None or callable
555 :param conversion_func: If this value is None then it has no affect on
556 the return type. Otherwise, it is treated as a function that will
557 transform provided value.
558 """
559 if providers is None:
560 providers = []
561 self._providers = providers
562 self._conversion_func = conversion_func
563
564 def provide(self):
565 """Provide the value from the first provider to return non-None.
566
567 Each provider in the chain has its provide method called. The first
568 one in the chain to return a non-None value is the returned from the
569 ChainProvider. When no non-None value is found, None is returned.
570 """
571 for provider in self._providers:
572 value = provider.provide()
573 if value is not None:
574 return self._convert_type(value)
575 return None
576
577 def _convert_type(self, value):
578 if self._conversion_func is not None:
579 return self._conversion_func(value)
580 return value
581
582 def __repr__(self):
583 return '[{}]'.format(', '.join([str(p) for p in self._providers]))
584
585
586class InstanceVarProvider(BaseProvider):

Calls

no outgoing calls