cloudos_cli.configure.configure¶
Functions
|
Recursively build a default_map dictionary for a Click group and all its subcommands. |
Load shared configuration from the default profile with fallback to empty defaults. |
|
|
Decorator to automatically handle profile configuration loading for commands. |
Classes
|
Class to manage configuration profiles for the CloudOS CLI. |
- class cloudos_cli.configure.configure.ConfigurationProfile(config_dir=None)[source]¶
Bases:
objectClass to manage configuration profiles for the CloudOS CLI. This class provides methods to create, list, remove, and load profiles from configuration files. It also allows setting a profile as the default profile. .. attribute:: config_dir
Directory where the configuration files are stored.
- type:
str
- credentials_file¶
Path to the credentials file.
- Type:
str
- config_file¶
Path to the config file.
- Type:
str
- check_if_profile_exists(profile_name)[source]¶
Check if a profile exists in the config file. Parameters: ———- profile_name : str
The name of the profile to check.
Returns:¶
- bool
True if the profile exists, False otherwise.
- create_profile_from_input(profile_name)[source]¶
Interactively create a profile in credentials and config files. Parameters: ———- profile_name : str
The name of the profile to create or update. If the profile already exists, the user will be prompted to update its parameters.
This method guides the user through an interactive process to input or update profile details such as API token, platform URL, workspace ID, project name, execution platform, repository provider, and workflow name. The profile can also be set as the default profile if desired. The API token is stored in the credentials file, while other settings are stored in the config file. If the profile already exists, existing values are pre-filled for convenience.
- determine_default_profile()[source]¶
Determine the default profile from the config file. Returns: ——- str
The name of the default profile, or None if no default is set.
- static get_param_value(ctx, param_value, param_name, default_value, required=False, missing_required_params=None)[source]¶
- load_profile(profile_name)[source]¶
Load a profile from the config and credentials files dynamically.
This method now returns ALL parameters from the profile, not just predefined ones. This makes it extensible - you can add new parameters to profiles without modifying this method.
Parameters:¶
- profile_namestr
The name of the profile to load.
Returns:¶
- dict
A dictionary containing all profile parameters. Returns all keys from both credentials and config files for the specified profile.
Examples
# If you add accelerate_saving_results to your profile config: config[profile_name][‘accelerate_saving_results’] = ‘true’
# It will automatically be included in the returned dictionary: profile_data = load_profile(‘myprofile’) # profile_data will contain ‘accelerate_saving_results’: ‘true’
- load_profile_and_validate_data(ctx, init_profile, cloudos_url_default, profile, required_dict, **cli_params)[source]¶
Load profile data and validate required parameters dynamically.
This method now accepts any parameters via **cli_params, making it extensible. You can add new parameters to profiles (like accelerate_saving_results) without modifying this method.
- Parameters:
ctx (click.Context) – The Click context object.
init_profile (str) – A default string to identify if any profile is available
cloudos_url_default (str) – The default cloudos URL to compare with the one from the profile
profile (str) – The profile name to load.
required_dict (dict) – A dictionary with param name as key and whether is required or not (as bool) as value.
**cli_params (dict) –
All CLI parameters passed as keyword arguments. Any parameter can be passed here and will be resolved from the profile if available.
- Examples: apikey, cloudos_url, workspace_id, project_name, workflow_name,
execution_platform, repository_platform, session_id, procurement_id, accelerate_saving_results, etc.
- Returns:
A dictionary containing all loaded and validated parameters.
- Return type:
dict
Examples
# Add a new parameter to profile without changing this method: # 1. Add to profile creation (create_profile_from_input) # 2. Add to load_profile method return dict # 3. Pass it in cli_params when calling this method # 4. It will automatically be resolved from profile!
- cloudos_cli.configure.configure.build_default_map_for_group(group, shared_config)[source]¶
Recursively build a default_map dictionary for a Click group and all its subcommands.
This function introspects a Click group to discover all registered commands and subcommands, then builds a default_map structure that applies the shared_config to all of them. This eliminates the need to manually maintain a list of commands in default_map.
- Parameters:
group (click.Group) – The Click group to introspect
shared_config (dict) – The configuration dictionary to apply to all commands
- Returns:
A dictionary mapping command names to their configurations
- Return type:
dict
Example
# Instead of manually defining: default_map = {
‘job’: {‘status’: shared_config, ‘list’: shared_config, …}, ‘workflow’: {‘list’: shared_config, …}
}
# Use: default_map = build_default_map_for_group(run_cloudos_cli, shared_config)
Load shared configuration from the default profile with fallback to empty defaults.
This function centralizes the logic for loading the shared configuration that will be used to populate the default_map for all commands. It handles missing profiles, incomplete profiles, and loading errors gracefully.
The default profile is loaded without validation - just to provide default values. The with_profile_config decorator will handle validation when commands actually run. This allows the default profile to have missing fields when not actually used.
- Returns:
A dictionary containing the shared configuration with all standard fields. Missing fields are filled with empty strings to prevent KeyErrors.
- Return type:
dict
Example
>>> shared_config = get_shared_config() >>> ctx.default_map = build_default_map_for_group(run_cloudos_cli, shared_config)
- cloudos_cli.configure.configure.with_profile_config(required_params=None)[source]¶
Decorator to automatically handle profile configuration loading for commands.
This decorator simplifies command functions by automatically loading configuration from profiles and validating required parameters. It eliminates the need to manually create required_dict and call load_profile_and_validate_data in each command.
- Parameters:
required_params (list, optional) – List of parameter names that can currently be added in a profile. Common values: - ‘apikey’: CloudOS API key - ‘workspace_id’: CloudOS workspace ID - ‘project_name’: Project name - ‘workflow_name’: Workflow/pipeline name - ‘session_id’: Interactive session ID - ‘procurement_id’: Procurement ID This list can be updated as new parameters are added to profiles.
Example
@job.command(‘details’) @click.option(’–apikey’, help=’Your CloudOS API key’, required=True) @click.option(’–workspace-id’, help=’The specific CloudOS workspace id.’, required=True) @click.option(’–job-id’, help=’The job id in CloudOS to search for.’, required=True) @click.option(’–profile’, help=’Profile to use from the config file’, default=None) @click.pass_context @with_profile_config(required_params=[‘apikey’, ‘workspace_id’]) def job_details(ctx, apikey, workspace_id, job_id, …):
# apikey, cloudos_url, workspace_id are automatically available cl = Cloudos(cloudos_url, apikey, None) …
- Returns:
Decorated function with automatic profile configuration loading.
- Return type:
function