MCPcopy
hub / github.com/diffgram/diffgram / ConnectionStrategy

Class ConnectionStrategy

shared/connection/connection_strategy.py:26–151  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24
25@dataclass()
26class ConnectionStrategy:
27
28 def __init__(self,
29 session = None,
30 connection_class = None,
31 connection = None,
32 connection_id = None,
33 integration_name = None):
34
35 self.connection = connection
36 self.session = session
37 self.integration_name = integration_name
38 self.connection_class = connection_class
39
40 if connection_id:
41 self.set_connection(connection_id = connection_id, check_perms = False)
42
43 def __post_init__(self):
44 if not self.connection_class:
45 self.set_connection()
46
47 def set_class(self):
48 # The Context is that for some of the storage ones with similar patterns we use the strategy pattern
49 # For other classes we still want to follow the connection and test pattern
50 # But Already know the class so can just pass it at setup
51 # This also removes need to add all to strategy mapping unless good reason like with storage where pattern is so similar
52
53 if self.connection_class:
54 return
55
56 if self.integration_name:
57 self.connection_class = CONNECTIONS_MAPPING[self.integration_name]
58 else:
59 self.connection_class = CONNECTIONS_MAPPING[self.connection.integration_name]
60
61 def get_client(self):
62 if not self.connection:
63 raise Exception("connection object or connection_id must be supplied at init")
64
65 connector, success = self.get_connector()
66
67 connector.connect()
68
69 return connector.get_client()
70
71 def set_connection(self, connection_id = None, check_perms = None):
72 if not connection_id: return
73
74 self.connection_operations = Connection_Operations(
75 session = self.session,
76 member = None,
77 connection_id = connection_id
78 )
79 self.connection = self.connection_operations.get_existing_connection(connection_id)
80 if check_perms:
81 self.connection_operations.validate_existing_connection_id_permissions()
82
83 def build_auth_data(self, input = None):

Callers 12

fetch_dataFunction · 0.90
put_dataFunction · 0.90
test_connection_apiFunction · 0.90
execute_actionMethod · 0.90
execute_actionMethod · 0.90
execute_actionMethod · 0.90

Calls

no outgoing calls

Tested by 1

test_connection_apiFunction · 0.72