Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternative way to fetch recordings #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .github/workflows/create-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build pull request
on:
pull_request:
types: [opened, synchronize]
jobs:
#build-pull-request-python:
build-pull-request-docker-image:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout repository
uses: actions/checkout@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to Docker Hub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
# Build the Docker image with the latest tag and the release tag
- name: Build and push Docker image with latest tag
uses: docker/build-push-action@v2
with:
context: .
push: false
tags: uugai/uugai-python-kerberos-vault:latest
19 changes: 19 additions & 0 deletions .github/workflows/pr-description.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Autofill PR description

on: pull_request

jobs:
openai-pr-description:
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v4
- name: Autofill PR description if empty using OpenAI
uses: cedricve/azureopenai-pr-description@master
with:
github_token: ${{ secrets.TOKEN }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
azure_openai_api_key: ${{ secrets.AZURE_OPENAI_API_KEY }}
azure_openai_endpoint: ${{ secrets.AZURE_OPENAI_ENDPOINT }}
azure_openai_version: ${{ secrets.AZURE_OPENAI_VERSION }}
overwrite_description: true
116 changes: 107 additions & 9 deletions uugai_python_kerberos_vault/KerberosVault.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import traceback
import requests


class KerberosVault:
"""A class for connecting with the Kerberos Vault.
"""


def __init__(self, storage_uri, storage_access_key, storage_secret_key):
""" Initializes the QueueProcessor object with necessary attributes.

Expand All @@ -24,7 +24,6 @@ def __init__(self, storage_uri, storage_access_key, storage_secret_key):
self.storage_access_key = storage_access_key
self.storage_secret_key = storage_secret_key


def update_storage_info(self, data):
""" Updates storage-related information based on data received from message payloads.

Expand All @@ -42,7 +41,6 @@ def update_storage_info(self, data):
if "storage_secret" in data and data['storage_secret'] != "":
self.storage_secret = data['storage_secret']


def create_headers(self, file_name, storage_provider):
""" Creates and returns headers required for accessing storage service based on message payload information.

Expand All @@ -64,7 +62,6 @@ def create_headers(self, file_name, storage_provider):
}

return self.headers


def retrieve_media(self, message: str, media_type: str = '', media_savepath: str = ''):
""" Fetches associated data from storage, and performs actions.
Expand All @@ -87,11 +84,13 @@ def retrieve_media(self, message: str, media_type: str = '', media_savepath: str
self.update_storage_info(message['data'])

# Create headers for accessing storage service
headers = self.create_headers(message['payload']['key'], message['source'])
headers = self.create_headers(
message['payload']['key'], message['source'])

try:
# Fetch data associated with the message from storage service
resp = requests.get(self.storage_uri + "/storage/blob", headers=headers, timeout=10)
resp = requests.get(self.storage_uri +
"/storage/blob", headers=headers, timeout=10)

if resp is None or resp.status_code != 200:
return requests.exceptions.RequestException('Failed to fetch data from storage')
Expand All @@ -104,11 +103,110 @@ def retrieve_media(self, message: str, media_type: str = '', media_savepath: str
# This creates a video-file in the data folder, containing the recording.
with open(media_savepath, 'wb') as output:
output.write(resp.content)

return resp


except Exception as x:
print('Error occurred while trying to fetch data from storage:')
print(x)
traceback.print_exc()
pass

def retrieve_media_url(self, message: str, media_type: str = ''):
""" Fetches associated data url from storage, and performs actions.

Parameters:
-----------
message : str
The message to be processed.
media_type : str
The type of message to be processed (image, video). Default is an empty string.
if type is 'video', the message is processed and video file is created. Filepath is returned.
else, the message response is returned.

"""

# Update storage-related information if available in message payload
if "data" in message:
self.update_storage_info(message['data'])

# Create headers for accessing storage service
headers = self.create_headers(
message['payload']['key'], message['source'])

try:
# Fetch data associated with the message from storage service
resp = requests.get(self.storage_uri + "/storage",
headers=headers, timeout=10)

if resp is None or resp.status_code != 200:
return requests.exceptions.RequestException('Failed to fetch data from storage')

elif media_type == 'image':
return NotImplementedError('media_type == image, needs to be implemented')

elif media_type == 'video':
return resp.content

except Exception as x:
print('Error occurred while trying to fetch data from storage:')
print(x)
traceback.print_exc()
pass

def retrieve_media_through_url(self, message: str, media_type: str = '', media_savepath: str = ''):
""" Fetches associated data from storage, and performs actions.

Parameters:
-----------
message : str
The message to be processed.
media_type : str
The type of message to be processed (image, video). Default is an empty string.
if type is 'video', the message is processed and video file is created. Filepath is returned.
else, the message response is returned.
media_savepath : str
The path where the media file is to be saved. Default is an empty string.

"""

# Update storage-related information if available in message payload
if "data" in message:
self.update_storage_info(message['data'])

# Create headers for accessing storage service
headers = self.create_headers(
message['payload']['key'], message['source'])

try:
# Fetch data associated with the message from storage service
resp = requests.get(self.storage_uri +
"/storage", headers=headers, timeout=10)

if resp is None or resp.status_code != 200:
return requests.exceptions.RequestException('Failed to fetch data from storage')

elif media_type == 'image':
return NotImplementedError('media_type == image, needs to be implemented')

elif media_type == 'video':
# We should have the url.
data = resp.json()
# Fetch the video file from the url.
if 'data' in data:
url = data['data']
if url:
respMedia = requests.get(url, timeout=10)
if respMedia is not None and respMedia.status_code == 200:
# From the received requested data, reconstruct a video-file.
# This creates a video-file in the data folder, containing the recording.
with open(media_savepath, 'wb') as output:
output.write(respMedia.content)

return resp

except Exception as x:
print('Error occurred while trying to fetch data from storage:')
print(x)
traceback.print_exc()
pass
pass
Loading