@@ -12,6 +12,8 @@ REPO_NAME="${INPUT_REPOSITORY_NAME:-${GITHUB_REPOSITORY##*/}}"
1212BRANCH=" ${INPUT_BRANCH:- ${GITHUB_REF_NAME:- main} } "
1313AUTH_TYPE=" ${INPUT_AUTH_TYPE:- http} "
1414GIT_TOKEN=" ${INPUT_GIT_TOKEN:- } "
15+ SSH_PRIVATE_KEY=" ${INPUT_SSH_PRIVATE_KEY:- } "
16+ SSH_HOST_KEY_VERIFICATION=" ${INPUT_SSH_HOST_KEY_VERIFICATION:- accept_new} "
1517AUTO_SYNC=" ${INPUT_AUTO_SYNC:- true} "
1618SYNC_INTERVAL=" ${INPUT_SYNC_INTERVAL:- 5} "
1719TRIGGER_SYNC=" ${INPUT_TRIGGER_SYNC:- true} "
@@ -20,6 +22,7 @@ ENV_VARS="${INPUT_ENV_VARS:-}"
2022# [C1/C2] Mask secrets immediately, before any logging or API calls
2123[[ -n " ${API_KEY} " ]] && echo " ::add-mask::${API_KEY} "
2224[[ -n " ${GIT_TOKEN} " ]] && echo " ::add-mask::${GIT_TOKEN} "
25+ [[ -n " ${SSH_PRIVATE_KEY} " ]] && echo " ::add-mask::${SSH_PRIVATE_KEY} "
2326
2427SYNCS_CREATED=0
2528SYNCS_UPDATED=0
@@ -196,7 +199,7 @@ ensure_repository() {
196199 if [[ -n " ${REPOSITORY_ID} " && " ${REPOSITORY_ID} " != " null" ]]; then
197200 log_info " Found existing repository: ${REPOSITORY_ID} "
198201
199- # Update credentials so the token stays current
202+ # Update credentials so they stay current
200203 if [[ " ${AUTH_TYPE} " == " http" && -n " ${GIT_TOKEN} " ]]; then
201204 local update_payload
202205 update_payload=$( jq -n \
@@ -206,6 +209,17 @@ ensure_repository() {
206209 arcane_api PUT " /customize/git-repositories/${REPOSITORY_ID} " \
207210 -d " ${update_payload} " > /dev/null
208211 log_info " Updated repository credentials"
212+ elif [[ " ${AUTH_TYPE} " == " ssh" && -n " ${SSH_PRIVATE_KEY} " ]]; then
213+ local update_payload
214+ update_payload=$( jq -n \
215+ --arg sshKey " ${SSH_PRIVATE_KEY} " \
216+ --arg username " git" \
217+ --arg sshHostKeyVerification " ${SSH_HOST_KEY_VERIFICATION} " \
218+ ' {sshKey: $sshKey, username: $username, sshHostKeyVerification: $sshHostKeyVerification}' )
219+
220+ arcane_api PUT " /customize/git-repositories/${REPOSITORY_ID} " \
221+ -d " ${update_payload} " > /dev/null
222+ log_info " Updated repository SSH credentials"
209223 fi
210224 else
211225 log_info " Creating new repository: ${REPO_NAME} "
@@ -218,6 +232,15 @@ ensure_repository() {
218232 --arg authType " ${AUTH_TYPE} " \
219233 --arg token " ${GIT_TOKEN} " \
220234 ' {name: $name, url: $url, authType: $authType, token: $token}' )
235+ elif [[ " ${AUTH_TYPE} " == " ssh" ]]; then
236+ create_payload=$( jq -n \
237+ --arg name " ${REPO_NAME} " \
238+ --arg url " ${REPO_URL} " \
239+ --arg authType " ${AUTH_TYPE} " \
240+ --arg sshKey " ${SSH_PRIVATE_KEY} " \
241+ --arg username " git" \
242+ --arg sshHostKeyVerification " ${SSH_HOST_KEY_VERIFICATION} " \
243+ ' {name: $name, url: $url, authType: $authType, sshKey: $sshKey, username: $username, sshHostKeyVerification: $sshHostKeyVerification}' )
221244 else
222245 create_payload=$( jq -n \
223246 --arg name " ${REPO_NAME} " \
@@ -379,9 +402,15 @@ if [[ "${AUTH_TYPE}" == "http" && -z "${GIT_TOKEN}" ]]; then
379402 exit 1
380403fi
381404
405+ # Validate ssh-private-key is set when auth-type is ssh
406+ if [[ " ${AUTH_TYPE} " == " ssh" && -z " ${SSH_PRIVATE_KEY} " ]]; then
407+ log_error " ssh-private-key is required when auth-type is ssh."
408+ exit 1
409+ fi
410+
382411# [H4] Reject unsupported auth-type values
383- if [[ " ${AUTH_TYPE} " != " none" && " ${AUTH_TYPE} " != " http" ]]; then
384- log_error " auth-type '${AUTH_TYPE} ' is not supported. Valid values: none, http."
412+ if [[ " ${AUTH_TYPE} " != " none" && " ${AUTH_TYPE} " != " http" && " ${AUTH_TYPE} " != " ssh " ]]; then
413+ log_error " auth-type '${AUTH_TYPE} ' is not supported. Valid values: none, http, ssh ."
385414 exit 1
386415fi
387416
0 commit comments