AIC API wrapper
Project description
AIC Utilities Package Documentation
Overview
The AIC Utilities package provides a set of classes and methods to interact with the AIC API for managing projects, workspaces, and pipelines. It also integrates with GitLab for source control management and Slack for logging and notifications. The package includes three main components:
- AIC: Manages interactions with the ACI API for fetching project and workspace details, handling pipeline configurations, and managing file uploads.
- GitLabManager: Manages interactions with GitLab, including pushing files to repositories, managing repository existence, and ensuring the correct subgroup configuration based on the workspace.
- SlackLogger: Provides logging functionality that sends log messages to a specified Slack channel, with the ability to redirect print statements to Slack.
Classes and Methods
1. AIC Class
The AIC
class handles interactions with the J.D. Power API, including managing projects, workspaces, pipelines, and file uploads.
Methods
-
__init__(self, api_key, project, workspace, pipelines=[], gitlab_token=None)
- Initializes the AIC instance with the specified API key, project, workspace, pipelines, and optional GitLab token.
-
get_data(self)
- Prints project, workspace, and drive IDs.
-
get_config(self)
- Returns the pipeline configurations.
-
get_project(self, project)
- Fetches the project ID for the specified project name.
-
get_workspace(self, workspace)
- Fetches the workspace ID for the specified workspace name.
-
pop_pipelines(self)
- Retrieves and returns the list of pipelines in the specified workspace.
-
fetch_pipeline_config(self, pipeline)
- Fetches the configuration for a single pipeline.
-
pop_pipeline_config(self, pipelines)
- Fetches configurations for multiple pipelines concurrently using
ThreadPoolExecutor
.
- Fetches configurations for multiple pipelines concurrently using
-
get_drive_id(self, drive_name="config")
- Fetches the drive ID for the specified drive name.
-
upload_json(self, file_name, json_content)
- Uploads JSON content to the specified drive.
-
push_to_gitlab(self, pipelines=[])
- Pushes pipeline configurations to GitLab concurrently.
-
upload_configs_to_drive(self)
- Uploads pipeline configurations to the drive.
-
get_files_from_drive(self, drive_id=None)
- Retrieves files from the specified drive.
-
download_file(self, drive_id, file_name)
- Downloads a file from the storage drive.
-
download_from_gcs(self, gs_path)
- Downloads content from Google Cloud Storage using the specified path.
-
delete_file(self, drive_id, file_id)
- Deletes a file from the storage drive.
-
push_source_code(AIC_prod, AIC_qa, prod_to_qa=False, qa_to_prod=False, pipelines=[])
- Overwrites pipeline configurations between production and QA based on the specified direction and pipelines.
-
write_config_to_pipeline(self, config)
- Uploads the given configuration to the corresponding pipeline job.
2. GitLabManager Class
The GitLabManager
class manages interactions with GitLab, including pushing files, checking repository existence, and creating repositories if needed.
Methods
-
__init__(self, aic_instance, gitlab_token=None, gitlab_namespace='pin/pin-analytics/pin-fusion-2.0/pipelines', gitlab_base_url='https://git.autodatacorp.org/api/v4', use_hash_comparison=True)
- Initializes the GitLabManager instance with the specified AIC instance, GitLab token, namespace, base URL, and hash comparison setting.
-
get_token_expiration_date(self)
- Retrieves the expiration date of the GitLab token.
-
check_token_expiration(self)
- Checks and reports the token expiration date.
-
read_gitlab_token(self)
- Reads the GitLab token from the storage drive.
-
generate_hash(self, content)
- Generates a hash for the given content to check for changes.
-
get_existing_file_content(self, repo_name, file_name)
- Fetches the existing content of a file from the specified repository in GitLab.
-
push_file_to_repo(self, repo_name, file_name, file_content)
- Pushes a file to the specified repository in GitLab, only if the content has changed.
-
ensure_correct_subgroup(self, workspace)
- Ensures the correct subgroup path based on the workspace.
-
create_repository(self, repo_name)
- Creates a new repository in the specified subgroup.
-
get_subgroup_id(self)
- Fetches the GitLab subgroup ID based on the namespace path.
-
get_namespace_id(self)
- Retrieves the namespace ID for the current GitLab namespace.
-
repository_exists(self, repo_path)
- Checks if the repository exists in GitLab.
3. SlackLogger Class
The SlackLogger
class provides logging functionality that sends log messages to a specified Slack channel. It includes a custom logging handler that integrates with Python's logging module.
Methods
-
__init__(self, token, channel)
- Initializes the SlackLogger with the specified Slack token and channel.
-
send_message(self, text)
- Sends a message to the specified Slack channel.
-
SlackLoggerHandler(logging.Handler)
- A custom logging handler that sends log messages to Slack using the SlackLogger.
-
redirect_print_to_logger(logger)
- Redirects print statements to the specified logger.
-
create_logger(cls, slack_token='xoxb-7424459969442-7456034210037-EMCjbI9oi1xTszU1iUh4tLFH', slack_channel='C07DYFK5SE8', redirect_print=True)
- Creates a logger that sends log messages to Slack, with options to redirect print statements.
Usage Examples
Creating an AIC Instance
from aic_utils.aic import AIC
# Initialize AIC instance
aic_instance = AIC(api_key='your_api_key', project='PIN ANALYTICS', workspace='PIN FUSION 2.0', pipelines=['pipeline1', 'pipeline2'])
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aic_utils-1.5.4.tar.gz
.
File metadata
- Download URL: aic_utils-1.5.4.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c4dedad258826854eb785bf8a15728705ca2acb82294e8f292fc2a7fd9d103c2 |
|
MD5 | e0d4960f7ef72cb76f3d425cae612fcd |
|
BLAKE2b-256 | 117095b4eeda96f7386a826edf9c2a6b0feb91d694f38a46d8a0c3e5c9f98bfe |
File details
Details for the file aic_utils-1.5.4-py3-none-any.whl
.
File metadata
- Download URL: aic_utils-1.5.4-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef350456780e7eb41488be24c228dcacc0fda86cd6200285929020141e742a31 |
|
MD5 | d37a713f32baa40bcbbb30a8ea81eacf |
|
BLAKE2b-256 | 100d69880d0452e85f98e0e494a88a6fecd49f0cb1e4276a09c0d6438f3c50d2 |