Backend API

The Data Models

class groundstation.backend_api.models.Communications(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.FlightScheduleCommands(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.FlightScheduleCommandsArgs(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.FlightSchedules(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.Housekeeping(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.Passover(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.PowerChannels(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.Telecommands(**kwargs)
to_json()

Returns a dictionary of some selected model attributes

class groundstation.backend_api.models.User(username, password, is_admin=False)
static decode_auth_token(auth_token)

Decodes the auth token

Parameters

auth_token – The authorization token

Returns

user_id (int)

encode_auth_token_by_id()

Generates the auth token

to_json()

Returns a dictionary of some selected model attributes

verify_password(password)

Returns True if passes password is valid, else False

Parameters

password (str) – The password to validate

Returns

True if password is valid

Return type

bool

Utility Functions

groundstation.backend_api.utils.add_arg_to_flightschedulecommand(index, argument, flightschedule_command_id)

Add a new argument to a pre-existing flightschedule command

groundstation.backend_api.utils.add_command_to_flightschedule(timestamp, flightschedule_id, command_id)

Add a new command to a pre-existing flight schedule

groundstation.backend_api.utils.add_flight_schedule(creation_date, upload_date, status, execution_time)

Add a new flight schedule to the database

groundstation.backend_api.utils.add_message_to_communications(timestamp, message, receiver, sender)

Add a new message to the communications table

groundstation.backend_api.utils.add_passover(timestamp)

Add a new passover to the database

groundstation.backend_api.utils.add_telecommand(command_name, num_arguments, is_dangerous)

Add a new telecommand to the database

groundstation.backend_api.utils.add_user(username, password, is_admin=False)

Add a new user to the database

groundstation.backend_api.utils.create_context(function)

A decorator to handle cases where backend api calls have no app context, namely for when locally using the api, db session must be initiated in order to access models and database operation. This is required because flask requires an ‘application context’ to exist in order to work.

groundstation.backend_api.utils.dynamic_filters_communications(filters)

Build a filter dynamically for communications table from query paramaters

Parameters

filters (dict) – Dictionary of arg-value pairs

Returns

a list of filters which can be passed into SQL alchemy filter queries.

Return type

list

groundstation.backend_api.utils.dynamic_filters_housekeeping(filters, ignore_keys=[])

Build a filter dynamically for housekeeping from query paramaters.

Parameters
  • filters (werkzeug.datastructures.MultiDict) – Dictionary of key-value pairs, using a multi dict allows users to have filters which overload the keys, ex.) if you want a filter like: ?current_in>5&current_in<10

  • ignore_keys (list) – Optional list, any keys in this list will not be used when building the filter

Returns

a list of filters which can be passed into SQL alchemy filter queries.

Return type

list

groundstation.backend_api.utils.login_required(f)

This is a wrapper which can be used to protect endpoints behind authentication

Validators

This module contains Validators which can be used to validated JSON payloads or dicts to make sure they follow the expected format and contain the required information needed by the backend_api endpoints. Refer to backend_api endpoints for examples, eg.) backend_api.housekeeping.HousekeepingLogList.post. Note: You can nest validators using the Nested field.

class groundstation.backend_api.validators.ArgumentValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for arguments to flight schedule commands

class groundstation.backend_api.validators.AuthLoginValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for checking login information is present

class groundstation.backend_api.validators.CommandValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for a single flight schedule command

class groundstation.backend_api.validators.FlightScheduleCommandValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for flighschedule commands

class groundstation.backend_api.validators.FlightSchedulePatchCommandValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for patching (editing) a flightschedule’s commands

class groundstation.backend_api.validators.FlightSchedulePatchValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for patching (editing) a flightschedule

class groundstation.backend_api.validators.FlightScheduleValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for flight schedules

class groundstation.backend_api.validators.HousekeepingValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for houskeeping

class groundstation.backend_api.validators.PassoverListValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator list of passovers

class groundstation.backend_api.validators.PassoverValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for passovers

class groundstation.backend_api.validators.PowerChannelValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for power channels

class groundstation.backend_api.validators.TelecommandListValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for new telecommands

class groundstation.backend_api.validators.UserValidator(*, only: Union[Sequence[str], Set[str]] = None, exclude: Union[Sequence[str], Set[str]] = (), many: bool = False, context: Dict = None, load_only: Union[Sequence[str], Set[str]] = (), dump_only: Union[Sequence[str], Set[str]] = (), partial: Union[bool, Sequence[str], Set[str]] = False, unknown: str = None)

Validator for creating new users