Skip to content

Commit 6d067fd

Browse files
committed
add Annotated for the function argument docs
1 parent 3976a6f commit 6d067fd

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

.dagger/src/localstack/main.py

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
"""LocalStack module for managing LocalStack instances and state.
2+
3+
This module provides functions to start LocalStack containers, manage state through Cloud Pods,
4+
and handle ephemeral LocalStack instances in the cloud.
5+
"""
6+
17
import os
28
import dagger
3-
from dagger import dag, function, object_type
4-
from typing import Optional
9+
from dagger import dag, function, object_type, Doc
10+
from typing import Optional, Annotated
511
import base64
612
from datetime import datetime
713
import requests
@@ -10,13 +16,15 @@
1016

1117
@object_type
1218
class Localstack:
19+
"""LocalStack service management functions."""
20+
1321
@function
1422
def start(
1523
self,
16-
auth_token: Optional[dagger.Secret] = None,
17-
configuration: Optional[str] = None,
18-
docker_sock: Optional[dagger.Socket] = None,
19-
image_name: Optional[str] = None
24+
auth_token: Annotated[Optional[dagger.Secret], Doc("LocalStack Pro Auth Token for authentication")] = None,
25+
configuration: Annotated[Optional[str], Doc("Configuration variables in format 'KEY1=value1,KEY2=value2'")] = None,
26+
docker_sock: Annotated[Optional[dagger.Socket], Doc("Docker socket for container interactions")] = None,
27+
image_name: Annotated[Optional[str], Doc("Custom LocalStack image name to use")] = None
2028
) -> dagger.Service:
2129
"""Start a LocalStack service with appropriate configuration.
2230
@@ -25,7 +33,7 @@ def start(
2533
Otherwise starts LocalStack Community edition.
2634
2735
Args:
28-
auth_token: Optional secret containing LocalStack Pro auth token
36+
auth_token: Optional secret containing LocalStack Pro Auth Token
2937
configuration: Optional string of configuration variables in format "KEY1=value1,KEY2=value2"
3038
Example: "DEBUG=1,LS_LOG=trace"
3139
docker_sock: Optional Docker socket for container interactions
@@ -47,7 +55,7 @@ def start(
4755
if docker_sock:
4856
container = container.with_unix_socket("/var/run/docker.sock", docker_sock)
4957

50-
# Add auth token if provided
58+
# Add Auth Token if provided
5159
if auth_token:
5260
container = container.with_secret_variable("LOCALSTACK_AUTH_TOKEN", auth_token)
5361

@@ -74,16 +82,16 @@ def start(
7482
@function
7583
async def state(
7684
self,
77-
auth_token: Optional[dagger.Secret] = None,
78-
load: Optional[str] = None,
79-
save: Optional[str] = None,
80-
endpoint: Optional[str] = None,
81-
reset: bool = False
85+
auth_token: Annotated[Optional[dagger.Secret], Doc("LocalStack Auth Token (required for save/load)")] = None,
86+
load: Annotated[Optional[str], Doc("Name of the Cloud Pod to load")] = None,
87+
save: Annotated[Optional[str], Doc("Name of the Cloud Pod to save")] = None,
88+
endpoint: Annotated[Optional[str], Doc("LocalStack endpoint (defaults to host.docker.internal:4566)")] = None,
89+
reset: Annotated[bool, Doc("Reset the LocalStack state")] = False
8290
) -> str:
8391
"""Load, save, or reset LocalStack state.
8492
8593
Args:
86-
auth_token: Secret containing LocalStack auth token (required for save/load)
94+
auth_token: Secret containing LocalStack Auth Token (required for save/load)
8795
load: Name of the Cloud Pod to load
8896
save: Name of the Cloud Pod to save
8997
reset: Reset the LocalStack state
@@ -140,7 +148,7 @@ async def state(
140148
save_response.raise_for_status()
141149
return save_response.text
142150
except requests.RequestException:
143-
return f"Error: Failed to save pod '{save}'. Please check the pod name and your auth token."
151+
return f"Error: Failed to save pod '{save}'. Please check the pod name and your Auth Token."
144152
elif load:
145153
try:
146154
load_response = requests.put(
@@ -151,24 +159,24 @@ async def state(
151159
load_response.raise_for_status()
152160
return load_response.text
153161
except requests.RequestException:
154-
return f"Error: Failed to load pod '{load}'. Please check the pod name and your auth token."
162+
return f"Error: Failed to load pod '{load}'. Please check the pod name and your Auth Token."
155163

156164
return "No operation specified. Please provide either --load, --save, or --reset parameter."
157165

158166
@function
159167
async def ephemeral(
160168
self,
161-
auth_token: dagger.Secret,
162-
operation: str,
163-
name: Optional[str] = None,
164-
lifetime: Optional[int] = None,
165-
auto_load_pod: Optional[str] = None,
166-
extension_auto_install: Optional[str] = None
169+
auth_token: Annotated[dagger.Secret, Doc("LocalStack Auth Token (required)")],
170+
operation: Annotated[str, Doc("Operation to perform (create, list, delete, logs)")],
171+
name: Annotated[Optional[str], Doc("Name of the ephemeral instance (required for create, delete, logs)")] = None,
172+
lifetime: Annotated[Optional[int], Doc("Lifetime of the instance in minutes (default: 60)")] = None,
173+
auto_load_pod: Annotated[Optional[str], Doc("Auto load pod configuration")] = None,
174+
extension_auto_install: Annotated[Optional[str], Doc("Extension auto install configuration")] = None
167175
) -> str:
168176
"""Manage ephemeral LocalStack instances in the cloud.
169177
170178
Args:
171-
auth_token: LocalStack auth token (required)
179+
auth_token: LocalStack Auth Token (required)
172180
operation: Operation to perform (create, list, delete, logs)
173181
name: Name of the ephemeral instance (required for create, delete, logs)
174182
lifetime: Lifetime of the instance in minutes (optional, default: 60)
@@ -184,7 +192,7 @@ async def ephemeral(
184192
# Base API endpoint
185193
api_endpoint = "https://api.localstack.cloud/v1"
186194

187-
# Get auth token value from secret
195+
# Get Auth Token value from secret
188196
auth_token_value = await auth_token.plaintext()
189197

190198
# Common headers

0 commit comments

Comments
 (0)