-
Notifications
You must be signed in to change notification settings - Fork 66
Expand file tree
/
Copy path__init__.py
More file actions
45 lines (38 loc) · 1.7 KB
/
__init__.py
File metadata and controls
45 lines (38 loc) · 1.7 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
import logging, json
import azure.durable_functions as df
import azure.functions as func
from ..Status.inmemorystatusmanager import InMemoryStatusManager
from ..Status.status import Status
from ..Auth import authorization
from ..Auth.knowngroups import SecurityGroups
"""
Update callback that can be customized to make any changes to the status
"""
def update_callback(status: Status):
return status
"""
Durable HTTP Start that kicks off orchestration for creating subscriptions
Returns:
Response that contains status URL's to monitor the orchestration
"""
@authorization.authorize([SecurityGroups.subscription_managers])
async def main(req: func.HttpRequest,starter:str) -> func.HttpResponse:
client = df.DurableOrchestrationClient(starter)
# Payload that contains how a subscription environment is created
payload: str = json.loads(req.get_body().decode())
client_name: str = req.route_params.get('clientName')
orchestrator_name: str = "SubscriptionLifecycleOrchestrator"
headers = {}
if client_name is None:
return func.HttpResponse(
"Must include clientName (in the body of the http)",
headers=headers, status_code=400)
else:
# Initialize a new status for this client in-memory
status_mgr = InMemoryStatusManager(client_name)
await status_mgr.safe_update_status(update_callback)
payload["customerName"] = client_name
payload["subscriptionId"] = None
instance_id = await client.start_new(orchestration_function_name=orchestrator_name,instance_id=None,client_input=payload)
logging.info(f"Started orchestration with ID = '{instance_id}'.")
return client.create_check_status_response(req,instance_id)