Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 4 additions & 38 deletions function/main.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
"""The composition function's main CLI."""

import click
from crossplane.function import logging, runtime
from crossplane.function import cli as sdkcli

from function import fn


@click.command()
@click.option(
"--debug",
"-d",
is_flag=True,
help="Emit debug logs.",
)
@click.option(
"--address",
default="0.0.0.0:9443",
show_default=True,
help="Address at which to listen for gRPC connections",
)
@click.option(
"--tls-certs-dir",
help="Serve using mTLS certificates.",
envvar="TLS_SERVER_CERTS_DIR",
)
@click.option(
"--insecure",
is_flag=True,
help="Run without mTLS credentials. "
"If you supply this flag --tls-certs-dir will be ignored.",
)
def cli(debug: bool, address: str, tls_certs_dir: str, insecure: bool) -> None: # noqa:FBT001 # We only expect callers via the CLI.
@sdkcli.standard_options
def cli(**kwargs):
"""A Crossplane composition function."""
try:
level = logging.Level.INFO
if debug:
level = logging.Level.DEBUG
logging.configure(level=level)
runtime.serve(
fn.FunctionRunner(),
address,
creds=runtime.load_credentials(tls_certs_dir),
insecure=insecure,
)
except Exception as e:
click.echo(f"Cannot run function: {e}")
sdkcli.run(fn.FunctionRunner(), **kwargs)


if __name__ == "__main__":
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ classifiers = [
]

dependencies = [
"crossplane-function-sdk-python==0.14.0",
"crossplane-function-sdk-python==0.15.0",
"click==8.5.0",
"grpcio>=1.73.1",
]
Expand Down