You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Ensure an API token exists for the account, creating and persisting one if necessary.
77
+
78
+
If an API token is not already available, creates a new token and stores it in the context resource "accounts.api_token" and updates "accounts.api_token.id".
79
+
80
+
Returns:
81
+
ApiToken: The existing or newly created API token instance.
Retrieve the buyer identified by "accounts.buyer.id" from the context or fetch it from the API and cache it.
24
+
25
+
If the context does not contain "accounts.buyer.id", returns `None`. If the id exists but no valid Buyer instance is cached, fetches the buyer from the API, stores it in the context under "accounts.buyer", updates "accounts.buyer.id" with the fetched buyer's id, and returns the Buyer.
26
+
27
+
Returns:
28
+
Buyer or `None` if "accounts.buyer.id" is not set in the context.
"""Get licensee from context or fetch from API."""
22
+
"""
23
+
Retrieve the current licensee from the context or fetch it from the MPT API and cache it in the context.
24
+
25
+
If a licensee is not present in the context but a licensee id exists, the function fetches the licensee from the MPT API, stores the licensee as the context resource "accounts.licensee", and updates "accounts.licensee.id" in the context.
26
+
27
+
Returns:
28
+
Licensee | None: `Licensee` instance if found, `None` if no licensee id is present.
Constructs a licensee payload dictionary used to create a licensee.
51
+
52
+
Parameters:
53
+
context (Context): Context used to read required values: `accounts.seller.id`, `accounts.buyer.id`, and the `accounts.user_group` resource.
54
+
55
+
Returns:
56
+
dict[str, object]: A dictionary containing licensee fields required by the API (name, address, seller, buyer, account, eligibility, groups, type, status, and defaultLanguage).
57
+
58
+
Raises:
59
+
ValueError: If the environment variable `CLIENT_ACCOUNT_ID` is not set.
60
+
ValueError: If `accounts.seller.id` or `accounts.buyer.id` is missing from the context.
61
+
ValueError: If the `accounts.user_group` resource is missing from the context.
62
+
"""
43
63
account_id=os.getenv("CLIENT_ACCOUNT_ID")
44
64
ifnotaccount_id:
45
65
raiseValueError("CLIENT_ACCOUNT_ID environment variable is required")
Ensure a licensee exists for the current context, creating one if none is present.
104
+
105
+
If no licensee is found in the provided context, attempts to create one using the MPT client and the prepared licensee data, then stores the created licensee in the context.
106
+
107
+
Returns:
108
+
The Licensee instance associated with the context.
Retrieve the Module stored in the context or fetch it from the API if not cached.
21
+
22
+
If the context does not contain "accounts.module.id", returns None. When a cached resource is absent or not a Module, the function fetches the module from the API and stores it in the context.
23
+
24
+
Returns:
25
+
Module if found or fetched, `None` if "accounts.module.id" is not set.
Ensure the context contains a current "Access Management" Module by fetching it if missing.
49
+
50
+
If the context has no module, query the API for modules named "Access Management". Cache the first found Module in the context under "accounts.module" and store its id at "accounts.module.id". Logs a warning and returns None if no suitable Module is found.
Retrieve the Seller stored in the provided context or fetch it from the API and cache it in context.
22
+
23
+
If the context does not contain a seller id ("accounts.seller.id"), returns `None`. If a seller id exists but the context has no matching Seller resource, fetches the Seller using the provided MPT client, stores the Seller in the context under "accounts.seller" and updates "accounts.seller.id" with the Seller's id before returning it.
24
+
25
+
Returns:
26
+
Seller | None: The Seller retrieved from context or API, or `None` if no seller id is present.
"""Get or create seller. Returns Seller if successful, None otherwise."""
67
+
"""
68
+
Ensure a seller exists in the provided context by retrieving it or creating a new one.
69
+
70
+
If no seller is found in context, a seller will be created via the MPT API. On successful creation the function sets the created Seller in the context under "accounts.seller" and its id under "accounts.seller.id".
71
+
72
+
Returns:
73
+
`Seller` if the seller was retrieved or created, `None` otherwise.
Ensure a UserGroup exists for the current context, creating and storing one if it does not.
81
+
82
+
If an existing UserGroup is present in the context it is returned unchanged. When creation succeeds the new UserGroup is saved in the context under "accounts.user_group" and "accounts.user_group.id".
83
+
84
+
Returns:
85
+
UserGroup | None: The retrieved or newly created `UserGroup`, or `None` if creation failed or no group could be obtained.
0 commit comments