.  ./.gh-api-examples.conf

# https://docs.github.com/en/enterprise-cloud@latest/rest/actions/secrets?apiVersion=2022-11-28#create-or-update-an-organization-secret
# PUT /orgs/{org}/actions/secrets/{secret_name}


secret_name=${org_secret_name}
visibility="all"
key_id=$(./get-an-organization-public-key.sh | jq -r '.key_id')
org_public_key=$(./get-an-organization-public-key.sh | jq -r '.key')
encrypted_value=$(ruby create-an-organization-secret-helper.rb ${org_public_key})

json_file=tmp/organization-secret.json
jq -n \
           --arg secret_name "${secret_name}" \
           --arg key_id "${key_id}" \
           --arg visibility "${visibility}" \
           --arg encrypted_value "${encrypted_value}" \
           '{
             secret_name: $secret_name,
             key_id: $key_id,
             visibility: $visibility,
             encrypted_value: $encrypted_value
           }' > ${json_file}


curl ${curl_custom_flags} \
     -X PUT \
     -H "Accept: application/vnd.github.v3+json" \
     -H "Authorization: Bearer ${GITHUB_TOKEN}" \
        "${GITHUB_API_BASE_URL}/orgs/${org}/actions/secrets/${secret_name}" --data @${json_file}

