iib.web

Submodules

iib.web.api_v1 module

iib.web.api_v1._get_user_queue()

Return the name of the celery task queue mapped to the current user.

Returns:queue name to be used or None if the default queue should be used
Return type:str or None
iib.web.api_v1._should_force_overwrite()

Determine if the overwrite_from_index parameter should be forced.

This is for clients that require this functionality but do not currently use the overwrite_from_index parameter already.

Returns:the boolean that determines if the overwrite should be forced
Return type:bool
iib.web.api_v1.add_bundles()

Submit a request to add operator bundles to an index image.

Return type:flask.Response
Raises:ValidationError – if required parameters are not supplied
iib.web.api_v1.get_build(request_id)

Retrieve the build request.

Parameters:request_id (int) – the request ID that was passed in through the URL.
Return type:flask.Response
Raises:NotFound – if the request is not found
iib.web.api_v1.get_builds()

Retrieve the paginated build requests.

Return type:flask.Response
iib.web.api_v1.patch_request(request_id)

Modify the given request.

Parameters:

request_id (int) – the request ID from the URL

Returns:

a Flask JSON response

Return type:

flask.Response

Raises:
  • Forbidden – If the user trying to patch a request is not an IIB worker
  • NotFound – if the request is not found
  • ValidationError – if the JSON is invalid
iib.web.api_v1.regenerate_bundle()

Submit a request to regenerate an operator bundle image.

Return type:flask.Response
Raises:ValidationError – if required parameters are not supplied
iib.web.api_v1.regenerate_bundle_batch()

Submit a batch of requests to regenerate operator bundle images.

Return type:flask.Response
Raises:ValidationError – if required parameters are not supplied
iib.web.api_v1.rm_operators()

Submit a request to remove operators from an index image.

Return type:flask.Response
Raises:ValidationError – if required parameters are not supplied

iib.web.app module

iib.web.app.create_app(config_obj=None)

Create a Flask application object.

Parameters:config_obj (str) – the path to the configuration object to use instead of calling load_config
Returns:a Flask application object
Return type:flask.Flask
iib.web.app.load_config(app)

Determine the correct configuration to use and apply it.

Parameters:app (flask.Flask) – a Flask application object
iib.web.app.validate_api_config(config)

Determine if the configuration is valid.

Parameters:config (dict) – the dict containing the IIB REST API config
Raises:ConfigError – if the config is invalid

iib.web.auth module

iib.web.auth._get_kerberos_principal(request)

Get the Kerberos principal from the current request.

This relies on the “REMOTE_USER” environment variable being set. This is usually set by the mod_auth_gssapi Apache authentication module.

Parameters:request (flask.Request) – the Flask request
Returns:the user’s Kerberos principal or None
Return type:str
iib.web.auth.load_user_from_request(request)

Load the user that authenticated from the current request.

This is used by the Flask-Login library. If the user does not exist in the database, an entry will be created.

If None is returned, then Flask-Login will set flask_login.current_user to an AnonymousUserMixin object, which has the is_authenticated property set to False. Additionally, any route decorated with @login_required will raise an Unauthorized exception.

Parameters:request (flask.Request) – the Flask request
Returns:the User object associated with the username or None
Return type:iib.web.models.User
iib.web.auth.user_loader(username)

Get the user by their username from the database.

This is used by the Flask-Login library.

Parameters:username (str) – the username of the user
Returns:the User object associated with the username or None
Return type:iib.web.models.User

iib.web.config module

class iib.web.config.Config

Bases: object

The base IIB Flask configuration.

class iib.web.config.DevelopmentConfig

Bases: iib.web.config.Config

The development IIB Flask configuration.

class iib.web.config.ProductionConfig

Bases: iib.web.config.Config

The production IIB Flask configuration.

class iib.web.config.TestingConfig

Bases: iib.web.config.DevelopmentConfig

The testing IIB Flask configuration.

class iib.web.config.TestingConfigNoAuth

Bases: iib.web.config.TestingConfig

The testing IIB Flask configuration without authentication.

iib.web.docs module

iib.web.docs.index()

Return the OpenAPI documentation presented by redoc.

iib.web.errors module

iib.web.errors.json_error(error)

Convert exceptions to JSON responses.

Parameters:error (Exception) – an Exception to convert to JSON
Returns:a Flask JSON response
Return type:flask.Response

iib.web.manage module

iib.web.models module

class iib.web.models.Architecture(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

An architecture associated with an image.

static validate_architecture_json(arches)

Validate the JSON representation of architectures.

Parameters:arches (list) – the JSON representation of architectures for a build request
Raises:ValidationError – if the JSON does not match the required schema
class iib.web.models.BaseEnum

Bases: enum.Enum

A base class for IIB enums.

class iib.web.models.Batch(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

A batch associated with one or more requests.

annotations

Return the Python representation of the JSON annotations.

request_states

Get the states of all the requests in the batch.

Returns:the list of states
Return type:list<str>
state

Get the state of the batch.

If one or more requests in the batch are in_progress, then the batch is in_progress. Once all the requests in the batch have completed, if one or more requests are in the failed state, then so is the batch. If all requests in the batch are in the complete state, then so is the batch.

Returns:the state of the batch
Return type:str
user

Get the User object associated with the batch.

Returns:the User object associated with the batch or None
Return type:User or None
static validate_batch(batch_id)

Validate the input batch ID.

If the input batch ID is a string, it will be converted to an integer and returned.

Parameters:batch_id (int) – the ID of the batch
Raises:ValidationError – if the batch ID is invalid
Returns:the validated batch ID
Return type:int
static validate_batch_request_params(payload)

Validate batch specific parameters from the input JSON payload.

The requests in the “build_requests” key’s value are not validated. Those should be validated separately.

Raises:ValidationError – if the payload is invalid
class iib.web.models.Image(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

An image that has been handled by IIB.

This will typically point to a manifest list.

classmethod get_or_create(pull_specification)

Get the image from the database and create it if it doesn’t exist.

Parameters:pull_specification (str) – pull_specification of the image
Returns:an Image object based on the input pull_specification; the Image object will be added to the database session, but not committed, if it was created
Return type:Image
Raises:ValidationError – if pull_specification for the image is invalid
class iib.web.models.Operator(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

An operator that has been handled by IIB.

classmethod get_or_create(name)

Get the operator from the database and create it if it doesn’t exist.

Parameters:name (str) – the name of the operator
Returns:an Operator object based on the input name; the Operator object will be added to the database session, but not committed, if it was created
Return type:Operator
class iib.web.models.Request(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

A generic image build request.

add_architecture(arch_name)

Add an architecture associated with this image.

Parameters:arch_name (str) – the architecture to add
Raises:ValidationError – if the architecture is invalid
add_state(state, state_reason)

Add a RequestState associated with the current request.

Parameters:
  • state (str) – the state name
  • state_reason (str) – the reason explaining the state transition
Raises:

ValidationError – if the state is invalid

classmethod from_json(kwargs)

Handle JSON requests for a request API endpoint.

Child classes MUST override this method.

Parameters:kwargs (dict) – the user provided parameters to create a Request
Returns:an object representation of the request
Retype:Request
get_mutable_keys()

Return the set of keys representing the attributes that can be modified.

Returns:a set of key names
Return type:set
to_json(verbose=True)

Provide the basic JSON representation of a build request.

Child classes are expected to enhance the JSON representation as needed.

Parameters:verbose (bool) – determines if the JSON output should be verbose
Returns:a dictionary representing the JSON of the build request
Return type:dict
type_name

Get the request’s type as a string.

Returns:the request’s type
Return type:str
validate_type(key, type_num)

Verify the type number used is valid.

Parameters:
  • key (str) – the name of the database column
  • type_num (int) – the request type number to be verified
Returns:

the request type number

Return type:

int

Raises:

ValidationError – if the request type is invalid

class iib.web.models.RequestAdd(**kwargs)

Bases: iib.web.models.Request, iib.web.models.RequestIndexImageMixin

An “add” index image build request.

binary_image

Return the relationship to the image that the opm binary comes from.

binary_image_id

Return the ID of the image that the opm binary comes from.

binary_image_resolved

Return the relationship to the resolved image that the opm binary comes from.

binary_image_resolved_id

Return the ID of the resolved image that the opm binary comes from.

from_index

Return the relationship of the index image to base the request from.

from_index_id

Return the ID of the index image to base the request from.

from_index_resolved

Return the relationship of the resolved index image to base the request from.

from_index_resolved_id

Return the ID of the resolved index image to base the request from.

classmethod from_json(kwargs)

Handle JSON requests for the Add API endpoint.

get_mutable_keys()

Return the set of keys representing the attributes that can be modified.

Returns:a set of key names
Return type:set
index_image

Return the relationship to the built index image.

index_image_id

Return the ID of the built index image.

to_json(verbose=True)

Provide the JSON representation of an “add” build request.

Parameters:verbose (bool) – determines if the JSON output should be verbose
Returns:a dictionary representing the JSON of the build request
Return type:dict
class iib.web.models.RequestAddBundle(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

An association table between add requests and the bundles they contain.

class iib.web.models.RequestArchitecture(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

An association table between requests and the architectures they were built for.

class iib.web.models.RequestIndexImageMixin

Bases: object

A class for shared functionality between index image requests.

This class uses the Mixin pattern as defined in: https://docs.sqlalchemy.org/en/13/orm/extensions/declarative/mixins.html

static _from_json(request_kwargs, additional_required_params=None, additional_optional_params=None)

Validate and process request agnostic parameters.

As part of the processing, the input request_kwargs parameter is updated to reference database objects where appropriate.

Parameters:request_kwargs (dict) – copy of args provided in API request
get_common_index_image_json()

Return the common set of attributes for an index image request.

For compatibility between the different types of index image requests, any index image request must provide the combination of possible attributes. For example, the “bundles” attribute is always included even though it’s only used by RequestAdd.

The specialized index image requests should modify the value of the attributes as needed.

Returns:a partial dictionary representing the JSON of the index image build request
Return type:dict
get_index_image_mutable_keys()

Return the set of keys representing the attributes that can be modified.

Returns:a set of key names
Return type:set
class iib.web.models.RequestRegenerateBundle(**kwargs)

Bases: iib.web.models.Request

A “regenerate_bundle” image build request.

classmethod from_json(kwargs, batch=None)

Handle JSON requests for the Regenerate Bundle API endpoint.

Parameters:
  • kwargs (dict) – the JSON payload of the request.
  • batch (Batch) – the batch to specify with the request. If one is not specified, one will be created automatically.
get_mutable_keys()

Return the set of keys representing the attributes that can be modified.

Returns:a set of key names
Return type:set
to_json(verbose=True)

Provide the JSON representation of a “regenerate-bundle” build request.

Parameters:verbose (bool) – determines if the JSON output should be verbose
Returns:a dictionary representing the JSON of the build request
Return type:dict
class iib.web.models.RequestRm(**kwargs)

Bases: iib.web.models.Request, iib.web.models.RequestIndexImageMixin

A “rm” index image build request.

binary_image

Return the relationship to the image that the opm binary comes from.

binary_image_id

Return the ID of the image that the opm binary comes from.

binary_image_resolved

Return the relationship to the resolved image that the opm binary comes from.

binary_image_resolved_id

Return the ID of the resolved image that the opm binary comes from.

from_index

Return the relationship of the index image to base the request from.

from_index_id

Return the ID of the index image to base the request from.

from_index_resolved

Return the relationship of the resolved index image to base the request from.

from_index_resolved_id

Return the ID of the resolved index image to base the request from.

classmethod from_json(kwargs)

Handle JSON requests for the Remove API endpoint.

get_mutable_keys()

Return the set of keys representing the attributes that can be modified.

Returns:a set of key names
Return type:set
index_image

Return the relationship to the built index image.

index_image_id

Return the ID of the built index image.

to_json(verbose=True)

Provide the JSON representation of an “rm” build request.

Parameters:verbose (bool) – determines if the JSON output should be verbose
Returns:a dictionary representing the JSON of the build request
Return type:dict
class iib.web.models.RequestRmOperator(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

An association table between rm requests and the operators they contain.

class iib.web.models.RequestState(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model

Represents a state (historical or present) of a request.

state_name

Get the state’s display name.

class iib.web.models.RequestStateMapping

Bases: iib.web.models.BaseEnum

An Enum that represents the request states.

class iib.web.models.RequestTypeMapping

Bases: iib.web.models.BaseEnum

An Enum that represents the request types.

class iib.web.models.User(**kwargs)

Bases: sqlalchemy.ext.declarative.api.Model, flask_login.mixins.UserMixin

Represents an external user that owns an IIB request.

classmethod get_or_create(username)

Get the user from the database and create it if it doesn’t exist.

Parameters:username (str) – the username of the user
Returns:a User object based on the input username; the User object will be added to the database session, but not committed, if it was created
Return type:User
iib.web.models.get_request_query_options(verbose=False)

Get the query options for a SQLAlchemy query for one or more requests to output as JSON.

This will add the joins ahead of time on relationships that are accessed in the to_json methods to avoid individual select statements when the relationships are accessed.

Parameters:verbose (bool) – if the request relationships should be loaded for verbose JSON output
Returns:a list of SQLAlchemy query options
Return type:list
iib.web.models.validate_request_params(request_params, required_params, optional_params)

Validate parameters for a build request.

All required parameters must be set in the request_params and unknown parameters are not allowed.

Parameters:
  • request_params (dict) – the request parameters provided by the user
  • required_params (set) – the set of required parameters
  • optional_params (set) – the set of optional parameters
Raises:

iib.exceptions.ValidationError – if validation of parameters fails

iib.web.utils module

iib.web.utils.pagination_metadata(pagination_query, **kwargs)

Return a dictionary containing metadata about the paginated query.

This must be run as part of a Flask request.

Parameters:
  • pagination_query (flask_sqlalchemy.Pagination) – the paginated query
  • kwargs (dict) – the query parameters to add to the URLs
Returns:

a dictionary containing metadata about the paginated query

iib.web.utils.str_to_bool(item)

Convert a string to a boolean.

Parameters:item (str) – string to parse
Returns:a boolean equivalent
Return type:bool

iib.web.wsgi module

Module contents