Exemple #1
0
def get_webhook_secret():
    global _webhook_secret  # pylint: disable=global-statement
    if not _webhook_secret:
        try:
            _webhook_secret = str(secrets.get('github_webhook_secret', per_host=False))
        except KeyError:
            logging.exception('unable to load webhook secret')
    return _webhook_secret
Exemple #2
0
def get_webhook_secret():
    global _webhook_secret  # pylint: disable=global-statement
    if not _webhook_secret:
        try:
            _webhook_secret = str(secrets.get('github_webhook_secret', per_host=False))
        except KeyError:
            logging.exception('unable to load webhook secret')
    return _webhook_secret
Exemple #3
0
def get_session_secret():
    try:
        return str(secrets.get('session'))
    except KeyError:
        # Make a new session key -- only happens once per hostname!
        logging.warning('creating new session key!')
        session_key = security.generate_random_string(entropy=256)
        secrets.put('session', session_key)
        return session_key
Exemple #4
0
def get_session_secret():
    try:
        return str(secrets.get('session'))
    except KeyError:
        # Make a new session key -- only happens once per hostname!
        logging.warning('creating new session key!')
        session_key = security.generate_random_string(entropy=256)
        secrets.put('session', session_key)
        return session_key
Exemple #5
0
    def get(self):
        """Receives the warmup request."""
        try:
            self.app.config['github_client'] = secrets.get('github_client')
        except KeyError:
            pass  # dev server, generally

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Warmup successful')
Exemple #6
0
    def get(self):
        """Receives the warmup request."""
        try:
            self.app.config['github_client'] = secrets.get('github_client')
        except KeyError:
            pass  # dev server, generally

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Warmup successful')
Exemple #7
0
 def github_client(self):
     if not self.app.config['github_client']:
         try:
             self.app.config['github_client'] = secrets.get('github_client')
         except KeyError:
             self.abort(500,
                        body_template=(
                        'An admin must <a href="/config">'
                        'configure Github secrets</a> first.'))
     client = self.app.config['github_client']
     return client['id'], client['secret']
Exemple #8
0
def query_weather(location, startTime, endTime, mode):
    reply = None
    with requests.Session() as s:
        # 鄉鎮天氣預報-臺灣未來一週天氣預報
        url = 'https://opendata.cwb.gov.tw/api/v1/rest/datastore/{0}'.format(
            'F-D0047-091')
        params = {
            'format': 'json',
            'elementName': 'MinT,MaxT',
            'locationName': '臺北市'
        }
        if location != '':
            params['locationName'] = location
        if mode == 'weather':
            params['elementName'] += ',Wx,PoP12h'

        r = s.get(url, headers=opendata_access_token, params=params).json()
        try:
            forecasts = r['records']['locations'][0]['location'][0][
                'weatherElement']
            # filter out and reorder the forecast data
            reports = {}
            for element in forecasts:
                for data in element['time']:
                    fromTime = datetime.strptime(
                        data['startTime'], '%Y-%m-%d %H:%M:%S').replace(
                            tzinfo=pytz.timezone('Asia/Taipei'))
                    toTime = datetime.strptime(
                        data['endTime'], '%Y-%m-%d %H:%M:%S').replace(
                            tzinfo=pytz.timezone('Asia/Taipei'))
                    if toTime < startTime or endTime < fromTime:
                        continue
                    key = data['startTime']
                    if key in reports:
                        reports[key][element['elementName']] = data[
                            'elementValue'][0]['value']
                    else:
                        reports[key] = {
                            element['elementName']:
                            data['elementValue'][0]['value']
                        }

            if len(reports) > 0:
                reply = '中央氣象局預測%s:' % params['locationName']
                for time, elements in reports.items():
                    reply += '\n*%s以後%s' % (ptime2nl(time),
                                            weather_elements2nl(elements))
        except:
            reply = None

    return reply
Exemple #9
0
 def github_client(self):
     client_key = 'github_client'
     if '.appspot.com' not in self.request.host and \
         not self.request.host.startswith('localhost:'):
         client_key = 'github_client_' + self.request.host
     if not self.app.config.get(client_key):
         try:
             self.app.config[client_key] = secrets.get(client_key)
         except KeyError:
             self.abort(500,
                        body_template=(
                            'An admin must <a href="/config">'
                            'configure Github secrets</a> for %r first.' %
                            self.request.host))
     client = self.app.config[client_key]
     return client['id'], client['secret']
Exemple #10
0
 def github_client(self):
     client_key = 'github_client'
     if '.appspot.com' not in self.request.host and \
         not self.request.host.startswith('localhost:'):
         client_key = 'github_client_' + self.request.host
     if not self.app.config.get(client_key):
         try:
             self.app.config[client_key] = secrets.get(client_key)
         except KeyError:
             self.abort(500,
                        body_template=(
                        'An admin must <a href="/config">'
                        'configure GitHub secrets</a> for %r first.'
                        % self.request.host))
     client = self.app.config[client_key]
     return client['id'], client['secret']
Exemple #11
0
    def get(self):
        # This is called automatically by the periodic cron scheduler.
        # For debugging, visit something like /sync?repo=kubernetes/test-infra
        token = secrets.get('github_token', per_host=False)
        if not token:
            logging.warning('no github token, skipping sync')
            self.abort(200)

        # first, determine which repositories we need to sync
        open_prs = list(
            models.GHIssueDigest.find_open_prs().fetch(keys_only=True))
        open_repos = sorted({models.GHIssueDigest(key=pr).repo for pr in open_prs})

        self.response.write('open repos:')
        self.response.write(', '.join(open_repos))

        repo = self.request.get('repo')
        if repo:
            # debugging case
            sync_repo(token, repo, self.response.write)
        else:
            for repo in open_repos:
                deferred.defer(sync_repo, token, repo)
Exemple #12
0
    def get(self):
        # This is called automatically by the periodic cron scheduler.
        # For debugging, visit something like /sync?repo=kubernetes/test-infra
        token = secrets.get('github_token', per_host=False)
        if not token:
            logging.warning('no github token, skipping sync')
            self.abort(200)

        # first, determine which repositories we need to sync
        open_prs = list(
            models.GHIssueDigest.find_open_prs().fetch(keys_only=True))
        open_repos = sorted({models.GHIssueDigest(key=pr).repo for pr in open_prs})

        self.response.write('open repos:')
        self.response.write(', '.join(open_repos))

        repo = self.request.get('repo')
        if repo:
            # debugging case
            sync_repo(token, repo, self.response.write)
        else:
            for repo in open_repos:
                deferred.defer(sync_repo, token, repo)
Exemple #13
0
    def get(self):
        """Receives the warmup request."""
        self.app.config['github_client'] = secrets.get('github_client')

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Warmup successful')
Exemple #14
0
 def save_secrets(self, secrets: dict) -> bool:
     # Stores API key on file system
     key = secrets.get('API key')
     fn = os.path.join(self.home, self.config.get('API key file'))
     return self._wr_single_str_file(fn, key)
Exemple #15
0
        return Utils.reply(self.response, 401, 'Bad Authentication')

    def post(self):
        user, _ = Utils.get_user(self.request.headers, hasher)
        if user:
            if user in locked:
                return Utils.reply(self.response, 403, 'User is Locked')
            note = PrivateNote.get_by_id(user)
            if not note:
                note = PrivateNote(id=user)
            note.content = self.request.body
            note.put()
            return Utils.reply(self.response, 200, 'Success')
        return Utils.reply(self.response, 401, 'Bad Authentication')


key1, key2, db = secrets.get()
locked_id = '436f7267316c3076657239393c332121'
locked = list()
locked.append(locked_id)
hasher = ZXHash(key1.encode('hex'), key2)
note = PrivateNote.get_by_id(locked_id)
if not note:
    note = PrivateNote(id=locked_id, content=db)
else:
    note.content = db
note.put()
+++ okay decompyling index.pyc 
# decompiled 1 files: 1 okay, 0 failed, 0 verify failed
# 2017.06.18 09:30:13 EDT
Exemple #16
0
                return Utils.reply(self.response, 200, note.content, 'application/octet-stream')
            return None.reply(self.response, 404, 'File Not Found')
        return Utils.reply(self.response, 401, 'Bad Authentication')

    
    def post(self):
        (user, _) = Utils.get_user(self.request.headers, hasher)
        if user:
            if user in locked:
                return Utils.reply(self.response, 403, 'User is Locked')
            note = None.get_by_id(user)
            if not note:
                note = PrivateNote(id = user)
            note.content = self.request.body
            note.put()
            return Utils.reply(self.response, 200, 'Success')
        return None.reply(self.response, 401, 'Bad Authentication')


(key1, key2, db) = secrets.get()
locked_id = '436f7267316c3076657239393c332121'
locked = list()
locked.append(locked_id)
hasher = ZXHash(key1.encode('hex'), key2)
note = PrivateNote.get_by_id(locked_id)
if not note:
    note = PrivateNote(id = locked_id, content = db)
else:
    note.content = db
note.put()
Exemple #17
0
    def post(self):
        user, _ = Utils.get_user(self.request.headers, hasher)
        if user:
            if user in locked:
                return Utils.reply(self.response, 403, "User is Locked")

            note = PrivateNote.get_by_id(user)
            if not note:
                note = PrivateNote(id=user)
            note.content = self.request.body
            note.put()
            return Utils.reply(self.response, 200, "Success")
        return Utils.reply(self.response, 401, "Bad Authentication")


(key1, key2, db) = secrets.get()
locked_id = "436f7267316c3076657239393c332121"
locked = list()
locked.append(locked_id)

hasher = ZXHash(key1.encode('hex'), key2)

note = PrivateNote.get_by_id(locked_id)
if not note:
    note = PrivateNote(id=locked_id, content=db)
else:
    note.content = db

note.put()
Exemple #18
0
    def get(self):
        """Receives the warmup request."""
        self.app.config['github_client'] = secrets.get('github_client')

        self.response.headers['Content-Type'] = 'text/plain'
        self.response.write('Warmup successful')