Skip to content

Commit

Permalink
adding docs directory, and setting up modules
Browse files Browse the repository at this point in the history
  • Loading branch information
telliere committed Mar 25, 2024
1 parent 6b59c47 commit d9ea9cb
Show file tree
Hide file tree
Showing 33 changed files with 170 additions and 58 deletions.
Empty file added client/__init__.py
Empty file.
Empty file.
Empty file.
2 changes: 1 addition & 1 deletion client/container_preparation/lib/image_build.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from dockerfile_parse import DockerfileParser
import os, sys
from tools.docker.docker_utils import build_build_env, check_build_env_exists
from client.container_preparation.tools.docker.docker_utils import build_build_env, check_build_env_exists

sys.path.append(os.path.expanduser("../../../")) # For cli usage
sys.path.append(os.path.expanduser("../../")) # For inside-container usage
Expand Down
6 changes: 3 additions & 3 deletions client/container_preparation/prepare_container.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from tools.docker.docker_utils import check_docker_socket_access
from lib.image_build import build_prepared_image, create_sif_image
from tools.cli.cli import parse_arguments
from client.container_preparation.tools.docker.docker_utils import check_docker_socket_access
from client.container_preparation.lib.image_build import build_prepared_image, create_sif_image
from client.container_preparation.tools.cli.cli import parse_arguments
from docker import DockerClient


Expand Down
Empty file.
Empty file.
1 change: 0 additions & 1 deletion client/container_preparation/tools/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import argparse


# Parse arguments from the cli
def parse_arguments() -> argparse.ArgumentParser:
"""Parse arguments from the cli
Expand Down
Empty file.
Empty file.
Empty file.
3 changes: 1 addition & 2 deletions client/data_preparation/prepare_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from tools.cli.cli import parse_arguments
from tools.utils import check_arguments
from client.data_preparation.tools.cli.cli import parse_arguments, check_arguments
from pyrage import x25519, encrypt
from os import path, remove
import tarfile
Expand Down
Empty file.
Empty file.
27 changes: 26 additions & 1 deletion client/data_preparation/tools/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse

from os.path import isfile, isdir

# Parse arguments from the cli
def parse_arguments() -> argparse.ArgumentParser:
Expand All @@ -22,3 +22,28 @@ def parse_arguments() -> argparse.ArgumentParser:
)

return parser.parse_args()

def check_arguments(input_path: str, output_path: str) -> bool:
"""Check cli arguments for data preparation and check wether or not input is a file
Args:
input_path (str): Path to the input file or directory
output_path (str): Path to the output directory
Returns:
bool: Wether or not the input is a file
"""

# Check input path exists, store wether it's a file or a directory
try:
input_is_file = isfile(input_path)
except FileNotFoundError:
print(f"File {input_path} doesn't exist.")

# Check output path exists, and it's a directory
try:
isdir(input_path)
except FileNotFoundError:
print(f"Directory {output_path} doesn't exist.")

return input_is_file
27 changes: 0 additions & 27 deletions client/data_preparation/tools/utils.py

This file was deleted.

Empty file.
Empty file.
10 changes: 3 additions & 7 deletions client/job_preparation/prepare_job.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
from utils.cli.cli import parse_arguments, check_arguments
from lib.sbatch_generation import sbatch_from_template
from lib.info_file import get_info_from_infofile
import sys, os

sys.path.append(os.path.expanduser("../../../")) # For cli usage
sys.path.append(os.path.expanduser("../../")) # For inside-container usage
from client.job_preparation.utils.cli.cli import parse_arguments, check_arguments
from client.job_preparation.lib.sbatch_generation import sbatch_from_template
from client.job_preparation.lib.info_file import get_info_from_infofile
from utils.ssh_utils import ssh_connect, ssh_copy_file, ssh_run_command
from utils.conf.client.conf import parse_configuration
from time import sleep
Expand Down
Empty file.
Empty file.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
31 changes: 31 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

import sys, os
sys.path.insert(0, os.path.abspath('..'))

project = 'HPCS'
copyright = '2024, Martin Matthiesen, Emilien Tellier'
author = 'Martin Matthiesen, Emilien Tellier'
release = '0.1.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.todo', 'sphinx.ext.viewcode', 'sphinx.ext.autodoc']

templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'alabaster'
html_static_path = ['_static']
22 changes: 22 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.. HPCS documentation master file, created by
sphinx-quickstart on Tue Mar 19 13:07:16 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
Welcome to HPCS's documentation!
================================

.. toctree::
:maxdepth: 2
:caption: Contents:

modules



Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Empty file added server/__init__.py
Empty file.
15 changes: 9 additions & 6 deletions server/app.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import hashlib, sys, os
import hashlib
from quart import Quart, jsonify, request
from lib.spire_interactions import (
from pyspiffe.spiffe_id.spiffe_id import SpiffeId

from server.lib.spire_interactions import (
connect_workload_api,
token_generate,
entry_create,
get_server_identity_JWT,
validate_client_JWT_SVID,
)
from lib import spire_interactions
from tools.docker_utils import get_build_env_image_digests
from server.lib import spire_interactions
from server.tools.docker_utils import get_build_env_image_digests
from pyspiffe.spiffe_id.spiffe_id import SpiffeId

from tools.config.config import parse_configuration
from tools.cli.cli import parse_arguments
from server.tools.config.config import parse_configuration
from server.tools.cli.cli import parse_arguments
from utils.vault.vault_utils import (
vault_login,
write_client_policy,
Expand Down
Empty file added server/lib/__init__.py
Empty file.
16 changes: 11 additions & 5 deletions server/lib/spire_interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,11 @@ def entry_create(
return subprocess.run(command, capture_output=True)


def get_server_identity_JWT() -> JwtSvid:
def get_server_identity_JWT(JwtSource : default_jwt_source.DefaultJwtSource) -> JwtSvid:
"""Get jwt SVID of the server
Args:
JwtSource (default_jwt_source.DefaultJwtSource): connection to the spire agent workload api
Returns:
JwtSvid: the SVID
"""
Expand All @@ -82,28 +84,32 @@ def get_server_identity_JWT() -> JwtSvid:
return SVID


def validate_JWT_SVID(JwtSVID: str) -> JwtSvid:
def validate_JWT_SVID(JwtSource : default_jwt_source.DefaultJwtSource, JwtSVID: str) -> JwtSvid:
"""Validate a provided JWT SVID against spire-agent
Args:
JwtSource (default_jwt_source.DefaultJwtSource): connection to the spire agent workload api
Returns:
JwtSvid: parsed and validated SVID
"""
return jwt_workload_api._workload_api_client.validate_jwt_svid(
return JwtSource._workload_api_client.validate_jwt_svid(
JwtSVID, audience="TESTING"
)


def validate_client_JWT_SVID(JwtSVID: str, client_id: str) -> bool:
def validate_client_JWT_SVID(JwtSource : default_jwt_source.DefaultJwtSource, JwtSVID: str, client_id: str) -> bool:
"""Validate a client JWT, same as `validate_JWT_SVID` plus client_id verification
Args:
JwtSource (default_jwt_source.DefaultJwtSource): connection to the spire agent workload api
JwtSVID (str): the client's JWT SVID
client_id (str): the client's id
Returns:
bool: JWT SVID is valide and matches client id or not
"""
SVID = validate_JWT_SVID(JwtSVID)
SVID = validate_JWT_SVID(JwtSource, JwtSVID)
if str(SVID.spiffe_id).split("/")[-2] != client_id:
return False
return True
Empty file added server/tools/__init__.py
Empty file.
Empty file added utils/__init__.py
Empty file.
13 changes: 8 additions & 5 deletions utils/ship_a_key.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import argparse
import requests
import yaml

from re import search
from os import path

from pyspiffe.workloadapi import default_jwt_source, default_workload_api_client
from pyspiffe.spiffe_id import spiffe_id
from pyspiffe.exceptions import SpiffeIdError
from pyspiffe.svid.jwt_svid import JwtSvid
import requests
from vault.vault_utils import vault_login, write_secret
import yaml
from hashlib import sha512
from ssh_utils import ssh_connect, ssh_copy_file
from conf.client.conf import parse_configuration

from utils.vault.vault_utils import vault_login, write_secret
from utils.ssh_utils import ssh_connect, ssh_copy_file
from utils.conf.client.conf import parse_configuration

# Provide client_id from cli$
# Same for trust domain
Expand Down
Empty file added utils/vault/__init__.py
Empty file.

0 comments on commit d9ea9cb

Please sign in to comment.