Skip to content

Commit 7207e78

Browse files
committed
GCPSigner: Tweak import return value
Instead of being a constructor, import_() now returns the private key URI and the public Key. This makes sense as * it's still trivial to construct the Signer if needed * In many cases we don't actually use the Signer at import time * This works around the problem that a Signer instance might need a SecretsHandler * This setup likely works for key generation as well
1 parent 6c3f985 commit 7207e78

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

securesystemslib/signer/_gcp_signer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,12 @@ def from_priv_key_uri(
8585
return cls(uri.path, public_key)
8686

8787
@classmethod
88-
def import_(cls, gcp_keyid: str):
89-
"""Load signer (including public key) from KMS"""
88+
def import_(cls, gcp_keyid: str) -> Tuple[str, Key]:
89+
"""Load key and signer details from KMS
90+
91+
Returns the private key uri and the public key. This method should only
92+
be called once per key: the uri and Key should be stored for later use.
93+
"""
9094
if GCP_IMPORT_ERROR:
9195
raise exceptions.UnsupportedLibraryError(GCP_IMPORT_ERROR)
9296

@@ -104,7 +108,7 @@ def import_(cls, gcp_keyid: str):
104108
keyid = _get_keyid(keytype, scheme, keyval)
105109
public_key = SSlibKey(keyid, keytype, scheme, keyval)
106110

107-
return cls(gcp_keyid, public_key)
111+
return f"{cls.SCHEME}:{gcp_keyid}", public_key
108112

109113
@staticmethod
110114
def _get_keytype_and_scheme(algorithm: int) -> Tuple[str, str]:

tests/check_kms_signers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def test_gcp_import(self):
6565
assign @jku.
6666
"""
6767

68-
signer = GCPSigner.import_(self.gcp_id)
69-
self.assertEqual(self.pubkey, signer.public_key)
68+
uri, key = GCPSigner.import_(self.gcp_id)
69+
self.assertEqual(key, self.pubkey)
70+
self.assertEqual(uri, f"gcpkms:{self.gcp_id}")
7071

7172

7273
if __name__ == "__main__":

0 commit comments

Comments
 (0)