From 4633477603c1d5195d6b3e1a1a30626d2b3e50d3 Mon Sep 17 00:00:00 2001 From: Cory Miller <13227161+cory-miller@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:29:55 -0400 Subject: Add SSH user parameter (#1685) * Add a configurable SSH user * Update docs with param * Indentation of readme * formatting woes * Update src/url-helper.ts Co-authored-by: Josh Gross * Update action.yml Co-authored-by: Josh Gross * Update genfiles --------- Co-authored-by: Josh Gross --- src/git-source-settings.ts | 5 +++++ src/input-helper.ts | 1 + src/url-helper.ts | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/git-source-settings.ts b/src/git-source-settings.ts index 629350b..4e41ac3 100644 --- a/src/git-source-settings.ts +++ b/src/git-source-settings.ts @@ -94,6 +94,11 @@ export interface IGitSourceSettings { */ sshStrict: boolean + /** + * The SSH user to login as + */ + sshUser: string + /** * Indicates whether to persist the credentials on disk to enable scripting authenticated git commands */ diff --git a/src/input-helper.ts b/src/input-helper.ts index e546c19..e230a55 100644 --- a/src/input-helper.ts +++ b/src/input-helper.ts @@ -143,6 +143,7 @@ export async function getInputs(): Promise { result.sshKnownHosts = core.getInput('ssh-known-hosts') result.sshStrict = (core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE' + result.sshUser = core.getInput('ssh-user') // Persist credentials result.persistCredentials = diff --git a/src/url-helper.ts b/src/url-helper.ts index 6807b7f..64ecbf3 100644 --- a/src/url-helper.ts +++ b/src/url-helper.ts @@ -12,7 +12,8 @@ export function getFetchUrl(settings: IGitSourceSettings): string { const encodedOwner = encodeURIComponent(settings.repositoryOwner) const encodedName = encodeURIComponent(settings.repositoryName) if (settings.sshKey) { - return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` + const user = settings.sshUser.length > 0 ? settings.sshUser : 'git' + return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git` } // "origin" is SCHEME://HOSTNAME[:PORT] -- cgit v1.2.3