Main

Proposers

  • name-of-proposer-1 (institution-of-proposer-1)
  • name-of-proposer-2 (institution-of-proposer-2) ...

Description

Describe your proposal in ~1000 characters. You can reference external content listed in section "References" as [Ref-1].

Demo or definition of done

Describe which high level conditions needs to be fulfilled to demonstrate this feature implementation is completed. You can reference external content (example, demo paper) listed in section "References" as [Ref-2].

References

  1. Reference name
  2. Author1, Author2, Author3, et. al., “My demo using feature,” in Conference-Name Demo Track, 20XX.

Acknowledgements

This work is funded by the European Commission through the project with Grant Agreement number . example: This work is funded by the European Commission through the FIDAL project with Grant Agreement number 101096146.

Merge request reports

Loading

.githooks/pre-push

0 → 100755
+25 −0
Changes for .githooks/pre-push: 25 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/sh
#
# pre-push hook to run 'make lint'
# If 'make lint' fails (exit code != 0), the push will be aborted.

echo "--- 🚀 Running 'make lint' before push ---"

# Run the linter
make fix

# Save the exit code of the last command
EXIT_CODE=$?

if [ $EXIT_CODE -ne 0 ]; then
    echo "-----------------------------------------------"
    echo "|        ⛔ The linter has failed! ⛔.        |"
    echo "|     Please fix the errors before pushing.   |"
    echo "-----------------------------------------------"
    exit 1 # Abort the push
fi

echo "--- ✅ Linter OK. ---"
echo "--- 🚀 Pushing... ---"

exit 0 # Allow the push
 No newline at end of file
+1 −1
Changes for ci_cd_test/testing_samples/testing_invoker_sample/capif_sdk_config_sample.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
{
  "capif_host": "capifcore",
  "register_host": "services-register-1",
  "register_host": "register",
  "capif_https_port": "443",
  "capif_register_port": "8080",
  "capif_username": "custom_user",
+1 −1
Changes for ci_cd_test/testing_samples/testing_provider_sample/testing_CICD_capif_sdk_config_sample.json: 1 added line, 1 removed line.
Original line number Diff line number Diff line
{
  "capif_host": "capifcore",
  "register_host": "services-register-1",
  "register_host": "register",
  "capif_https_port": "443",
  "capif_register_port": "8080",
  "capif_username": "custom_user",
+254 −0
Changes for ci_cd_test/prepare_capif_for_sdk.sh: 254 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/usr/bin/env bash
set -euo pipefail

# -----------------------------
# Config (override por env vars)
# -----------------------------
CAPIF_REPO_URL="${CAPIF_REPO_URL:-https://labs.etsi.org/rep/ocf/capif.git}"
CAPIF_BRANCH="${CAPIF_BRANCH:-staging}"
CAPIF_DIR="${CAPIF_DIR:-.capif}"

CAPIF_SERVICES_DIR="${CAPIF_SERVICES_DIR:-services}"
CAPIF_RUN_SCRIPT="${CAPIF_RUN_SCRIPT:-run.sh}"
CAPIF_CHECK_SCRIPT="${CAPIF_CHECK_SCRIPT:-check_services_are_running.sh}"

CAPIF_BASE_URL="${CAPIF_BASE_URL:-https://localhost:8084}"
LOGIN_URL="${LOGIN_URL:-$CAPIF_BASE_URL/login}"
CREATE_USER_URL="${CREATE_USER_URL:-$CAPIF_BASE_URL/createUser}"

ADMIN_USER="${ADMIN_USER:-admin}"
ADMIN_PASS="${ADMIN_PASS:-password123}"

NEW_USER="${NEW_USER:-custom_user}"
NEW_PASS="${NEW_PASS:-user_pass}"

WAIT_SECONDS="${WAIT_SECONDS:-300}"   # CAPIF puede tardar bastante
SLEEP_SECONDS="${SLEEP_SECONDS:-5}"

# -----------------------------
# Helpers
# -----------------------------
require() {
  command -v "$1" >/dev/null 2>&1 || { echo "❌ Missing dependency: $1" >&2; exit 1; }
}

json_get_access_token() {
  python3 -c 'import json,sys; 
raw=sys.stdin.read().strip()
try:
    data=json.loads(raw)
except Exception:
    print("", end=""); sys.exit(0)
print(data.get("access_token") or data.get("accessToken") or data.get("token") or "", end="")'
}

wait_for_services_ready() {
  local deadline=$(( $(date +%s) + WAIT_SECONDS ))

  echo "== Waiting for CAPIF services to be running (timeout ${WAIT_SECONDS}s) =="

  while true; do
    if bash "./$CAPIF_CHECK_SCRIPT" >/dev/null 2>&1; then
      echo "✅ CAPIF services are running"
      return 0
    fi

    if [ "$(date +%s)" -ge "$deadline" ]; then
      echo "❌ Timeout waiting for CAPIF services. Dumping status:" >&2
      # Intento dar algo de info útil (sin saber exactamente qué compose hay)
      (docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" || true) >&2
      echo "---- check_services_are_running.sh output ----" >&2
      (bash "./$CAPIF_CHECK_SCRIPT" || true) >&2
      return 1
    fi

    sleep "$SLEEP_SECONDS"
  done
}

wait_for_login_endpoint() {
  local deadline=$(( $(date +%s) + WAIT_SECONDS ))
  echo "== Waiting for API endpoint (POST): $LOGIN_URL (timeout ${WAIT_SECONDS}s) =="

  while true; do
    code="$(curl -ksS -o /dev/null -w "%{http_code}" -X POST "$LOGIN_URL" || true)"

    # “Vive” si responde a POST aunque sea con 400/401/403/415 (depende de la API)
    if [[ "$code" =~ ^(200|201|400|401|403|405|415)$ ]]; then
      echo "✅ Endpoint responds to POST (HTTP $code)"
      return 0
    fi

    if [ "$(date +%s)" -ge "$deadline" ]; then
      echo "❌ Timeout waiting for POST $LOGIN_URL (last HTTP $code)" >&2
      return 1
    fi

    sleep 2
  done
}

# -----------------------------
# Main
# -----------------------------
require git
require curl
require docker

if command -v python3 >/dev/null 2>&1; then
  PY=python3
elif command -v python >/dev/null 2>&1; then
  PY=python
else
  echo "❌ Missing dependency: python3/python" >&2
  exit 1
fi

# docker compose puede ser "docker compose" o "docker-compose"
if ! (docker compose version >/dev/null 2>&1 || command -v docker-compose >/dev/null 2>&1); then
  echo "❌ Missing dependency: docker compose (or docker-compose)" >&2
  exit 1
fi

echo "=============================="
echo " PREPARE CAPIF FOR SDK"
echo "=============================="
echo "Repo:        $CAPIF_REPO_URL"
echo "Branch:      $CAPIF_BRANCH"
echo "CAPIF dir:   $CAPIF_DIR"
echo "Services dir:$CAPIF_SERVICES_DIR"
echo "Base URL:    $CAPIF_BASE_URL"
echo ""

# 1) Clonar / actualizar CAPIF
if [ -d "$CAPIF_DIR/.git" ]; then
  echo "== Updating existing CAPIF repo at $CAPIF_DIR =="
  git -C "$CAPIF_DIR" fetch --all --prune
  git -C "$CAPIF_DIR" checkout "$CAPIF_BRANCH"
  git -C "$CAPIF_DIR" pull --ff-only origin "$CAPIF_BRANCH"
else
  echo "== Cloning CAPIF repo =="
  git clone --branch "$CAPIF_BRANCH" --single-branch "$CAPIF_REPO_URL" "$CAPIF_DIR"
fi

# 2) Entrar en /services y lanzar run.sh
echo "== Installing yq locally (no sudo) =="
YQ_BIN="$PWD/.bin"
mkdir -p "$YQ_BIN"
curl -Ls -o "$YQ_BIN/yq" "https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64"
chmod +x "$YQ_BIN/yq"
export PATH="$YQ_BIN:$PATH"
yq --version

SERV_DIR="$CAPIF_DIR/$CAPIF_SERVICES_DIR"
if [ ! -d "$SERV_DIR" ]; then
  echo "❌ Services dir not found: $SERV_DIR" >&2
  exit 1
fi

pushd "$SERV_DIR" >/dev/null

if [ ! -f "./$CAPIF_RUN_SCRIPT" ]; then
  echo "❌ run script not found: $SERV_DIR/$CAPIF_RUN_SCRIPT" >&2
  exit 1
fi
chmod +x "./$CAPIF_RUN_SCRIPT" "./$CAPIF_CHECK_SCRIPT" 2>/dev/null || true

echo "== Running CAPIF services: $SERV_DIR/$CAPIF_RUN_SCRIPT =="
# Importante: run.sh puede tardar y puede fallar si no está todo running aún.
# Así que no abortamos aquí: lo seguimos con un wait loop.
set +e
bash "./$CAPIF_RUN_SCRIPT"
RUN_RC=$?
set -e

if [ "$RUN_RC" -ne 0 ]; then
  echo "⚠️ run.sh returned non-zero ($RUN_RC). We'll still wait/retry until services are running..."
fi

# 3) Esperar a que check_services_are_running.sh diga OK
wait_for_services_ready

popd >/dev/null

# 4) Esperar también a que el endpoint /login responda (doble garantía)
wait_for_login_endpoint

# 5) Login admin -> token (Basic Auth admin:password123)
echo "== Login as admin to get access token =="

tmp="$(mktemp)"
code="$(curl -ksS -o "$tmp" -w "%{http_code}" \
  -X POST "$LOGIN_URL" \
  -u "${ADMIN_USER}:${ADMIN_PASS}" \
  -H "Accept: application/json" || true)"

LOGIN_RESP="$(cat "$tmp")"
rm -f "$tmp"

echo "Login HTTP: $code"
echo "Login body (first 200 chars):"
echo "$LOGIN_RESP" | head -c 200; echo ""

if [[ "$code" != "200" && "$code" != "201" ]]; then
  echo "❌ /login failed (HTTP $code). Full body:" >&2
  echo "$LOGIN_RESP" >&2
  exit 1
fi

# Si no parece JSON, aborta con body
if [[ "$LOGIN_RESP" != \{* ]]; then
  echo "❌ /login did not return JSON. Full body:" >&2
  echo "$LOGIN_RESP" >&2
  exit 1
fi

TOKEN="$(printf "%s" "$LOGIN_RESP" | json_get_access_token)"

if [ -z "$TOKEN" ]; then
  echo "❌ Could not extract access token from /login response." >&2
  echo "Response was:" >&2
  echo "$LOGIN_RESP" >&2
  exit 1
fi
echo "✅ Got access token (len=${#TOKEN})"

# 6) Create user
echo "== Creating user '$NEW_USER' =="
CREATE_PAYLOAD="$(cat <<JSON
{
  "username": "$NEW_USER",
  "password": "$NEW_PASS",
  "enterprise": "ETSI",
  "country": "Spain",
  "email": "example@gmail.com",
  "purpose": "Use OpenCAPIF",
  "phone_number": "+123456789",
  "company_web": "www.etsi.com",
  "description": "UserDescription"
}
JSON
)"

CREATE_RESP="$(curl -ksS -X POST "$CREATE_USER_URL" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKEN" \
  --data-raw "$CREATE_PAYLOAD" \
  -w "\nHTTP_STATUS=%{http_code}\n")"

echo "$CREATE_RESP" | sed -n '1,160p'
STATUS="$(echo "$CREATE_RESP" | sed -n 's/^HTTP_STATUS=\([0-9][0-9][0-9]\)$/\1/p' | tail -n1)"

if [ "$STATUS" != "200" ] && [ "$STATUS" != "201" ] && [ "$STATUS" != "409" ]; then
  echo "❌ createUser failed (HTTP $STATUS)" >&2
  exit 1
fi

if [ "$STATUS" = "409" ]; then
  echo "⚠️ User already exists (HTTP 409). Continuing."
else
  echo "✅ User created (HTTP $STATUS)."
fi

echo ""
echo "✅ CAPIF prepared successfully."
 No newline at end of file
+1 −0
Changes for installation/requirements.txt: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -31,3 +31,4 @@ coverage>=7.4.0,<8
flake8>=7.1.0,<8
binaryornot>=0.4.4,<0.5
jinja2-time==0.2.0
ruff==0.9.5
Loading
Loading