reviewboard.licensing.provider¶
Providers for managing licensing options.
New in version 7.1.
- class BaseLicenseProvider[source]¶
Bases:
Generic[_TLicenseInfo]Base class for a provider for managing licenses.
License providers make internal licensing information available to Review Board, to simplify and unify license management for multiple add-ons in one place.
A license provider can control what licenses they want to expose for display purposes, handle checking for changes to licenses (new, updated, or removed), and can provide custom actions that can be invoked via an action button.
New in version 7.1.
- BUILTIN_ACTIONS: Final[set[str]] = {'license-update-check', 'process-license-update', 'upload-license'}¶
A set of built-in actions common to all license providers.
- js_license_model_name: ClassVar[str] = 'RB.License'¶
The name of the JavaScript model for the license front-end.
- js_license_view_name: ClassVar[str] = 'RB.LicenseView'¶
The name of the JavaScript view for the license front-end.
- custom_actions: set[str] = {}¶
Custom actions that can be handled by the license provider.
Each action must correspond to a
handle_actionname_actionmethod.
- get_licenses() Sequence[_TLicenseInfo][source]¶
Return the list of available licenses.
This may include active licenses, expired licenses, and trial licenses.
- Returns:
The list of licenses provided.
- Return type:
- get_license_by_id(license_id: str) Optional[_TLicenseInfo][source]¶
Return a license with the given provider-unique ID.
This may return an active license, expired license, or trial license.
- Parameters:
license_id (
str) – The provider-unique ID for the license.- Returns:
The license information, or
Noneif not found.- Return type:
- get_manage_license_url(*, license_info: _TLicenseInfo) str | None[source]¶
Return the URL for managing licenses online.
This is used to link to an outside license management portal for a given license.
- Parameters:
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information to link to in the portal.- Returns:
The URL to the license portal, or
Noneif one is not available.- Return type:
- get_license_actions(*, license_info: _TLicenseInfo, request: HttpRequest | None = None) list[LicenseAction][source]¶
Return actions to display when viewing a license.
By default, this may contain Manage License and Update License actions. Subclasses may override this to provide custom actions.
- Parameters:
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information that will be displayed.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The list of actions to display for the license.
- Return type:
- get_license_line_items(*, license_info: _TLicenseInfo, request: HttpRequest | None = None) Sequence[LicenseLineItem][source]¶
Return line items to display when viewing a license.
Line items may contain information or even custom HTML describing an important aspect of a license.
By default, this will contain any line items assigned to the license. Subclasses may override this to provide additional information.
- Parameters:
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information that will be displayed.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The list of line items to display for the license.
- Return type:
- get_check_license_request(*, action_data: JSONDictImmutable, license_info: _TLicenseInfo, request: HttpRequest | None = None) RequestCheckLicenseResult | None[source]¶
Return data used to check a license for validity.
This can be any JSON data that the license provider may want to send to a license portal in order to check if a license is still valid or if there’s a newer license available.
- Parameters:
action_data (
dict) –Data provided in the request to the action.
This will correspond to HTTP POST data if processing via an HTTP request from the client.
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information that will be checked.request (
django.http.HttpRequest, optional) – The HTTP request from the client, if any.
- Returns:
The state used to control the license check, or
Noneif checks are not supported.- Return type:
reviewboard.licensing.license_checks.RequestCheckLicenseResult- Raises:
reviewboard.licensing.errors.LicenseActionError – There was an error generating data for this request.
- get_js_license_model_data(*, license_info: _TLicenseInfo, request: HttpRequest | None = None) SerializableDjangoJSONDict[source]¶
Return data for the JavaScript license model.
This provides all the data needed by the JavaScript license model to display and manage the license in the UI.
- Parameters:
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information to convert to model data.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The data for the JavaScript license model.
- Return type:
typelets.django.json.SerializableDjangoJSONDict
- process_check_license_result(*, action_data: LicenseActionData, license_info: _TLicenseInfo, check_request_data: JSONValue, check_response_data: JSONValue, session_token: str | None, request: HttpRequest | None = None) ProcessCheckLicenseResult[source]¶
Process the result of a license check.
This will take the response from a license check and process it. This may involve applying and saving the new license, or updating related state.
The result indicates if the license is already up-to-date, newly-applied, or hit an error. It may also return new license attributes.
- Parameters:
action_data (
reviewboard.licensing.actions.LicenseActionData) –Data provided in the request to the action.
This will correspond to HTTP POST data if processing via an HTTP request from the client.
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information to convert to model data.check_request_data (
typelets.json.JSONValue) – The original request data sent to the license check.check_response_data (
typelets.json.JSONValue) – The response data from the license check.session_token (
str) –The session token provided by
get_check_license_request().This will be
Noneif a session token was not provided.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The processed result of the license check.
- Return type:
reviewboard.licensing.license_checks.ProcessCheckLicenseResult- Raises:
NotImplementedError – This method must be implemented by subclasses.
reviewboard.licensing.errors.LicenseActionError – There was an error processing license data, or the license data was not valid for the product.
- set_license_data(*, license_info: _TLicenseInfo, license_data: bytes, request: HttpRequest | None = None) None[source]¶
Manually set new license data.
This is used to allow a user to upload a new license directly, if supported by the license provider.
Subclasses that override this must validate the license and ensure it can be set.
- Parameters:
license_info (
reviewboard.licensing.license.LicenseInfo) – The license information to convert to model data.license_data (
bytes) – The license data to set.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Raises:
reviewboard.licensing.errors.LicenseActionError – There was an error setting license data, or the license data was not valid for the product.
- call_action(action_id: str, *, license_info: _TLicenseInfo, action_data: LicenseActionData = {}, request: HttpRequest | None = None) SerializableDjangoJSONDict[source]¶
Call and handle a registered license action.
This is used to perform license action requests from the UI or within the server for purposes such as license update checks and activation.
Custom handlers can include the following standard fields in a JSON response:
- Keys:
- Parameters:
action_data (
dict) –Data provided in the request to the action.
This will correspond to HTTP POST data if processing via an HTTP request from the client.
license_info (
reviewboard.licensing.license.LicenseInfo) – Information on the license to check for updates.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The JSON-serializable dictionary of results to send back to the client.
- Return type:
- Raises:
reviewboard.licensing.errors.LicenseActionError – An error invoking an action in the License Provider. This will result in a suitable error message for the client.
- handle_license_update_check_action(*, action_data: LicenseActionData, license_info: _TLicenseInfo, request: HttpRequest | None) SerializableDjangoJSONDict[source]¶
Handle a license update check.
This will request a license server URL and a payload from the License Provider. The client can send the payload to the license server URL to request a new license, or check status for a license.
- Parameters:
action_data (
dict) –Data provided in the request to the action.
This will correspond to HTTP POST data if processing via an HTTP request from the client.
license_info (
reviewboard.licensing.license.LicenseInfo) – Information on the license to check for updates.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The JSON-serializable dictionary of results to send back to the client.
- Return type:
- Raises:
reviewboard.licensing.errors.LicenseActionError – An error invoking an action in the License Provider. This will result in a suitable error message for the client.
- handle_process_license_update_action(*, action_data: LicenseActionData, license_info: _TLicenseInfo, request: HttpRequest | None) SerializableDjangoJSONDict[source]¶
Handle an automated license update payload.
This will process the payload from a license server, passing the result to the License Provider. That may install a new license or update information about a license in the backend.
- Parameters:
action_data (
dict) –Data provided in the request to the action.
This will correspond to HTTP POST data if processing via an HTTP request from the client.
license_info (
reviewboard.licensing.license.LicenseInfo) – Information on the license to check for updates.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The JSON-serializable dictionary of results to send back to the client.
- Return type:
- Raises:
reviewboard.licensing.errors.LicenseActionError – An error with the data or with invoking the actions in the License Provider. This will result in a suitable error message for the client.
- handle_upload_license_action(*, action_data: LicenseActionData, license_info: _TLicenseInfo, request: HttpRequest | None) SerializableDjangoJSONDict[source]¶
Handle a manual license upload.
This will take the provided license data and pass it to the License Provider for license replacement. This is dependent on the capabilities of the License Provider.
- Parameters:
action_data (
dict) –Data provided in the request to the action.
This will correspond to HTTP POST data if processing via an HTTP request from the client.
license_info (
reviewboard.licensing.license.LicenseInfo) – Information on the license to check for updates.request (
django.http.HttpRequest, optional) – The HTTP request from the client.
- Returns:
The JSON-serializable dictionary of results to send back to the client.
- Return type:
- Raises:
reviewboard.licensing.errors.LicenseActionError – An error with the data or with invoking the upload in the License Provider. This will result in a suitable error message for the client.