(self, api_key_api, api_key_id_or_key, requester_user)
| 180 | return Response(json=api_key_create_response_api, status=http_client.CREATED) |
| 181 | |
| 182 | def put(self, api_key_api, api_key_id_or_key, requester_user): |
| 183 | api_key_db = ApiKey.get_by_key_or_id(api_key_id_or_key) |
| 184 | |
| 185 | permission_type = PermissionType.API_KEY_MODIFY |
| 186 | rbac_utils = get_rbac_backend().get_utils_class() |
| 187 | rbac_utils.assert_user_has_resource_db_permission( |
| 188 | user_db=requester_user, |
| 189 | resource_db=api_key_db, |
| 190 | permission_type=permission_type, |
| 191 | ) |
| 192 | |
| 193 | old_api_key_db = api_key_db |
| 194 | api_key_db = ApiKeyAPI.to_model(api_key_api) |
| 195 | |
| 196 | try: |
| 197 | User.get_by_name(api_key_api.user) |
| 198 | except StackStormDBObjectNotFoundError: |
| 199 | user_db = UserDB(name=api_key_api.user) |
| 200 | User.add_or_update(user_db) |
| 201 | |
| 202 | extra = {"username": api_key_api.user, "user": user_db} |
| 203 | LOG.audit('Registered new user "%s".' % (api_key_api.user), extra=extra) |
| 204 | |
| 205 | # Passing in key_hash as MASKED_ATTRIBUTE_VALUE is expected since we do not |
| 206 | # leak it out therefore it is expected we get the same value back. Interpret |
| 207 | # this special code and empty value as no-change |
| 208 | if api_key_db.key_hash == MASKED_ATTRIBUTE_VALUE or not api_key_db.key_hash: |
| 209 | api_key_db.key_hash = old_api_key_db.key_hash |
| 210 | |
| 211 | # Rather than silently ignore any update to key_hash it is better to explicitly |
| 212 | # disallow and notify user. |
| 213 | if old_api_key_db.key_hash != api_key_db.key_hash: |
| 214 | raise ValueError("Update of key_hash is not allowed.") |
| 215 | |
| 216 | api_key_db.id = old_api_key_db.id |
| 217 | api_key_db = ApiKey.add_or_update(api_key_db) |
| 218 | |
| 219 | extra = {"old_api_key_db": old_api_key_db, "new_api_key_db": api_key_db} |
| 220 | LOG.audit("API Key updated. ApiKey.id=%s." % (api_key_db.id), extra=extra) |
| 221 | api_key_api = ApiKeyAPI.from_model(api_key_db) |
| 222 | |
| 223 | return api_key_api |
| 224 | |
| 225 | def delete(self, api_key_id_or_key, requester_user): |
| 226 | """ |
nothing calls this directly
no test coverage detected