apply_manifest

Utility for applying any Smarter manifest using the api/v1/cli endpoint.

class smarter.apps.api.management.commands.apply_manifest.Command(stdout=None, stderr=None, no_color=False, force_color=False)[source]

Bases: SmarterCommand

Utility 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.py interface. 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:

  1. Validate the provided manifest input.

  2. Retrieve the specified user and ensure they have an associated admin profile.

  3. Parse the manifest and find the broker for its kind.

  4. Apply the manifest with that broker, as the user, through a request built with Django’s RequestFactory.

  5. Report success, or log the manifest and the broker’s response and raise CommandError.

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.

add_arguments(parser)[source]

Add arguments to the command.

property data: str

Open and validate the structure of the Manifest data.

filespec: str | None = None
get_user_profile(username, account_number)[source]

Return the user profile that applies the manifest, and set self.user.

Parameters:
  • username (str | None) – The --username option.

  • account_number (str | None) – The --account_number option, for a user who belongs to several accounts.

Return type:

UserProfile | None

Returns:

The profile, or None after reporting the failure, if there is no such user or profile.

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.'
manifest: str | None = None
user: User | None = None