def update(self, name="snow_account", snow_url=None, release="automatic", username=None, password=None): response, data = self.validate_snow_account(snow_url, release, username, password) if response.status not in (200, 201): raise admin.InternalException( "Can not authenticate the ServiceNow account you provided.") account = self.get_by_name(name) props = { "url": snow_url, "release": release, "username": username, "password": password } account.update( **{ "body": binding._encode(**props), "app": "Splunk_TA_snow", "owner": self._service.namespace.get('owner') }) return self.get_by_name(name)
def delete(self, name="snow_account"): account = self.get_by_name(name) props = {"url": " ", "release": " ", "username": "******", "password": "******"} return account.update( **{ "body": binding._encode(**props), "app": "Splunk_TA_snow", "owner": self._service.namespace.get('owner') })
def handleEdit(self, confInfo): target = self.callerArgs[ARG_TARGET][0] service = self._get_ta_target_service(target) snow_default = self._get_snow_default(service) collection_interval = self.callerArgs["collection_interval"][0] since_when = self.callerArgs["since_when"][0] since_when = since_when if since_when else "" loglevel = self.callerArgs["loglevel"][0] props = {"collection_interval": collection_interval, "since_when": since_when, "loglevel": loglevel} snow_default.update( **{"body": binding._encode(**props),"app": "Splunk_TA_snow","owner": service.namespace.get('owner')}) return self._get_snow_default(service)
def update(self, name, exclude="", index="main", host="splunk", duration=None, timefield="sys_updated_on", since_when=""): input = self.get_by_name(name) props = { "host": host, "index": index, "timefield": timefield, "duration": duration } if exclude: props["exclude"] = exclude if since_when: props["since_when"] = since_when input.update( **{ "body": binding._encode(**props), "app": SNOW_TA_NAME, "owner": self.service.namespace.get('owner') })
def update(self, path, owner=None, perms_read=None, perms_write=None): '''Update ACL of /servicesNS/{`owner`}/{`app`}/{`path`}. If the ACL is per-entity (ends in /acl), owner can be reassigned. If the acl is endpoint-level (ends in _acl), owner will be ignored. The 'sharing' setting is always retrieved from the current. :param path: Path of ACL relative to /servicesNS/{owner}/{app}. MUST end with /acl or /_acl indicating whether the permission is applied at the per-entity level or endpoint level respectively. :type path: ``string`` :param owner: (optional) New owner of ACL, default is `nobody`. :type owner: ``string`` :param perms_read: (optional) List of roles (['*'] for all roles). If unspecified we will POST with current (if available) perms.read, default is None. :type perms_read: ``list`` :param perms_write: (optional) List of roles (['*'] for all roles). If unspecified we will POST with current (if available) perms.write, default is None. :type perms_write: ``list`` :returns: A dict contains ACL after update. :rtype: ``dict`` :raises ACLException: If `path` is invalid. Usage:: >>> aclm = acl.ACLManager(session_key, 'Splunk_TA_test') >>> perms = aclm.update('data/transforms/extractions/_acl', perms_read=['admin'], perms_write=['admin']) ''' if not path.endswith('/acl') and not path.endswith('/_acl'): raise ACLException( 'Invalid endpoint: %s, must end with /acl or /_acl.' % path) curr_acl = self.get(path) postargs = {} if perms_read: postargs['perms.read'] = ','.join(perms_read) else: curr_read = curr_acl['perms'].get('read', []) if curr_read: postargs['perms.read'] = ','.join(curr_read) if perms_write: postargs['perms.write'] = ','.join(perms_write) else: curr_write = curr_acl['perms'].get('write', []) if curr_write: postargs['perms.write'] = ','.join(curr_write) if path.endswith('/acl'): # Allow ownership to be reset only at entity level. postargs['owner'] = owner or curr_acl['owner'] postargs['sharing'] = curr_acl['sharing'] try: content = self._rest_client.post(path, body=binding._encode(**postargs), output_mode='json').body.read() except binding.HTTPError as e: if e.status != 404: raise raise ACLException('Invalid endpoint: %s.', path) return json.loads(content)['entry'][0]['acl']
def update( self, path: str, owner: str = None, perms_read: List = None, perms_write: List = None, ) -> dict: """Update ACL of /servicesNS/{`owner`}/{`app`}/{`path`}. If the ACL is per-entity (ends in /acl), owner can be reassigned. If the acl is endpoint-level (ends in _acl), owner will be ignored. The 'sharing' setting is always retrieved from the current. Arguments: path: Path of ACL relative to /servicesNS/{owner}/{app}. MUST end with /acl or /_acl indicating whether the permission is applied at the per-entity level or endpoint level respectively. owner: (optional) New owner of ACL, default is `nobody`. perms_read: (optional) List of roles (['*'] for all roles). If unspecified we will POST with current (if available) perms.read, default is None. perms_write: (optional) List of roles (['*'] for all roles). If unspecified we will POST with current (if available) perms.write, default is None. Returns: A dict contains ACL after update. Raises: ACLException: If `path` is invalid. Examples: >>> aclm = acl.ACLManager(session_key, 'Splunk_TA_test') >>> perms = aclm.update('data/transforms/extractions/_acl', perms_read=['admin'], perms_write=['admin']) """ if not path.endswith("/acl") and not path.endswith("/_acl"): raise ACLException( "Invalid endpoint: %s, must end with /acl or /_acl." % path ) curr_acl = self.get(path) postargs = {} if perms_read: postargs["perms.read"] = ",".join(perms_read) else: curr_read = curr_acl["perms"].get("read", []) if curr_read: postargs["perms.read"] = ",".join(curr_read) if perms_write: postargs["perms.write"] = ",".join(perms_write) else: curr_write = curr_acl["perms"].get("write", []) if curr_write: postargs["perms.write"] = ",".join(curr_write) if path.endswith("/acl"): # Allow ownership to be reset only at entity level. postargs["owner"] = owner or curr_acl["owner"] postargs["sharing"] = curr_acl["sharing"] try: content = self._rest_client.post( path, body=binding._encode(**postargs), output_mode="json" ).body.read() except binding.HTTPError as e: if e.status != 404: raise raise ACLException("Invalid endpoint: %s.", path) return json.loads(content)["entry"][0]["acl"]
def move(self, move_args): body = _encode(**move_args) return self.post('move', **{'body': body})