示例#1
0
def prepare_auction_and_participation_urls(self):
    auction_url = self.worker_defaults["AUCTIONS_URL"].format(
        auction_id=self.tender_id)
    patch_data = {"data": {"auctionUrl": auction_url, "bids": []}}
    for bid in self._auction_data["data"]["bids"]:
        if bid.get('status', 'active') == 'active':
            participation_url = self.worker_defaults["AUCTIONS_URL"].format(
                auction_id=self.auction_doc_id)
            participation_url += '/login?bidder_id={}&hash={}'.format(
                bid["id"],
                calculate_hash(bid["id"], self.worker_defaults["HASH_SECRET"]))
            patch_data['data']['bids'].append({
                "participationUrl": participation_url,
                "id": bid["id"]
            })
        else:
            patch_data['data']['bids'].append({"id": bid["id"]})
    LOGGER.info("Set auction and participation urls for tender {}".format(
        self.tender_id),
                extra={
                    "JOURNAL_REQUEST_ID": self.request_id,
                    "MESSAGE_ID": AUCTION_WORKER_SET_AUCTION_URLS
                })
    LOGGER.info(repr(patch_data))
    make_request(self.tender_url + '/auction',
                 patch_data,
                 user=self.worker_defaults["TENDERS_API_TOKEN"],
                 request_id=self.request_id,
                 session=self.session)
示例#2
0
 def set_participation_urls(self, external_data):
     request_id = generate_request_id()
     patch_data = {"data": {"auctionUrl": self.auction_url, "bids": []}}
     for bid in external_data["data"]["bids"]:
         if bid.get('status', 'active') == 'active':
             participation_url = self.auction_url
             participation_url += '/login?bidder_id={}&hash={}'.format(
                 bid["id"], calculate_hash(bid["id"], self.hash_secret))
             patch_data['data']['bids'].append({
                 "participationUrl": participation_url,
                 "id": bid["id"]
             })
         else:
             patch_data['data']['bids'].append({"id": bid["id"]})
     LOGGER.info("Set auction and participation urls for tender {}".format(
         self.source_id),
                 extra={
                     "JOURNAL_REQUEST_ID": request_id,
                     "MESSAGE_ID": AUCTION_WORKER_SET_AUCTION_URLS
                 })
     LOGGER.info(repr(patch_data))
     make_request(self.api_url + '/auction',
                  patch_data,
                  user=self.api_token,
                  request_id=request_id,
                  session=self.session)
def prepare_users_data(tender_data):
    auction_worker_defaults = BuiltIn().get_variable_value(
        "${auction_worker_defaults}")
    with open(auction_worker_defaults) as auction_worker_defaults_file:
        auction_worker_defaults_info = yaml.load(auction_worker_defaults_file)
    users_data = {}
    for index, bid in enumerate(tender_data["bids"]):
        if "lots" in tender_data:
            lot_id_appendix = "_" + tender_data["lots"][0]["id"]
        else:
            lot_id_appendix = ""
        auction_id = "11111111111111111111111111111111"

        users_data[bid["id"]] = {
            'login_url':
            auction_worker_defaults_info['AUCTIONS_URL'].format(
                auction_id=auction_id) + lot_id_appendix +
            '/login?bidder_id={}&hash={}'.format(
                bid["id"],
                calculate_hash(bid["id"],
                               auction_worker_defaults_info["HASH_SECRET"])),
            'amount':
            bid['value']['amount'],
            'position':
            positions[index],
            'size':
            size
        }
    print('users_data: ', json.dumps(users_data))
    return users_data
def run_texas(tender_file_path):
    with open(tender_file_path) as _file:
        auction_json = json.load(_file).get('data', {})
        auction_id = uuid4().hex
        bids = auction_json.get('bids', [])
        if auction_id:
            check_output(TESTS['texas']['worker_cmd'].format(
                CWD, auction_id).split())

    for bid in bids:
        print 'texas-auctions/{}/login?bidder_id={}&hash={}'.format(
            auction_id, bid["id"], calculate_hash(bid["id"], HASH_SECRET))
    sleep(30)
    return auction_id
def prepare_users_data(tender_data):
    auction_worker_defaults = BuiltIn().get_variable_value("${auction_worker_defaults}")
    with open(auction_worker_defaults) as auction_worker_defaults_file:
        auction_worker_defaults_info = yaml.load(auction_worker_defaults_file)
    users_data = {}
    for index, bid in enumerate(tender_data["bids"]):
        users_data[bid["id"]] = {
            'login_url': auction_worker_defaults_info['AUCTIONS_URL'].format(auction_id="11111111111111111111111111111111") +  '/login?bidder_id={}&hash={}'.format(
                bid["id"], calculate_hash(bid["id"], auction_worker_defaults_info["HASH_SECRET"])
            ),
            'amount': bid['value']['amount'],
            'position': positions[index],
            'size': size
        }
    return users_data
def prepare_users_data(tender_data):
    auction_worker_defaults = BuiltIn().get_variable_value("${auction_worker_defaults}")
    with open(auction_worker_defaults) as auction_worker_defaults_file:
        auction_worker_defaults_info = json.load(auction_worker_defaults_file)
    users_data = {}
    for index, bid in enumerate(tender_data["bids"]):
        users_data[bid["id"]] = {
            'login_url': auction_worker_defaults_info['AUCTIONS_URL'].format(auction_id="11111111111111111111111111111111") +  '/login?bidder_id={}&hash={}'.format(
                bid["id"], calculate_hash(bid["id"], auction_worker_defaults_info["HASH_SECRET"])
            ),
            'amount': bid['value']['amount'],
            'position': positions[index],
            'size': size
        }
    return users_data
def prepare_auction_and_participation_urls(self):
    auction_url = self.worker_defaults['AUCTIONS_URL'].format(
        auction_id=self.auction_doc_id)
    patch_data = {
        'data': {
            'lots': list(self._auction_data['data']['lots']),
            'bids': list(self._auction_data['data']['bids'])
        }
    }
    for index, lot in enumerate(self._auction_data['data']['lots']):
        if lot['id'] == self.lot_id:
            patch_data['data']['lots'][index]['auctionUrl'] = auction_url
            break

    for bid_index, bid in enumerate(self._auction_data['data']['bids']):
        if bid.get('status', 'active') == 'active':
            for lot_index, lot_bid in enumerate(bid['lotValues']):
                if lot_bid['relatedLot'] == self.lot_id and lot_bid.get(
                        'status', 'active') == 'active':
                    participation_url = self.worker_defaults[
                        'AUCTIONS_URL'].format(auction_id=self.auction_doc_id)
                    participation_url += '/login?bidder_id={}&hash={}'.format(
                        bid['id'],
                        calculate_hash(bid['id'],
                                       self.worker_defaults['HASH_SECRET']))
                    patch_data['data']['bids'][bid_index]['lotValues'][
                        lot_index]['participationUrl'] = participation_url
                    break
    logger.info("Set auction and participation urls for tender {}".format(
        self.tender_id),
                extra={
                    "JOURNAL_REQUEST_ID": self.request_id,
                    "MESSAGE_ID": AUCTION_WORKER_SET_AUCTION_URLS
                })
    logger.info(repr(patch_data))
    make_request(self.tender_url + '/auction/{}'.format(self.lot_id),
                 patch_data,
                 user=self.worker_defaults["TENDERS_API_TOKEN"],
                 request_id=self.request_id,
                 session=self.session)
    return patch_data
def login():
    bidder_id = os.urandom(16).encode('hex')
    hash = calculate_hash(bidder_id, app.config['HASH_SECRET'])

    next_url = request.args.get('next') or request.referrer or None
    if 'X-Forwarded-Path' in request.headers:
        callback_url = urljoin(request.headers['X-Forwarded-Path'],
                               'authorized')
    else:
        callback_url = url_for('authorized', next=next_url, _external=True)
    response = app.remote_oauth.authorize(callback=callback_url,
                                          bidder_id=bidder_id,
                                          hash=hash)
    app.config['auction'].bidders_data.append({'id': bidder_id, 'date': ''})
    if 'return_url' in request.args:
        session['return_url'] = request.args['return_url']
    session['login_bidder_id'] = bidder_id
    session['login_hash'] = hash
    session['login_callback'] = callback_url
    app.logger.debug("Session: {}".format(repr(session)))
    return response