apply_manifest
utility for applying any Smarter manifest using the api/v1/cli endpoint.
- class smarter.apps.api.management.commands.apply_manifest.Command(*args, **kwargs)[source]
Bases:
SmarterCommandUtility for running
api/v1/cli/endpoints to verify their functionality.This management command serves both as a utility and an instructional tool for interacting with Smarter manifests via the API. It is designed to help developers and administrators understand and validate the process of applying manifests through the CLI endpoint.
Key Features and Demonstrations:
Shows how to generate an API key for a user, which is required for authenticated requests.
Demonstrates how to include the API key in HTTP requests to
api/v1/cli/endpoints.Explains how to construct and send HTTP requests to the manifest application endpoint.
Illustrates how to handle and interpret the response object returned by the API.
Usage:
This command can be invoked via Django’s
manage.pyinterface. It accepts either a manifest file (YAML or JSON) or a manifest string directly, along with the username of the admin user who will apply the manifest. The command will:Validate the provided manifest input.
Retrieve the specified user and ensure they have an associated admin profile.
Generate a single-use API token for authentication.
Construct the appropriate API endpoint URL, considering the current environment (HTTP/HTTPS).
Send the manifest data to the API endpoint using an authenticated HTTP POST request.
Display formatted output, including request details and the API response, with optional verbosity.
Error Handling:
The command provides clear error messages for common failure scenarios, such as missing user profiles, invalid manifest input, or unsuccessful API responses. All failures are reported with context to aid trouble shooting.
Intended Audience:
This tool is intended for developers, system administrators, and anyone interested in learning how Smarter manifests are applied programmatically. It is especially useful for instructional purposes, demonstrations, and manual verification of API endpoint behavior.
- handle(*args, **options)[source]
Prepare and get a response from the api/v1/cli/apply endpoint. We need to be mindful of the environment we are in, as the endpoint may be hosted over https or http.
- help = 'Apply a Smarter manifest.'