Пример #1
0
def password(container: Tuple[str, str], old_password: str,
             new_password: str) -> None:
    docker = Docker()
    user = Application.env.get("RABBITMQ_USER")
    docker.exec_command(
        container,
        user=services.get_default_user(SERVICE_NAME),
        command=f'rabbitmqctl change_password "{user}" "{new_password}"',
    )
Пример #2
0
def password(container: Tuple[str, str], old_password: str,
             new_password: str) -> None:
    docker = Docker()

    docker.exec_command(
        container,
        user=services.get_default_user(SERVICE_NAME),
        command=f"""bin/cypher-shell \"
            ALTER CURRENT USER
            SET PASSWORD
            FROM '{old_password}'
            TO '{new_password}';
        \"""",
    )
Пример #3
0
def password(container: Tuple[str, str], old_password: str, new_password: str) -> None:

    docker = Docker()
    # restapi init need the env variable to be updated but can't be done after
    # the restart because it often fails because unable to re-connect to
    # services in a short time and some long sleep would be needed
    # => applied a workaround to be able to execute it before the restart
    docker = Docker()
    docker.exec_command(
        container,
        user=services.get_default_user(SERVICE_NAME),
        command=f"""/bin/bash -c '
            AUTH_DEFAULT_PASSWORD=\"{new_password}\"
                restapi init --force-user
            '
            """,
    )
Пример #4
0
def password(container: Tuple[str, str], old_password: str,
             new_password: str) -> None:
    # https://dev.mysql.com/doc/refman/8.0/en/set-password.html

    docker = Docker()

    user = Application.env.get("ALCHEMY_USER")
    pwd = Application.env.get("MYSQL_ROOT_PASSWORD")
    db = Application.env.get("ALCHEMY_DB")

    docker.exec_command(
        container,
        user=services.get_default_user(SERVICE_NAME),
        command=f"""
            mysql -uroot -p\"{pwd}\" -D\"{db}\" -e
                "ALTER USER '{user}'@'%' IDENTIFIED BY '{new_password}';"
            """,
    )
Пример #5
0
def password(container: Tuple[str, str], old_password: str,
             new_password: str) -> None:

    docker = Docker()
    # Interactively:
    # \password username
    # Non interactively:
    # https://ubiq.co/database-blog/how-to-change-user-password-in-postgresql
    user = Application.env.get("ALCHEMY_USER")
    db = Application.env.get("ALCHEMY_DB")
    docker.exec_command(
        container,
        user=services.get_default_user(SERVICE_NAME),
        command=f"""
            psql -U {user} -d {db} -c \"
                ALTER USER {user} WITH PASSWORD \'{new_password}\';
            \"
        """,
    )
Пример #6
0
def test_get_default_user() -> None:
    assert services.get_default_user("invalid") is None
    assert services.get_default_user("backend") == "developer"
    assert services.get_default_user("celery") == "developer"
    assert services.get_default_user("flower") == "developer"
    assert services.get_default_user("celerybeat") == "developer"
    Configuration.frontend = "invalid"
    assert services.get_default_user("frontend") is None
    Configuration.frontend = "no"
    assert services.get_default_user("frontend") is None
    Configuration.frontend = "angular"
    assert services.get_default_user("frontend") == "node"
    Configuration.frontend = "angularjs"
    assert services.get_default_user("frontend") is None
    assert services.get_default_user("postgres") == "postgres"
    assert services.get_default_user("neo4j") == "neo4j"
    assert services.get_default_user("redis") == "redis"
Пример #7
0
def shell(
    service: str = typer.Argument(
        ...,
        help="Service name",
        shell_complete=Application.autocomplete_service),
    command: str = typer.Argument(
        "bash",
        help="UNIX command to be executed on selected running service"),
    user: Optional[str] = typer.Option(
        None,
        "--user",
        "-u",
        help="User existing in selected service",
        show_default=False,
    ),
    default_command: bool = typer.Option(
        False,
        "--default-command",
        "--default",
        help="Execute the default command configured for the container",
        show_default=False,
    ),
    no_tty: bool = typer.Option(
        False,
        "--no-tty",
        help=
        "Disable pseudo-tty allocation (useful for non-interactive script)",
        show_default=False,
    ),
    replica: int = typer.Option(
        1,
        "--replica",
        "--slot",
        help="Execute the command on the specified replica",
        show_default=False,
    ),
    broadcast: bool = typer.Option(
        False,
        "--broadcast",
        help="Execute the command on all the replicas",
        show_default=False,
    ),
) -> None:

    Application.print_command(
        Application.serialize_parameter("--user", user, IF=user),
        Application.serialize_parameter("--default",
                                        default_command,
                                        IF=default_command),
        Application.serialize_parameter("", service),
        Application.serialize_parameter("", command),
    )

    if no_tty:
        log.warning("--no-tty option is deprecated, you can stop using it")

    if replica > 1 and broadcast:
        print_and_exit("--replica and --broadcast options are not compatible")
    Application.get_controller().controller_init()

    docker = Docker()

    if not user:
        user = services.get_default_user(service)

    if default_command:
        command = services.get_default_command(service)

    log.debug("Requested command: {} with user: {}", command, user
              or "default")
    if broadcast:
        containers = docker.get_containers(service)
        if not containers:
            print_and_exit("No running container found for {} service",
                           service)

        docker.exec_command(containers, user=user, command=command)
    else:
        container = docker.get_container(service, slot=replica)

        if not container:
            if replica != 1:
                print_and_exit("Replica number {} not found for {} service",
                               str(replica), service)
            print_and_exit("No running container found for {} service",
                           service)

        docker.exec_command(container, user=user, command=command)