Skip to content

Commit db7743d

Browse files
author
Patrick J. McNerthney
committed
Rework how self.connection and resource.connection are implemented
1 parent 4b91ebc commit db7743d

2 files changed

Lines changed: 10 additions & 35 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ The BaseComposite class provides the following fields for manipulating the Compo
203203
| self.spec | Map | The composite observed spec |
204204
| self.status | Map | The composite desired and observed status, read from observed if not in desired |
205205
| self.conditions | Conditions | The composite desired and observed conditions, read from observed if not in desired |
206-
| self.connection | Connection | The composite desired and observed connection detials, read from observed if not in desired |
207206
| self.events | Events | Returned events against the Composite and optionally on the Claim |
207+
| self.connection | Connection | The composite desired and observed connection detials, read from observed if not in desired |
208208
| self.ready | Boolean | The composite desired ready state |
209209

210210
The BaseComposite also provides access to the following Crossplane Function level features:

crossplane/pythonic/composite.py

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def __init__(self, request, logger):
4444
self.spec = self.observed.spec
4545
self.status = self.desired.status
4646
self.conditions = Conditions(observed, self.response)
47-
self.connection = Connection(observed, desired)
4847
self.events = Events(self.response)
4948

5049
@property
@@ -67,6 +66,14 @@ def ttl(self, ttl):
6766
else:
6867
raise ValueError('ttl must be an int or float')
6968

69+
@property
70+
def connection(self):
71+
return self.response.desired.composite.connection_details
72+
73+
@connection.setter
74+
def connection(sel, connection):
75+
self.response.desired.composite.connection_details = connection
76+
7077
@property
7178
def ready(self):
7279
ready = self.desired._parent.ready
@@ -190,7 +197,7 @@ def __init__(self, composite, name):
190197
self.observed = observed.resource
191198
self.desired = desired.resource
192199
self.conditions = Conditions(observed)
193-
self.connection = Connection(observed)
200+
self.connection = observed.connection_details
194201
self.unknownsFatal = None
195202
self.autoReady = None
196203
self.usages = None
@@ -555,38 +562,6 @@ def _find_condition(self, create=False):
555562
return self._conditions._response.conditions.append(condition)
556563

557564

558-
class Connection:
559-
def __init__(self, observed, desired=None):
560-
self.__dict__['_observed'] = observed
561-
self.__dict__['_desired'] = desired
562-
563-
def __bool__(self):
564-
if self._desired is not None and len(self._desired.connection_details) > 0:
565-
return True
566-
if self._observed is not None and len(self._observed.connection_details) > 0:
567-
return True
568-
return False
569-
570-
def __getattr__(self, key):
571-
return self[key]
572-
573-
def __getitem__(self, key):
574-
value = None
575-
if self._desired is not None and key in self._desired.connection_details:
576-
value = self._desired.connection_details[key]
577-
if value is None and key in self._observed.connection_details:
578-
value = self._observed.connection_details[key]
579-
return value
580-
581-
def __setattr__(self, key, value):
582-
self[key] = value
583-
584-
def __setitem__(self, key, value):
585-
if self._desired is None:
586-
raise ValueError('Connection is read only')
587-
self._desired.connection_details[key] = value
588-
589-
590565
class Events:
591566
def __init__(self, response):
592567
self._results = response.results

0 commit comments

Comments
 (0)