MCPcopy Index your code
hub / github.com/TaskingAI/TaskingAI / BundleCredentials

Class BundleCredentials

plugin/app/models/credentials.py:9–70  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

7
8
9class BundleCredentials(BaseModel):
10
11 credentials: Dict[str, str] = Field({})
12
13 def __getattr__(self, item):
14 # This method is called only if Python doesn't find the attribute
15 # in the usual places (instance dictionary or class hierarchy).
16 if item in self.credentials:
17 return self.credentials.get(item)
18 else:
19 # If the item is not in credentials return None
20 return None
21
22 def encrypt(self):
23 for key, value in self.credentials.items():
24 if value is not None:
25 encrypted_value = aes_encrypt(value)
26 self.credentials[key] = str(encrypted_value)
27 return self
28
29 def decrypt(self):
30 for key, value in self.credentials.items():
31 if value is not None:
32 if "," in value:
33 try:
34 decrypted_value = aes_decrypt(value)
35 self.credentials[key] = str(decrypted_value)
36 except ValueError as e:
37 raise ValueError(f"error decrypting {key}: {e}")
38 else:
39 raise ValueError(f"invalid credentials. Not encrypted: {value}")
40 return self
41
42 def load_input(self, bundle_id, credentials: Dict[str, str]):
43 try:
44 from app.cache import get_bundle
45
46 allowed_fields = get_bundle(bundle_id).allowed_credential_names()
47 for field in allowed_fields:
48 if field in credentials:
49 self.credentials[field] = credentials[field]
50 return self
51 except Exception as e:
52 raise ValueError(f"error loading credentials from input: {e}")
53
54 def load_default(self, bundle_id):
55 try:
56 from app.cache import get_bundle
57
58 default_credentials = get_bundle(bundle_id).allowed_credential_names()
59 for name in default_credentials:
60 self.credentials[name] = load_str_env(name, required=True)
61 return self
62 except Exception as e:
63 raise ValueError(f"error loading credentials from env: {e}")
64
65 def to_dict(self, bundle_id):
66 from app.cache import get_bundle

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected