forward.py 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. import argparse
  10. from materialize.cli.scratch import check_required_vars
  11. from materialize.scratch import get_instance, mssh
  12. def configure_parser(parser: argparse.ArgumentParser) -> None:
  13. check_required_vars()
  14. parser.add_argument(
  15. "instance",
  16. help="The ID of the instance to connect to, or 'mine' to specify your only live instance",
  17. )
  18. parser.add_argument("ports", nargs="*", help="The remote ports to forward locally")
  19. def run(args: argparse.Namespace) -> None:
  20. instance = get_instance(args.instance)
  21. ssh_args = []
  22. for port in args.ports:
  23. ssh_args.extend(["-L", f"{port}:127.0.0.1:{port}"])
  24. mssh(instance, "sleep infinity", extra_ssh_args=ssh_args)