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

scripts: nit support 'short' certificate uploading #288

Merged
merged 1 commit into from
Nov 19, 2024
Merged
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
37 changes: 21 additions & 16 deletions scripts/upload-certs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ set -o pipefail # don’t hide errors within pipes

# Function to display usage information
usage() {
echo "Usage: $0 [options] <orb-id> <keypath>
options:
echo "Usage: $0 [OPTIONS] <orb-id> <keypath>

Options:
-h, --help Display this help message
-t, --token <bearer> Bearer token for authentication.
-b, --backend (stage|prod) Targets the stage or prod backend.
-s, --short Short upload (skip attestation cert).

Environment variables (overriden by options):
FM_CLI_ENV: Must be either 'stage' or 'prod'.
Expand All @@ -33,6 +35,7 @@ main() {
local bearer="${FM_CLI_ORB_AUTH_INTERNAL_TOKEN:-""}"
local backend="${FM_CLI_ENV:-""}"
local positional_args=()
local short=false
local arg
while [[ "$#" -gt 0 ]]; do
arg="${1}"; shift
Expand All @@ -43,6 +46,8 @@ main() {
bearer="${1}"; shift ;;
-b|--backend)
backend="${1}"; shift ;;
-s|--short)
short=true ;;
-*)
echo "Unknown option: ${arg}"
usage; exit 1 ;;
Expand Down Expand Up @@ -92,26 +97,24 @@ main() {
exit 1
fi

local certificate
certificate=$(sed 's/$/\\n/' "${keypath}/f0000013.cert" | tr -d \\n)
local signup_pubkey
signup_pubkey=$(sed 's/$/\\n/' "${keypath}/sss_70000002_0002_0040.bin" | tr -d \\n)
local attestation_pubkey
attestation_pubkey=$(sed 's/$/\\n/' "${keypath}/sss_70000001_0002_0040.bin" | tr -d \\n)

# Get Cloudflared token
echo "Getting Cloudflared access token..."
local cf_token
cf_token="$(get_cloudflared_token "${domain}")"

# Post certificate
curl --fail --location \
-H "Authorization: Bearer ${bearer}" \
-H "cf-access-token: ${cf_token}" \
-X POST "https://${domain}/api/v1/certificate" \
-d '{ "orbId": "'"${orb_id}"'", "certificate": "'"${certificate}"'" }'
# Post attestation certificate
if [[ ! "${short}" ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another usage feedback that I had is that a lot of times dir name is the orb-id, so we don't need to provide that explicitely. We can use that in next script that combines both copy/upload.

local certificate
certificate=$(sed 's/$/\\n/' "${keypath}/f0000013.cert" | tr -d \\n)
curl --fail --location \
-H "Authorization: Bearer ${bearer}" \
-H "cf-access-token: ${cf_token}" \
-X POST "https://${domain}/api/v1/certificate" \
-d '{ "orbId": "'"${orb_id}"'", "certificate": "'"${certificate}"'" }'
fi

# Post signup key
local signup_pubkey
signup_pubkey=$(sed 's/$/\\n/' "${keypath}/sss_70000002_0002_0040.bin" | tr -d \\n)
curl --fail --location \
-H "Authorization: Bearer ${bearer}" \
-H "cf-access-token: ${cf_token}" \
Expand All @@ -125,6 +128,8 @@ main() {
}'

# Post attestation key
local attestation_pubkey
attestation_pubkey=$(sed 's/$/\\n/' "${keypath}/sss_70000001_0002_0040.bin" | tr -d \\n)
curl --fail --location \
-H "Authorization: Bearer ${bearer}" \
-H "cf-access-token: ${cf_token}" \
Expand Down
Loading