Ejemplo n.º 1
0
def get_ssh_key_or_prompt(ssh_key, username, password, secrets_configuration):
    ssh_key = get_ssh_key.get_user_public_key(ssh_key, secrets_configuration)

    if username is not None and password is None and ssh_key is None:
        log.warning(
            "It is recommended to use an SSH key for user creation instead of a password."
        )
        for i in range(3):
            if i > 0:
                log.error("Please try again.")
            password = getpass.getpass(
                "Please input a password for user '{0}': ".format(username))
            confirm_password = getpass.getpass(
                "Please confirm your password for user '{0}': ".format(
                    username))
            if password != confirm_password:
                log.error("Password confirmation did not match.")
            elif not password:
                log.error("Password cannot be empty.")
            else:
                break
        else:
            raise error.AztkError(
                "Failed to get valid password, cannot add user to cluster. It is recommended that you provide a ssh public key in .aztk/secrets.yaml. Or provide an ssh-key or password with command line parameters (--ssh-key or --password). You may also run the 'aztk spark cluster add-user' command to add a user to this cluster."
            )
    return ssh_key, password
Ejemplo n.º 2
0
def __create_user(self,
                  id: str,
                  node_id: str,
                  username: str,
                  password: str = None,
                  ssh_key: str = None) -> str:
    """
        Create a pool user
        :param pool: the pool to add the user to
        :param node: the node to add the user to
        :param username: username of the user to add
        :param password: password of the user to add
        :param ssh_key: ssh_key of the user to add
    """
    # Create new ssh user for the given node
    self.batch_client.compute_node.add_user(
        id,
        node_id,
        batch_models.ComputeNodeUser(
            name=username,
            is_admin=True,
            password=password,
            ssh_public_key=get_ssh_key.get_user_public_key(
                ssh_key, self.secrets_configuration),
            expiry_time=datetime.now(timezone.utc) + timedelta(days=365),
        ),
    )