Ejemplo n.º 1
0
 def provision_pgt(self, request, st, success):
     '''Provision a PGT ticket if requested
     '''
     pgt_url = request.GET.get(PGT_URL_PARAM)
     if not pgt_url:
         return
     if not pgt_url.startswith('https://'):
         self.logger.warning('ignoring non HTTP pgtUrl %r', pgt_url)
         return
     # PGT URL must be declared
     if not st.service.match_service(pgt_url):
         self.logger.warning('pgtUrl %r does not match service %r', pgt_url,
                             st.service.slug)
     pgt = make_id(PGT_PREFIX)
     pgt_iou = make_id(PGT_IOU_PREFIX)
     # Skip PGT_URL check for testing purpose
     # instead store PGT_IOU / PGT association in session
     if app_settings.CHECK_PGT_URL:
         response = requests.get(pgt_url,
                                 params={
                                     PGT_ID_PARAM: pgt,
                                     PGT_IOU_PARAM: pgt_iou
                                 })
         if response.status_code != 200:
             self.logger.warning('pgtUrl %r returned non 200 code: %d',
                                 pgt_url, response.status_code)
             return
     else:
         request.session[pgt_iou] = pgt
     proxies = ('%s %s' % (pgt_url, st.proxies)).strip()
     # Save the PGT ticket
     Ticket.objects.create(ticket_id=pgt,
                           expire=None,
                           service=st.service,
                           service_url=st.service_url,
                           validity=True,
                           user=st.user,
                           session_key=st.session_key,
                           proxies=proxies)
     user = ET.SubElement(success, PGT_ELT)
     user.text = pgt_iou
     if self.add_proxies:
         proxies_elt = ET.SubElement(success, PROXIES_ELT)
         for proxy in st.proxies.split():
             proxy_elt = ET.SubElement(proxies_elt, PROXY_ELT)
             proxy_elt.text = proxy
Ejemplo n.º 2
0
 def provision_pgt(self, request, st, success):
     '''Provision a PGT ticket if requested
     '''
     pgt_url = request.GET.get(PGT_URL_PARAM)
     if not pgt_url:
         return
     if not pgt_url.startswith('https://'):
         self.logger.warning('ignoring non HTTP pgtUrl %r', pgt_url)
         return
     # PGT URL must be declared
     if not st.service.match_service(pgt_url):
         self.logger.warning('pgtUrl %r does not match service %r',
             pgt_url, st.service.slug)
     pgt = make_id(PGT_PREFIX)
     pgt_iou = make_id(PGT_IOU_PREFIX)
     # Skip PGT_URL check for testing purpose
     # instead store PGT_IOU / PGT association in session
     if app_settings.CHECK_PGT_URL:
         response = requests.get(pgt_url, params={
            PGT_PARAM: pgt,
            PGT_IOU_PARAM: pgt_iou})
         if response.status_code != 200:
             self.logger.warning('pgtUrl %r returned non 200 code: %d',
                 pgt_url, response.status_code)
             return
     else:
         request.session[pgt_iou] = pgt
     proxies = ('%s %s' % (pgt_url, st.proxies)).strip()
     # Save the PGT ticket
     Ticket.objects.create(
             ticket_id=pgt,
             expire=None,
             service=st.service,
             service_url=st.service_url,
             validity=True,
             user=st.user,
             session_key=st.session_key,
             proxies=proxies)
     user = ET.SubElement(success, PGT_ELT)
     user.text = pgt_iou
     if self.add_proxies:
         proxies_elt = ET.SubElement(success, PROXIES_ELT)
         for proxy in st.proxies.split():
             proxy_elt = ET.SubElement(proxies_elt, PROXY_ELT)
             proxy_elt.text = proxy
Ejemplo n.º 3
0
def load_app(app_def_file, app_id=None):
    """Loads an app definition from a json file and sets the app id."""
    app_path = os.path.join(apps_dir(), "{}.json".format(app_def_file))
    app = get_resource(app_path)

    if app_id is None:
        app['id'] = make_id(app_def_file)
    else:
        app['id'] = app_id

    return app
Ejemplo n.º 4
0
def load_app(app_def_file, app_id=None, parent_group="/"):
    """Loads an app definition from a json file and sets the app id."""
    app_path = os.path.join(apps_dir(), "{}.json".format(app_def_file))
    app = get_resource(app_path)

    if app_id is None:
        app['id'] = make_id(app_def_file, parent_group)
    else:
        app['id'] = join(parent_group, app_id)

    logger.info('Loaded an app definition with id={}'.format(app['id']))
    return app
Ejemplo n.º 5
0
def load_app(app_def_file, app_id=None, parent_group="/"):
    """Loads an app definition from a json file and sets the app id."""
    app_path = os.path.join(apps_dir(), "{}.json".format(app_def_file))
    app = get_resource(app_path)

    if app_id is None:
        app['id'] = make_id(app_def_file, parent_group)
    else:
        app['id'] = join(parent_group, app_id)

    logger.info('Loaded an app definition with id={}'.format(app['id']))
    return app
Ejemplo n.º 6
0
def conference_api():
    """
    1. Create a conference name
    2. Create an endpoint and store in redis with conference name
    3. Attach the above application to it
    4. Return endpoint username/password to template
    """
    conference_name = 'p%s' % (make_id(8))
    app_id = create_plivo_application(conference_name)
    endpoint_username = create_plivo_endpoint(conference_name, app_id)
    inbound_did = attach_inbound_did(app_id)
    link_conference(conference_name, endpoint_username, conference_name, inbound_did)

    conference_url = url_for('conference', _external=True, conference_name=conference_name)
    return jsonify(conference_url = conference_url, conference_name = conference_name)
Ejemplo n.º 7
0
 def get(self, request):
     pgt = request.GET.get(PGT_PARAM)
     target_service_url = request.GET.get(TARGET_SERVICE_PARAM)
     if not pgt or not target_service_url:
         return self.validation_failure(
             INVALID_REQUEST_ERROR,
             "'pgt' and 'targetService' parameters are both required")
     if not pgt.startswith(PGT_PREFIX):
         return self.validation_failure(
             BAD_PGT_ERROR, 'a proxy granting ticket must start with PGT-')
     try:
         pgt = Ticket.objects.get(ticket_id=pgt)
     except Ticket.DoesNotExist:
         pgt = None
     if pgt is None:
         return self.validation_failure(BAD_PGT_ERROR, 'pgt does not '
                                        'exist')
     if not pgt.valid():
         pgt.delete()
         return self.validation_failure(BAD_PGT_ERROR,
                                        'session has expired')
     target_service = Service.objects.for_service(target_service_url)
     # No target service exists for this url, maybe the URL is missing from
     # the urls field
     if not target_service:
         return self.validation_failure(INVALID_TARGET_SERVICE_ERROR,
                                        'target service is invalid')
     # Verify that the requested service is authorized to get proxy tickets
     # for the target service
     if not target_service.proxy.filter(pk=pgt.service_id).exists():
         return self.validation_failure(
             PROXY_UNAUTHORIZED_ERROR,
             'proxying to the target service is forbidden')
     pt = Ticket.objects.create(ticket_id=make_id(PT_PREFIX),
                                validity=True,
                                expire=now() + timedelta(seconds=60),
                                service=target_service,
                                service_url=target_service_url,
                                user=pgt.user,
                                session_key=pgt.session_key,
                                proxies=pgt.proxies)
     return self.validation_success(request, pt)
Ejemplo n.º 8
0
 def get(self, request):
     pgt = request.GET.get(PGT_PARAM)
     target_service_url = request.GET.get(TARGET_SERVICE_PARAM)
     if not pgt or not target_service_url:
         return self.validation_failure(INVALID_REQUEST_ERROR,
                 "'pgt' and 'targetService' parameters are both required")
     if not pgt.startswith(PGT_PREFIX):
         return self.validation_failure(BAD_PGT_ERROR,
                 'a proxy granting ticket must start with PGT-')
     try:
         pgt = Ticket.objects.get(ticket_id=pgt)
     except Ticket.DoesNotExist:
         pgt = None
     if pgt is None:
         return self.validation_failure(BAD_PGT_ERROR, 'pgt does not '
                 'exist')
     if not pgt.valid():
         pgt.delete()
         return self.validation_failure(BAD_PGT_ERROR, 'session has expired')
     target_service = Service.objects.for_service(target_service_url)
     # No target service exists for this url, maybe the URL is missing from
     # the urls field
     if not target_service:
         return self.validation_failure(INVALID_TARGET_SERVICE_ERROR,
                 'target service is invalid')
     # Verify that the requested service is authorized to get proxy tickets
     # for the target service
     if not target_service.proxy.filter(pk=pgt.service_id).exists():
         return self.validation_failure(PROXY_UNAUTHORIZED_ERROR,
                 'proxying to the target service is forbidden')
     pt = Ticket.objects.create(
         ticket_id=make_id(PT_PREFIX),
         validity=True,
         expire=now()+timedelta(seconds=60),
         service=target_service,
         service_url=target_service_url,
         user=pgt.user,
         session_key=pgt.session_key,
         proxies=pgt.proxies)
     return self.validation_success(request, pt)
Ejemplo n.º 9
0
    # Optimization parameters
    train_epoch = config['optimization_params']['train_epoch']
    test_epoch = config['optimization_params']['test_epoch']
    L2 = config['optimization_params']['L2']
    train_lr = config['optimization_params']['train_lr']
    test_lr = config['optimization_params']['test_lr']

    # Network parameters -- single hidden layer MLP
    # Can also adjust the nonlinearity
    OUT_DIM = 2
    INPUT_SIZE = 6  #data, lik1, lik2, prior, N_ratio, N_t
    NHID = config['network_params']['NHID']
    NONLIN = config['network_params']['NONLIN']

    storage_id = utils.make_id(config)

    # Informative data vs uninformative data

    ID_approx_model = expt.get_approxmodel(OUT_DIM, INPUT_SIZE, NHID, NONLIN)
    ID_rational_model = expt.get_rationalmodel(N_trials)
    ID_block_vals = expt.assign_PL_EU(N_balls, N_blocks, True)
    ID_X = expt.data_gen(ID_block_vals, N_trials)

    UD_approx_model = expt.get_approxmodel(OUT_DIM, INPUT_SIZE, NHID, NONLIN)
    UD_rational_model = expt.get_rationalmodel(N_trials)
    UD_block_vals = expt.assign_PL_EU(N_balls, N_blocks, False)
    UD_X = expt.data_gen(UD_block_vals, N_trials)

    # Create the data frames
    ID_train_data = {
Ejemplo n.º 10
0
        return repo_origin(self.repo.name, self.schema["RepoTags"])


if __name__ == "__main__":
    from docker import Client
    c = Client("unix:///var/run/docker.sock")
    esquema = {
        'Created': 1441279808,
        'Labels': {},
        'VirtualSize': 795865269,
        'ParentId':
        '9cce8d0ab3ceadd880b97330a259d362e51e303089fc096db5094f2642585bee',
        'RepoTags': ['iso8601:latest', 'src/iso8601:latest'],
        'RepoDigests': [],
        'Id':
        '15ef989c576bdc0ae8ed721f9c58a850ee050620ed8e9d816dacaffdb050e497',
        'Size': 0
    }

    from utils import make_id

    class tmp:
        pass

    val = Validador(esquema)
    val.client = c
    val.repo = tmp()
    val.repo.name = "src"
    dataset = "http://datos.labcd.mx/dataset/3968a764-f85a-4b7c-903b-bd3e3e23fd78/resource/1f2b8d6b-c93a-4f63-b6c3-90293a91726b/download/embajadas.csv"
    val.run(make_id(), dataset)
Ejemplo n.º 11
0
def load_pod(pod_name):
    pod_path = os.path.join(pods_dir(), "{}.json".format(pod_name))
    pod = get_resource(pod_path)
    pod['id'] = make_id(pod_name)
    return pod
Ejemplo n.º 12
0
def load_app(app_name):
    app_path = os.path.join(apps_dir(), "{}.json".format(app_name))
    app = get_resource(app_path)
    app['id'] = make_id(app_name)
    return app
Ejemplo n.º 13
0
        work.run()
        return work

    @property
    def name(self):
        return repo_origin(self.repo.name, self.schema["RepoTags"])


if __name__ == "__main__":
    from docker import Client
    c = Client("unix:///var/run/docker.sock")
    esquema = {'Created': 1441279808,
               'Labels': {},
               'VirtualSize': 795865269,
               'ParentId': '9cce8d0ab3ceadd880b97330a259d362e51e303089fc096db5094f2642585bee',
               'RepoTags': ['iso8601:latest', 'src/iso8601:latest'],
               'RepoDigests': [],
               'Id': '15ef989c576bdc0ae8ed721f9c58a850ee050620ed8e9d816dacaffdb050e497',
               'Size': 0
               }

    from utils import make_id
    class tmp:
        pass
    val = Validador(esquema)
    val.client = c
    val.repo =tmp()
    val.repo.name = "src"
    dataset = "http://datos.labcd.mx/dataset/3968a764-f85a-4b7c-903b-bd3e3e23fd78/resource/1f2b8d6b-c93a-4f63-b6c3-90293a91726b/download/embajadas.csv"
    val.run(make_id(), dataset)
Ejemplo n.º 14
0
def load_app(app_name):
    app_path = os.path.join(apps_dir(), "{}.json".format(app_name))
    app = get_resource(app_path)
    app['id'] = make_id(app_name)
    return app