Skip to content

Commit ac5d138

Browse files
committed
add support for Cb Protection URL query parameters when updating certain values
1 parent c949ec6 commit ac5d138

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/cbapi/models.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def _refresh(self):
244244
return True
245245
return False
246246

247-
def _build_api_request_uri(self):
247+
def _build_api_request_uri(self, http_method="GET"):
248248
baseuri = self.__class__.__dict__.get('urlobject', None)
249249
if self._model_unique_id is not None:
250250
return baseuri + "/%s" % self._model_unique_id
@@ -372,8 +372,9 @@ def _update_object(self):
372372
data=new_object_info)
373373
else:
374374
log.debug("Updating {0:s} with unique ID {1:s}".format(self.__class__.__name__, str(self._model_unique_id)))
375-
ret = self._cb.api_json_request(self.__class__._change_object_http_method,
376-
self._build_api_request_uri(), data=self._info)
375+
http_method = self.__class__._change_object_http_method
376+
ret = self._cb.api_json_request(http_method,self._build_api_request_uri(http_method=http_method),
377+
data=self._info)
377378

378379
return self._refresh_if_needed(ret)
379380

src/cbapi/protection/models.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,23 @@ class Computer(MutableBaseModel):
102102
def __init__(self, cb, model_unique_id, initial_data=None):
103103
super(Computer, self).__init__(cb, model_unique_id, initial_data)
104104

105+
def _build_api_request_uri(self, http_method="GET"):
106+
base_uri = super(Computer, self)._build_api_request_uri(http_method=http_method)
107+
args = []
108+
109+
if http_method == "PUT":
110+
if any(n in self._dirty_attributes
111+
for n in ["debugLevel", "kernelDebugLevel", "debugFlags", "debugDuration", "ccLevel", "ccFlags"]):
112+
args.append("changeDiagnostics=true")
113+
if any(n in self._dirty_attributes
114+
for n in ["template", "templateCloneCleanupMode", "templateCloneCleanupTime", "templateCloneCleanupTimeScale", "templateTrackModsOnly"]):
115+
args.append("changeTemplate=true")
116+
117+
if args:
118+
base_uri += "?{0}".format("&".join(args))
119+
120+
return base_uri
121+
105122
@property
106123
def policy(self):
107124
return self._join(Policy, "policyId")
@@ -115,13 +132,14 @@ def fileInstances(self):
115132
return self._cb.select(FileInstance).where("computerId:{0:d}".format(self.id))
116133

117134
@property
118-
def template(self):
135+
def templateComputer(self):
119136
return self._join(Computer, "templateComputerId")
120137

121138
def resetCLIPassword(self):
122-
self._build_api_request_uri()
139+
url = self._build_api_request_uri() + "?resetCLIPassword=true"
140+
self._cb.put_object(url, {})
123141
self.refresh()
124-
return getattr(self, "cliPassword")
142+
return getattr(self, "CLIPassword")
125143

126144

127145
class Connector(MutableBaseModel, CreatableModelMixin):

0 commit comments

Comments
 (0)