Esempio n. 1
0
    def install(self, challenge=None, force=False):
        if challenge is None:
            challenge = os.getcwd()

        path = Path(challenge)

        if path.name.endswith(".yml") is False:
            path = path / "challenge.yml"

        click.secho(f"Found {path}")
        challenge = load_challenge(path)
        click.secho(f'Loaded {challenge["name"]}', fg="yellow")

        installed_challenges = load_installed_challenges()
        for c in installed_challenges:
            if c["name"] == challenge["name"]:
                click.secho(
                    "Already found existing challenge with same name. Perhaps you meant sync instead of install?",
                    fg="red",
                )
                if force is True:
                    click.secho(
                        "Ignoring existing challenge because of --force",
                        fg="yellow")
                else:
                    return

        click.secho(f'Installing {challenge["name"]}', fg="yellow")
        create_challenge(challenge=challenge)
        click.secho(f"Success!", fg="green")
Esempio n. 2
0
    def sync(self, challenge=None):
        if challenge is None:
            challenge = os.getcwd()

        path = Path(challenge)

        if path.name.endswith(".yml") is False:
            path = path / "challenge.yml"

        click.secho(f"Found {path}")
        challenge = load_challenge(path)
        click.secho(f'Loaded {challenge["name"]}', fg="yellow")

        installed_challenges = load_installed_challenges()
        for c in installed_challenges:
            if c["name"] == challenge["name"]:
                break
        else:
            click.secho(
                "Couldn't find existing challenge. Perhaps you meant install instead of sync?",
                fg="red",
            )

        click.secho(f'Syncing {challenge["name"]}', fg="yellow")
        sync_challenge(challenge=challenge)
        click.secho(f"Success!", fg="green")
Esempio n. 3
0
    def sync(self, challenge=None, ignore=()):
        if challenge is None:
            # Get all challenges if not specifying a challenge
            config = load_config()
            challenges = dict(config["challenges"]).keys()
        else:
            challenges = [challenge]

        if isinstance(ignore, str):
            ignore = (ignore,)

        for challenge in challenges:
            path = Path(challenge)

            if path.name.endswith(".yml") is False:
                path = path / "challenge.yml"

            click.secho(f"Found {path}")
            challenge = load_challenge(path)
            click.secho(f'Loaded {challenge["name"]}', fg="yellow")

            installed_challenges = load_installed_challenges()
            for c in installed_challenges:
                if c["name"] == challenge["name"]:
                    break
            else:
                click.secho(
                    f'Couldn\'t find existing challenge {c["name"]}. Perhaps you meant install instead of sync?',
                    fg="red",
                )
                continue  # Go to the next challenge in the overall list

            click.secho(f'Syncing {challenge["name"]}', fg="yellow")
            sync_challenge(challenge=challenge, ignore=ignore)
            click.secho(f"Success!", fg="green")
Esempio n. 4
0
    def deploy(self, challenge, host=None):
        if challenge is None:
            challenge = os.getcwd()

        path = Path(challenge)

        if path.name.endswith(".yml") is False:
            path = path / "challenge.yml"

        challenge = load_challenge(path)
        image = challenge.get("image")
        target_host = host or challenge.get("host") or input("Target host URI: ")
        if image is None:
            click.secho(
                "This challenge can't be deployed because it doesn't have an associated image",
                fg="red",
            )
            return
        if bool(target_host) is False:
            click.secho(
                "This challenge can't be deployed because there is no target host to deploy to",
                fg="red",
            )
            return
        url = urlparse(target_host)

        if bool(url.netloc) is False:
            click.secho(
                "Provided host has no URI scheme. Provide a URI scheme like ssh:// or registry://",
                fg="red",
            )
            return

        status, domain, port = DEPLOY_HANDLERS[url.scheme](
            challenge=challenge, host=target_host
        )

        if status:
            click.secho(
                f"Challenge deployed at {domain}:{port}", fg="green",
            )
        else:
            click.secho(
                f"An error occured during deployment", fg="red",
            )
Esempio n. 5
0
    def install(self, challenge=None, force=False, ignore=()):
        if challenge is None:
            # Get all challenges if not specifying a challenge
            config = load_config()
            challenges = dict(config["challenges"]).keys()
        else:
            challenges = [challenge]

        if isinstance(ignore, str):
            ignore = (ignore,)

        for challenge in challenges:
            path = Path(challenge)

            if path.name.endswith(".yml") is False:
                path = path / "challenge.yml"

            click.secho(f"Found {path}")
            challenge = load_challenge(path)
            click.secho(f'Loaded {challenge["name"]}', fg="yellow")

            installed_challenges = load_installed_challenges()
            for c in installed_challenges:
                if c["name"] == challenge["name"]:
                    click.secho(
                        f'Already found existing challenge with same name ({challenge["name"]}). Perhaps you meant sync instead of install?',
                        fg="red",
                    )
                    if force is True:
                        click.secho(
                            "Ignoring existing challenge because of --force",
                            fg="yellow",
                        )
                    else:
                        break
            else:  # If we don't break because of duplicated challenge names
                click.secho(f'Installing {challenge["name"]}', fg="yellow")
                create_challenge(challenge=challenge, ignore=ignore)
                click.secho(f"Success!", fg="green")