Utils

Utility functions for Provider app.

smarter.apps.provider.utils.get_google_maps_api_key(recursed=False)[source]

Get the Google Maps API key from the secret store.

Return type:

str | None

smarter.apps.provider.utils.get_google_service_account_bearer_token()[source]

Get a Google service account bearer token.

Return type:

str | None

smarter.apps.provider.utils.get_model_verification_for_type(provider_model, verification_type)[source]

Get the model verification for a specific type, creating it if it does not exist.

Parameters:
Return type:

ProviderModelVerification

Returns:

The existing or new ProviderModelVerification.

smarter.apps.provider.utils.get_provider_verification_for_type(provider, verification_type)[source]

Get the provider verification for a specific type, creating it if it does not exist.

Parameters:
Return type:

ProviderVerification

Returns:

The existing or new ProviderVerification.

smarter.apps.provider.utils.initialize_google_maps()[source]

Initialize Google Maps provider.

Return type:

None

smarter.apps.provider.utils.initialize_secret(secret_string, secret_name, description, user_profile)[source]

Initialize a secret from an environment variable.

Parameters:
  • env_var (str) – The name of the environment variable containing the secret value.

  • secret_name (str) – The name to assign to the created/updated Secret object.

  • description (str) – A description for the Secret object.

Return type:

Secret | None

smarter.apps.provider.utils.set_model_verification(provider_model_verification, is_successful, **kwargs)[source]

Save the model verification’s outcome, and send the matching signal.

Sends model_verification_success or model_verification_failure.

Parameters:
  • provider_model_verification (ProviderModelVerification) – The verification to update.

  • is_successful (bool) – Whether the verification passed.

  • kwargs – Not used.

Return type:

None

smarter.apps.provider.utils.set_provider_verification(provider_verification, is_successful, **kwargs)[source]

Save the provider verification’s outcome, and send the matching signal.

Sends provider_verification_success or provider_verification_failure.

Parameters:
  • provider_verification (ProviderVerification) – The verification to update.

  • is_successful (bool) – Whether the verification passed.

  • kwargs – Not used.

Return type:

None

smarter.apps.provider.utils.should_log(level)[source]

Check if logging should be done based on the waffle switch.

smarter.apps.provider.utils.test_web_page(url, test_str)[source]

Fetch a web page, and check that it is an HTML page that contains a string.

Parameters:
  • url (str) – The page’s URL, fetched with a 10 second timeout.

  • test_str (str) – The text that the page must contain, case-insensitively.

Return type:

bool

Returns:

True if the page returns 200, is HTML and contains test_str; False otherwise, including on a network error.