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

Function get_key

st2common/st2common/util/keyvalue.py:82–125  ·  view source on GitHub ↗

Retrieve key from KVP store

(key=None, user_db=None, scope=None, decrypt=False)

Source from the content-addressed store, hash-verified

80
81
82def get_key(key=None, user_db=None, scope=None, decrypt=False):
83 """
84 Retrieve key from KVP store
85 """
86 if not isinstance(key, six.string_types):
87 raise TypeError("Given key is not typeof string.")
88
89 if not isinstance(decrypt, bool):
90 raise TypeError("Decrypt parameter is not typeof bool.")
91
92 if not user_db:
93 # Use system user
94 user_db = UserDB(name=cfg.CONF.system_user.user)
95
96 scope, key_id = _derive_scope_and_key(key=key, user=user_db.name, scope=scope)
97 scope = get_datastore_full_scope(scope)
98
99 LOG.debug(
100 "get_key key_id: %s, scope: %s, user: %s, decrypt: %s"
101 % (key_id, scope, str(user_db.name), decrypt)
102 )
103
104 _validate_scope(scope=scope)
105
106 # Get the key value pair by scope and name.
107 kvp = KeyValuePair.get_by_scope_and_name(scope, key_id)
108
109 # Check that user has permission to the key value pair.
110 # If RBAC is enabled, this check will verify if user has system role with all access.
111 # If RBAC is enabled, this check guards against a user accessing another user's kvp.
112 # If RBAC is enabled, user needs to be explicitly granted permission to view a system kvp.
113 # The check is sufficient to allow decryption of the system kvp.
114 rbac_utils = get_rbac_backend().get_utils_class()
115 rbac_utils.assert_user_has_resource_db_permission(
116 user_db=user_db,
117 resource_db=kvp,
118 permission_type=PermissionType.KEY_VALUE_PAIR_VIEW,
119 )
120
121 # Decrypt in deserialize_key_value cannot handle NoneType.
122 if kvp.value is None:
123 return kvp.value
124
125 return deserialize_key_value(kvp.value, decrypt)

Callers

nothing calls this directly

Calls 9

UserDBClass · 0.90
get_rbac_backendFunction · 0.90
deserialize_key_valueFunction · 0.90
_derive_scope_and_keyFunction · 0.85
get_datastore_full_scopeFunction · 0.85
_validate_scopeFunction · 0.85
get_by_scope_and_nameMethod · 0.80
get_utils_classMethod · 0.45

Tested by

no test coverage detected