Welcome to NCTL’s documentation!

Ngrok Tunnel

nctl.ngrok.distribution_handler(public_url: str, env_dump: Dict[str, Any]) None

Updates the cloudfront distribution in a dedicated process.

Parameters:
  • public_url – Public URL from ngrok, that has to be updated.

  • env_dump – JSON dump of environment variables’ configuration.

nctl.ngrok.writer(frame: str) None

Extracts the message part from each line into a custom message format.

Parameters:

frame – Each line of log message from ngrok.

nctl.ngrok.tunnel(**kwargs) None

Initiates a ngrok tunnel using the CLI and updates cloudfront distribution.

AWS CloudFront

class nctl.aws.CloudFront(env_dump: Dict[str, Any])

Initiates CloudFront object to get and update a cloudfront distribution.

>>> CloudFront
run(public_url: str) None

Updates the distribution if ID is available, otherwise creates a new distribution.

Parameters:

public_url – Public URL from ngrok, that has to be updated.

get_distribution() dict

Get cloudfront distribution.

Returns:

Distribution information.

Return type:

dict

create_distribution() None

Creates a cloudfront distribution from a JSON or YAML file as config.

update_distribution(current_config: Dict[str, Any], origin_name: str) None

Updates the origin host of a cloudfront distribution.

Parameters:
  • current_config – Current configuration as in CloudFront.

  • origin_name – Origin name that has to be replaced with.

await_deploy(last_response: Dict[str, Any]) None

Waits for the distribution to be deployed.

Parameters:

last_response – Last known response from AWS.

store_config(configuration: Dict[str, Any] = None) None

Stores the cloudfront distribution config in a YAML file locally.

Parameters:

configuration – CloudFront distribution configuration.

Logger

class nctl.logger.LogConfig(pydantic.BaseModel)

BaseModel object for log configurations.

>>> LogConfig
debug: bool
log: LogOptions
process: str | None
log_config: Optional[Union[Dict[str, Any], Path]]
class Config

Extra configuration for LogConfig object.

extra = 'ignore'
class nctl.logger.AddProcessName(process_name: str)

Wrapper that overrides logging.Filter to add processName to the existing log format.

>>> AddProcessName
Parameters:

process_name – Takes name of the process to be added as argument.

filter(record: LogRecord) bool

Overrides the built-in filter record.

nctl.logger.configure_logging(**kwargs) None

Configure logging based on the parameters.

Keyword Arguments:
  • debug – Boolean flag to enable/disable debug mode.

  • process – Name of the process to add a process name filter to default logging.

  • log_config – Custom logging configuration.

Models

class nctl.models.Concurrency(pydantic.BaseModel)

BaseModel to load the multiprocessing object reference.

>>> Concurrency
cloudfront_process: multiprocessing.context.Process | None
class Config

Config to allow arbitrary types.

arbitrary_types_allowed = True

class nctl.models.EnvConfig(pydantic.BaseSettings)

Configuration settings for environment variables.

>>> EnvConfig
port: int
host: str
ngrok_auth: str | None
ngrok_config: Optional[Path]
aws_profile_name: str | None
aws_access_key_id: str | None
aws_secret_access_key: str | None
aws_default_region: str | None
distribution_id: str | None
distribution_config: Optional[Path]
configdir: str
debug: bool
log: LogOptions
log_config: Optional[Union[Dict[str, Any], Path]]
classmethod from_env_file(env_file: Path) EnvConfig

Create Settings instance from environment file.

Parameters:

env_file – Name of the env file.

Returns:

Loads the EnvConfig model.

Return type:

EnvConfig

class Config

Extra configuration for EnvConfig object.

extra = 'ignore'
hide_input_in_errors = True

class nctl.models.LogOptions(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Enum for log options.

>>> LogOptions
stdout: str = 'stdout'
file: str = 'file'

Squire

nctl.squire.create_ngrok_config(token: str, filename: str) None

Creates a config file for ngrok.

Parameters:
  • token – Ngrok auth token.

  • filename – Filename to dump the config.

nctl.squire.envfile_loader(filename: str | os.PathLike) EnvConfig

Loads environment variables based on filetypes.

Parameters:

filename – Filename from where env vars have to be loaded.

Returns:

Returns a reference to the EnvConfig object.

Return type:

EnvConfig

nctl.squire.load_env(**kwargs) EnvConfig

Merge env vars from env_file with kwargs, giving priority to kwargs.

See also

This function allows env vars to be loaded partially from .env files and partially through kwargs.

Returns:

Returns a reference to the EnvConfig object.

Return type:

EnvConfig

nctl.squire.run_validations() None

Validates the loaded environment variables and checks ngrok CLI availability.

Raises:
  • AssertionError

  • If any of the validations fail.

Indices and tables