def listServicesHandler(): ''' List all the services known by the ZeroRobot. It is handler for GET /services ''' kwargs = {} for x in [ "name", "template_uid", "template_host", "template_account", "template_repo", "template_name", "template_version" ]: val = request.args.get(x) if val: kwargs[x] = val if auth.god_jwt.check_god_token(request): # god token passed, we list all the services services = [service_view(s) for s in scol.find(**kwargs)] else: # normal flow, only return service for which the user has the secret allowed_services = auth.user_jwt.extract_service_guid(request) services = [ service_view(s) for s in scol.find(**kwargs) if s.guid in allowed_services or scol.is_service_public(s.guid) is True ] return json.dumps(services), 200, {"Content-type": 'application/json'}
def service_view(service): s = { "template": str(service.template_uid), "version": service.version, "name": service.name, "guid": service.guid, "state": state_view(service.state), "actions": [], "public": scol.is_service_public(service.guid) } if config.god: s['data'] = service.data return s
def _verify_secret_token(tokens): service_guid = request.view_args.get('service_guid') if not service_guid: return False for token in tokens.split(' '): if user_jwt.verify(service_guid, token): return True try: if scol.is_service_public(service_guid): return True except scol.ServiceNotFoundError: return False return False
def listServicesHandler(): ''' List all the services known by the ZeroRobot. It is handler for GET /services ''' kwargs = {} for x in [ "name", "template_uid", "template_host", "template_account", "template_repo", "template_name", "template_version" ]: val = request.args.get(x) if val: kwargs[x] = val allowed_services = extract_guid_from_headers(request.headers) services = [ service_view(s) for s in scol.find(**kwargs) if s.guid in allowed_services or scol.is_service_public(s.guid) is True ] return json.dumps(services), 200, {"Content-type": 'application/json'}
def test_set_service_public(self): s1 = FakeService('111', 's1') scol.add(s1) assert scol.is_service_public(s1.guid) is False scol.set_service_public(s1.guid) assert scol.is_service_public(s1.guid)