Skip to content

Commit 9cbe137

Browse files
committed
freshen cwltool/secrets.py
1 parent a84ddf1 commit 9cbe137

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

cwltool/secrets.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
"""Minimal in memory storage of secrets."""
22
import uuid
3-
from typing import Any, Dict, List, MutableMapping, MutableSequence
3+
from typing import Dict, List, MutableMapping, MutableSequence, Optional, cast
4+
5+
from .utils import CWLObjectType, CWLOutputType
46

57

68
class SecretStore(object):
79
"""Minimal implementation of a secret storage."""
810

9-
def __init__(self): # type: () -> None
11+
def __init__(self) -> None:
1012
"""Initialize the secret store."""
1113
self.secrets = {} # type: Dict[str, str]
1214

13-
def add(self, value): # type: (str) -> str
15+
def add(self, value: Optional[CWLOutputType]) -> Optional[CWLOutputType]:
1416
"""
1517
Add the given value to the store.
1618
@@ -25,36 +27,36 @@ def add(self, value): # type: (str) -> str
2527
return placeholder
2628
return value
2729

28-
def store(self, secrets, job):
29-
# type: (List[str], MutableMapping[str, Any]) -> None
30+
def store(self, secrets: List[str], job: CWLObjectType) -> None:
3031
"""Sanitize the job object of any of the given secrets."""
3132
for j in job:
3233
if j in secrets:
3334
job[j] = self.add(job[j])
3435

35-
def has_secret(self, value): # type: (Any) -> bool
36+
def has_secret(self, value: CWLOutputType) -> bool:
3637
"""Test if the provided document has any of our secrets."""
3738
if isinstance(value, str):
3839
for k in self.secrets:
3940
if k in value:
4041
return True
4142
elif isinstance(value, MutableMapping):
4243
for this_value in value.values():
43-
if self.has_secret(this_value):
44+
if self.has_secret(cast(CWLOutputType, this_value)):
4445
return True
4546
elif isinstance(value, MutableSequence):
4647
for this_value in value:
47-
if self.has_secret(this_value):
48+
if self.has_secret(cast(CWLOutputType, this_value)):
4849
return True
4950
return False
5051

51-
def retrieve(self, value): # type: (Any) -> Any
52+
def retrieve(self, value: CWLOutputType) -> CWLOutputType:
5253
"""Replace placeholders with their corresponding secrets."""
5354
if isinstance(value, str):
5455
for key, this_value in self.secrets.items():
5556
value = value.replace(key, this_value)
57+
return value
5658
elif isinstance(value, MutableMapping):
57-
return {k: self.retrieve(v) for k, v in value.items()}
59+
return {k: self.retrieve(cast(CWLOutputType, v)) for k, v in value.items()}
5860
elif isinstance(value, MutableSequence):
59-
return [self.retrieve(v) for k, v in enumerate(value)]
61+
return [self.retrieve(cast(CWLOutputType, v)) for v in value]
6062
return value

0 commit comments

Comments
 (0)