#!/bin/bash

# Fetch the prepared authority ID
prepared_authority=$(docker compose exec -t root-server \
    /opt/spire/bin/spire-server \
    localauthority x509 show -output json | jq -r .prepared.authority_id) || fail-now "Failed to fetch prepared authority ID"

# Activate the authority
activated_authority=$(docker compose exec -t root-server \
    /opt/spire/bin/spire-server \
    localauthority x509 activate -authorityID "${prepared_authority}" \
    -output json | jq -r .activated_authority.authority_id) || fail-now "Failed to activate authority"

log-info "Activated authority: ${activated_authority}"

# Check logs for specific lines
check-log-line root-server "X509 CA activated|local_authority_id=${prepared_authority}"
check-log-line root-server "Successfully rotated X\.509 CA"
