MCPcopy Create free account
hub / github.com/StackStorm/st2 / KeyValueLookup

Class KeyValueLookup

st2common/st2common/services/keyvalues.py:106–206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104
105
106class KeyValueLookup(BaseKeyValueLookup):
107
108 scope = SYSTEM_SCOPE
109
110 def __init__(
111 self,
112 prefix=None,
113 key_prefix=None,
114 cache=None,
115 scope=FULL_SYSTEM_SCOPE,
116 context=None,
117 ):
118 if not scope:
119 scope = FULL_SYSTEM_SCOPE
120
121 if scope == SYSTEM_SCOPE:
122 scope = FULL_SYSTEM_SCOPE
123
124 self._prefix = prefix
125 self._key_prefix = key_prefix or ""
126 self._value_cache = cache or {}
127 self._scope = scope
128
129 self._context = context if context else dict()
130 self._user = (
131 context["user"]
132 if context and "user" in context and context["user"]
133 else cfg.CONF.system_user.user
134 )
135 self._user = (
136 context["api_user"]
137 if context and "api_user" in context and context["api_user"]
138 else self._user
139 )
140
141 def __str__(self):
142 return self._value_cache[self._key_prefix]
143
144 def __int__(self):
145 return int(float(self))
146
147 def __float__(self):
148 return float(str(self))
149
150 def __getitem__(self, key):
151 return self._get(key)
152
153 def __getattr__(self, name):
154 return self._get(name)
155
156 def _get(self, name):
157 # get the value for this key and save in value_cache
158 if self._key_prefix:
159 key = "%s.%s" % (self._key_prefix, name)
160 else:
161 key = name
162
163 if self._prefix:

Calls

no outgoing calls