Esempio n. 1
0
def main():
    requests.get('https://httpbin.org/get?code=0')
    username = core.get_input('username')
    res = f"Hello {username}"
    core.info("test")
    core.set_command_echo(True)
    core.set_output('res', res)
    tz = timezone(timedelta(hours=+8))
    time = datetime.now(tz).strftime('%Y-%m-%d %H:%M:%S')
    print(f"::set-output name=time::{time}")
    context = Context()
    print(context)
    print(context.payload)
def __save_to_file(record, rae):
    file_name = rae.field_value                  # ex. 'config.json'

    core.info("Processing file %s" % file_name)
    core.debug("Number of files in secret: %s" % len(record.files))
    file_found = None
    for f in record.files:
        core.debug("Checking file name: \"%s\", file title: \"%s\"" % (f.name, f.title))
        if f.name == file_name or f.title == file_name:
            core.info("Found file '%s'" % file_name)
            if file_found:
                core.warning(
                    "More than two files named %s in record uid=%s. Make sure to have unique names for files." % (
                    file_name, record.uid))
                # TODO Is there a way to get files by their UID? or some other unique identifier?

            file_found = f

    if not file_found:
        core.warning("No files found named \"%s\"" % file_name)
        # core.end_group()
        return

    core.info("Located file %s" % file_name)

    is_file_destination = rae.destination_type == DestinationKey.FILE

    if is_file_destination:
        core.info("File destination: %s" % rae.destination_val)

        file_found.save_file(rae.destination_val, True)
        core.debug("File saved to %s" % rae.destination_val)
    else:
        core.error("Only file destination is currently supported. Ex. file:/path/to/file.json")
Esempio n. 3
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))
Esempio n. 4
0
def error(s: str = ''):
    core.info(f'[{now()}] {s}')
Esempio n. 5
0
def info(s: str = ''):
    core.info(f'[{now()}] {s}')
Esempio n. 6
0
from actions_toolkit import core

from app.action import Action

if __name__ == '__main__':
    input_hook = core.get_input('webhook')
    input_secret = core.get_input('secret', required=False)
    count_str = core.get_input('count')
    input_count = int(count_str) if count_str else 8
    action = Action(input_hook, input_secret, input_count)
    try:
        action.run()
        core.info('V2EX Action Run Successfully.')
    except Exception as e:
        core.set_failed(str(e))
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")
Esempio n. 8
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))
Esempio n. 9
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('Success, thanks for using @yanglbme/gitee-pages-action!')
    except Exception as e:
        core.set_failed(str(e))