def setActivatorStatus(activator): " update the activator status" app.logger.info(pformat(activator)) # Does the activator to delete exist? existing_activator = Activator.query.filter( Activator.id == activator['id']).one_or_none() # if found? if existing_activator is not None: existing_activator.status = activator.get('status', existing_activator.status) existing_activator.accessRequestedBy = activator.get( 'accessRequestedBy', existing_activator.accessRequestedBy) existing_activator.lastUpdated = ModelTools.get_utc_timestamp() db.session.merge(existing_activator) db.session.commit() activator = activator_extension.build_activator(existing_activator) activator_schema = ExtendedActivatorSchema() data = activator_schema.dump(activator) return data, 200 # Otherwise, nope, activator to update was not found else: id = activator['id'] abort(404, f"Activator id {id} not found")
def read_all(category=None, status=None, environment=None, platform=None, type=None, source=None, sensitivity=None, page=None, page_size=None, sort=None): """ This function responds to a request for /api/activators with the complete lists of activators :return: json string of list of activators """ # Create the list of activators from our data # pre-process sort instructions if (sort==None): activator_query = Activator.query.order_by(Activator.id) else: try: sort_inst = [ si.split(":") for si in sort ] orderby_arr = [] for si in sort_inst: si1 = si[0] if len(si) > 1: si2 = si[1] else: si2 = "asc" orderby_arr.append(f"{si1} {si2}") #print("orderby: {}".format(orderby_arr)) activator_query = Activator.query.order_by(literal_column(", ".join(orderby_arr))) except Exception as e: print(e) activator_query = Activator.query.order_by(Activator.id) activator_query = activator_query.filter( (category==None or Activator.category==category), (status==None or Activator.status==status), (environment==None or Activator.envs.like("%\"{}\"%".format(environment))), (platform==None or Activator.platforms.like("%\"{}\"%".format(platform))), (type==None or Activator.type==type), (source==None or Activator.sourceControl.like("%\"{}\"%".format(source))), (sensitivity==None or Activator.sensitivity==sensitivity) ) if (page==None or page_size==None): activators = activator_query.all() else: activators = activator_query.limit(page_size).offset(page * page_size).all() activators_arr = [] for act in activators: activators_arr.append(activator_extension.build_activator(act)) # Serialize the data for the response activator_schema = ExtendedActivatorSchema(many=True) data = activator_schema.dump(activators_arr) app.logger.debug("read_all") app.logger.debug(pformat(data)) return data, 200
def read_one(id): """ This function responds to a request for /api/activator/{key} with one matching activator from activatorss :param application: key of activator to find :return: activator matching key """ act = (Activator.query.filter(Activator.id == id).one_or_none()) activator = activator_extension.build_activator(act) if activator is not None: # Serialize the data for the response activator_schema = ExtendedActivatorSchema() data = activator_schema.dump(activator) return data else: abort(404, "Activator with id {id} not found".format(id=id))
def read_all(category=None, status=None, environment=None, platform=None, type=None, source=None, sensitivity=None): """ This function responds to a request for /api/activators with the complete lists of activators :return: json string of list of activators """ # Create the list of activators from our data activators = Activator.query.filter( (category == None or Activator.category == category), (status == None or Activator.status == status), (environment == None or Activator.envs.like("%\"{}\"%".format(environment))), (platform == None or Activator.platforms.like("%\"{}\"%".format(platform))), (type == None or Activator.type == type), (source == None or Activator.sourceControl.like("%\"{}\"%".format(source))), (sensitivity == None or Activator.sensitivity == sensitivity)).order_by( Activator.id).all() activators_arr = [] for act in activators: activators_arr.append(activator_extension.build_activator(act)) # Serialize the data for the response activator_schema = ExtendedActivatorSchema(many=True) data = activator_schema.dump(activators_arr) app.logger.debug("read_all") app.logger.debug(pformat(data)) return data