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

Method from_model

st2common/st2common/models/api/keyvalue.py:109–140  ·  view source on GitHub ↗
(cls, model, mask_secrets=True)

Source from the content-addressed store, hash-verified

107
108 @classmethod
109 def from_model(cls, model, mask_secrets=True):
110 if not KeyValuePairAPI.crypto_setup:
111 KeyValuePairAPI._setup_crypto()
112
113 doc = cls._from_model(model, mask_secrets=mask_secrets)
114
115 if getattr(model, "expire_timestamp", None) and model.expire_timestamp:
116 doc["expire_timestamp"] = isotime.format(
117 model.expire_timestamp, offset=False
118 )
119
120 encrypted = False
121 secret = getattr(model, "secret", False)
122 if secret:
123 encrypted = True
124
125 if not mask_secrets and secret:
126 doc["value"] = symmetric_decrypt(KeyValuePairAPI.crypto_key, model.value)
127 encrypted = False
128
129 scope = getattr(model, "scope", SYSTEM_SCOPE)
130 if scope:
131 doc["scope"] = scope
132
133 key = doc.get("name", None)
134 if (scope == USER_SCOPE or scope == FULL_USER_SCOPE) and key:
135 doc["user"] = UserKeyReference.get_user(key)
136 doc["name"] = UserKeyReference.get_name(key)
137
138 doc["encrypted"] = encrypted
139 attrs = {attr: value for attr, value in six.iteritems(doc) if value is not None}
140 return cls(**attrs)
141
142 @classmethod
143 def to_model(cls, kvp):

Callers

nothing calls this directly

Calls 7

symmetric_decryptFunction · 0.90
_setup_cryptoMethod · 0.80
_from_modelMethod · 0.80
formatMethod · 0.45
getMethod · 0.45
get_userMethod · 0.45
get_nameMethod · 0.45

Tested by

no test coverage detected