(cls, model, mask_secrets=True)
| 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): |
nothing calls this directly
no test coverage detected