Ejemplo n.º 1
0
 def ding(self):
     timestamp = str(round(time.time() * 1000))
     secret_enc = self.secret.encode('utf-8')
     string_to_sign = f'{timestamp}\n{self.secret}'
     string_to_sign_enc = string_to_sign.encode('utf-8')
     hmac_code = hmac.new(secret_enc,
                          string_to_sign_enc,
                          digestmod=hashlib.sha256).digest()
     sign = urllib.parse.quote_plus(base64.b64encode(hmac_code))
     url = f'{self.hook}&timestamp={timestamp}&sign={sign}'
     data = {
         'msgtype': 'markdown',
         'markdown': {
             'title': 'V2EX 当前热门',
             'text': f'### V2EX 当前热门\n{"".join(self.contents)}'
         }
     }
     headers = {'Content-Type': 'application/json'}
     try:
         resp = requests.post(url=url,
                              headers=headers,
                              data=json.dumps(data),
                              timeout=Action.timeout,
                              verify=False)
         self.res = resp.json()['errcode'] == 0
     except Exception as e:
         core.set_failed(f'something error occurred, message: {e}')
Ejemplo n.º 2
0
 def wx(self):
     data = {
         'msgtype': 'markdown',
         'markdown': {
             'content': f'### V2EX 当前热门\n{"".join(self.contents)}'
         }
     }
     headers = {'Content-Type': 'application/json'}
     try:
         resp = requests.post(url=self.hook,
                              headers=headers,
                              data=json.dumps(data),
                              timeout=Action.timeout,
                              verify=False)
         self.res = resp.json()['errcode'] == 0
     except Exception as e:
         core.set_failed(f'something error occurred, message: {e}')
Ejemplo n.º 3
0
 def get_v2ex_hot_topics():
     url = 'https://v2ex.com/?tab=hot'
     headers = {'User-Agent': Action.ua.random}
     contents = []
     try:
         resp = requests.get(url=url,
                             headers=headers,
                             timeout=Action.timeout,
                             verify=False)
         match = re.compile(
             '<span class="item_hot_topic_title">(.*?)</span>', re.DOTALL)
         for item in match.findall(resp.text):
             detail_url = 'https://v2ex.com' + re.search(
                 '<a href="(.*?)">', item.strip()).group(1)
             title = re.search('">(.*?)</a>', item.strip()).group(1)
             content = f'> - [{title}]({detail_url})\n'
             contents.append(content)
         return contents
     except Exception as e:
         core.set_failed(f'something error occurred, message: {e}')
Ejemplo n.º 4
0
from actions_toolkit import core

from app.action import Action

if __name__ == '__main__':
    username = core.get_input('gitee-username')
    password = core.get_input('gitee-password')
    repo = core.get_input('gitee-repo')
    branch = core.get_input('branch', required=False)
    directory = core.get_input('directory', required=False)
    https = core.get_input('https', required=False)
    action = Action(username, password, repo, branch, directory, https)
    try:
        action.run()
        core.info('Rebuild Gitee Pages successfully.')
    except Exception as e:
        core.set_failed(str(e))
Ejemplo n.º 5
0
def set_failed(s: str = ''):
    core.set_failed(f'[{now()}] {s}')
Ejemplo n.º 6
0
def run_action():

    core.info('-= Keeper Commander GitHub Action =-')

    keeper_server = environ.get('KEEPER_SERVER')
    secret_config = environ.get('SECRET_CONFIG')
    secret_query = environ.get('SECRETS')
    verify_ssl_certs = environ.get('VERIFY_SSL_CERTS')
    unmask_secret = environ.get('UNMASK')

    if verify_ssl_certs:
        verify_ssl_certs = verify_ssl_certs.lower() in ['true', '1', 't', 'y', 'yes']
    else:
        verify_ssl_certs = True

    if not secret_config:
        core.set_failed("Commander configuration is empty")

    core.debug('Secret query:%s' % secret_query)

    # 1. Authenticate Commander
    c = Commander(config=InMemoryKeyValueStorage(secret_config), verify_ssl_certs=verify_ssl_certs)

    if keeper_server:
        core.info('Keeper server: %s' % keeper_server)
        c.server = keeper_server

    record_actions = RecordActionEntry.from_query_entries(secret_query)

    # Get only UIDs of the records from the query list
    uids = [r.uid for r in record_actions]

    # Retrieving only secrets that were asked in the action
    retrieved_secrets = c.get_secrets(uids)

    core.debug("Begin retrieving secrets from Keeper...")
    core.info("Retrieved %s secrets." % len(retrieved_secrets))

    core.debug("Secrets to retrieve: %s" % len(record_actions))

    count = 0
    outputs_map = {}
    env_map = {}

    for record_action in record_actions:

        count += 1

        core.info("Retrieving secret %s: uid=%s" % (str(count), record_action.uid))

        record = find_record(retrieved_secrets, record_action.uid)

        if not record:
            core.warning("Record uid=%s not found. Make sure you have this record added to the application you are "
                         "using." % record_action.uid)
        else:
            core.info("Secret uid=%s, source field type=[%s], source field value=[%s], dest=%s" % (
                record.uid,
                record_action.field_type,
                record_action.field_value,
                record_action.destination_type))

            if record_action.destination_type == DestinationKey.ENV:

                if record_action.field_value == 'title':
                    secret_value = record.title
                elif record_action.field_type == 'field':
                    secret_value = record.field(record_action.field_value)[0]
                elif record_action.field_type == 'custom':
                    secret_value = record.custom_field(record_action.field_value)[0]
                else:
                    raise Exception("Currently supporting only fields and custom fields in the record")

                env_map[record_action.destination_val] = secret_value

                if unmask_secret == 'true':
                    core.warning("Secret with destination '%s' will be unmasked" % record_action.destination_val)
                else:
                    core.set_secret(secret_value)   # hiding any values, even title

            elif record_action.destination_type == DestinationKey.OUT:
                outputs_map[record_action.destination_val] = record.password
            elif record_action.destination_type == DestinationKey.FILE:
                __save_to_file(record, record_action)
            else:
                raise Exception("Unknown destination type specified: %s" % record_action.destination_type)

    if outputs_map:
        outputs_json = json.dumps(outputs_map)
        core.debug('out-secrets = %s' % outputs_json)
        core.set_output('out-secrets', outputs_json)

    write_to_env(env_map)

    core.info("Finish retrieving secrets from Keeper Security")