def post(self, actor_id): """Add new permissions for an actor""" logger.debug("top of POST /actors/{}/permissions.".format(actor_id)) id = Actor.get_dbid(g.tenant, actor_id) try: Actor.from_db(actors_store[id]) except KeyError: logger.debug("Did not find actor: {}.".format(actor_id)) raise ResourceError( "actor not found: {}'".format(actor_id), 404) args = self.validate_post() logger.debug("POST permissions body validated for actor: {}.".format(actor_id)) set_permission(args['user'], id, PermissionLevel(args['level'])) logger.info("Permission added for user: {} actor: {} level: {}".format(args['user'], id, args['level'])) permissions = get_permissions(id) return ok(result=permissions, msg="Permission added successfully.")
def post(self): logger.info("top of POST to register a new actor.") args = self.validate_post() logger.debug("validate_post() successful") args['tenant'] = g.tenant args['api_server'] = g.api_server args['owner'] = g.user use_container_uid = args.get('use_container_uid') if Config.get('web', 'case') == 'camel': use_container_uid = args.get('useContainerUid') try: use_tas = Config.get('workers', 'use_tas_uid') except configparser.NoOptionError: logger.debug("no use_tas_uid config.") use_tas = False if hasattr(use_tas, 'lower'): use_tas = use_tas.lower() == 'true' else: logger.error( "use_tas_uid configured but not as a string. use_tas_uid: {}". format(use_tas)) logger.debug("use_tas={}. user_container_uid={}".format( use_tas, use_container_uid)) if use_tas and not use_container_uid: uid, gid, tasdir = get_tas_data(g.user) args['uid'] = uid args['gid'] = gid args['tasdir'] = tasdir args['mounts'] = get_all_mounts(args) actor = Actor(**args) actors_store[actor.db_id] = actor.to_db() logger.debug( "new actor saved in db. id: {}. image: {}. tenant: {}".format( actor.db_id, actor.image, actor.tenant)) actor.ensure_one_worker() logger.debug("ensure_one_worker() called") set_permission(g.user, actor.db_id, UPDATE) logger.debug("UPDATE permission added to user: {}".format(g.user)) return ok(result=actor.display(), msg="Actor created successfully.", request=request)
def put(self, actor_id): logger.debug("top of PUT /actors/{}".format(actor_id)) dbid = Actor.get_dbid(g.tenant, actor_id) try: actor = Actor.from_db(actors_store[dbid]) except KeyError: logger.debug("did not find actor {} in store.".format(dbid)) raise ResourceError( "No actor found with id: {}.".format(actor_id), 404) previous_image = actor.image previous_status = actor.status previous_owner = actor.owner args = self.validate_put(actor) logger.debug("PUT args validated successfully.") args['tenant'] = g.tenant # user can force an update by setting the force param: update_image = args.get('force') if not update_image and args['image'] == previous_image: logger.debug("new image is the same and force was false. not updating actor.") logger.debug("Setting status to the actor's previous status which is: {}".format(previous_status)) args['status'] = previous_status else: update_image = True args['status'] = SUBMITTED logger.debug("new image is different. updating actor.") args['api_server'] = g.api_server # we do not allow a PUT to override the owner in case the PUT is issued by another user args['owner'] = previous_owner use_container_uid = args.get('use_container_uid') if Config.get('web', 'case') == 'camel': use_container_uid = args.get('useContainerUid') try: use_tas = Config.get('workers', 'use_tas_uid') except configparser.NoOptionError: logger.debug("no use_tas_uid config.") use_tas = False if hasattr(use_tas, 'lower'): use_tas = use_tas.lower() == 'true' else: logger.error("use_tas_uid configured but not as a string. use_tas_uid: {}".format(use_tas)) logger.debug("use_tas={}. user_container_uid={}".format(use_tas, use_container_uid)) if use_tas and not use_container_uid: uid, gid, tasdir = get_tas_data(g.user, g.tenant) if uid and gid: args['uid'] = uid args['gid'] = gid if tasdir: args['tasdir'] = tasdir args['mounts'] = get_all_mounts(args) args['last_update_time'] = get_current_utc_time() logger.debug("update args: {}".format(args)) actor = Actor(**args) actors_store[actor.db_id] = actor.to_db() logger.info("updated actor {} stored in db.".format(actor_id)) if update_image: worker_ids = [Worker.request_worker(tenant=g.tenant, actor_id=actor.db_id)] ch = CommandChannel() ch.put_cmd(actor_id=actor.db_id, worker_ids=worker_ids, image=actor.image, tenant=args['tenant']) ch.close() logger.debug("put new command on command channel to update actor.") # put could have been issued by a user with if not previous_owner == g.user: set_permission(g.user, actor.db_id, UPDATE) return ok(result=actor.display(), msg="Actor updated successfully.")