forked from crossplane-contrib/function-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
51 lines (45 loc) · 1.24 KB
/
Copy pathmain.py
File metadata and controls
51 lines (45 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
"""The composition function's main CLI."""
import click
from crossplane.function import logging, runtime
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.
"""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}")
if __name__ == "__main__":
cli()