Skip to content

Commit

Permalink
Merge pull request #243 from QCDIS/242-add-secret-creation-endpoint
Browse files Browse the repository at this point in the history
add secret creation endpoint
  • Loading branch information
gpelouze authored May 28, 2024
2 parents 81003f7 + 15f97f9 commit da0c161
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
2 changes: 2 additions & 0 deletions vreapis/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ services:
- ALLOWED_HOST=*
- ARGO_NAMESPACE=
- ARGO_URL=
- K8S_SECRET_CREATOR_URL=
- K8S_SECRET_CREATOR_TOKEN=
- BASE_PATH=/vre-api-test
- CALL_BACK_URL=
- CORS_ALLOWED_ORIGIN_REGEXES=
Expand Down
32 changes: 32 additions & 0 deletions vreapis/services/k8s_secret_creator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import json
import logging
import os

import requests

from django.conf import settings


logger = logging.getLogger(__name__)


class K8sSecretCreator:
def __init__(self):
self.url = os.environ['K8S_SECRET_CREATOR_URL']
self.token = os.environ['K8S_SECRET_CREATOR_TOKEN']

def create_secret(self, data):
resp = requests.post(
self.url,
verify=(not settings.ALLOW_INSECURE_TLS),
headers={
'accept': 'application/json',
'Content-Type': 'application/json',
'X-Auth': self.token,
},
data=json.dumps(data),
)
if resp.status_code != 200:
logger.error(f"Secret submission failed: {resp.json()}")
resp.raise_for_status()
return resp.json()
12 changes: 12 additions & 0 deletions vreapis/workflows/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from rest_framework.permissions import IsAuthenticated

from services.argo import ArgoWorkflow
from services.k8s_secret_creator import K8sSecretCreator
from virtual_labs.models import VirtualLab
from vreapis.views import GetSerializerMixin

Expand Down Expand Up @@ -127,3 +128,14 @@ def submit(self, request, *args, **kwargs):
status=500)

return Response(new_workflow.data)

@action(detail=False, methods=['POST'], name='Create a workflow secret')
def create_secret(self, request, *args, **kwargs):
try:
return Response(K8sSecretCreator().create_secret(request.data))
except Exception as e:
return Response(
{
'message': 'Could not create secret',
},
status=500)

0 comments on commit da0c161

Please sign in to comment.