Skip to content
Snippets Groups Projects
Commit 8f9ee6e6 authored by Leon Michel Gorißen's avatar Leon Michel Gorißen
Browse files

Feat: Make git commit hash avialable

parent 96483246
No related branches found
No related tags found
No related merge requests found
...@@ -11,9 +11,9 @@ import coscine ...@@ -11,9 +11,9 @@ import coscine
import os import os
import signal import signal
import sys import sys
import subprocess
# TODO create new coscine resource with new application profile once available # TODO create new coscine resource with new application profile once available
# TODO add git commit to data
app = Flask(__name__) # Create a new Flask application app = Flask(__name__) # Create a new Flask application
...@@ -39,8 +39,30 @@ logger.addHandler(console_handler) # Add console handler to logger ...@@ -39,8 +39,30 @@ logger.addHandler(console_handler) # Add console handler to logger
logger.addHandler(file_handler) # Add file handler to logger logger.addHandler(file_handler) # Add file handler to logger
# Retrieve environment variables for API token and robot UUID # Retrieve environment variables for API token and robot UUID
api_token = os.environ.get("COSCINE_API_TOKEN") # Get COSCINE_API_TOKEN from environment def get_env_variable(var_name):
robot_uuid = os.environ.get("ROBOT_UUID") # Get ROBOT_UUID from environment value = os.environ.get(var_name)
if value is None:
raise EnvironmentError(f"The environment variable {var_name} is not set.")
return value
try:
api_token = get_env_variable("COSCINE_API_TOKEN") # Get COSCINE_API_TOKEN from environment
robot_uuid = get_env_variable("ROBOT_UUID") # Get ROBOT_UUID from environment
except EnvironmentError as e:
print(e)
# Handle the error appropriately, e.g., exit the program or set default values
api_token = None
robot_uuid = None
try:
# Run the git command to get the latest commit hash
result = subprocess.run(['git', 'rev-parse', 'HEAD'], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
# The commit hash will be in result.stdout
commit_hash = result.stdout.strip()
except subprocess.CalledProcessError as e:
print(f"Error occurred while getting the latest git commit: {e.stderr}")
def upload_coscine(filepath: Path, token: str) -> None: def upload_coscine(filepath: Path, token: str) -> None:
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment