diff options
| -rw-r--r-- | README.md | 5 | ||||
| -rw-r--r-- | __test__/git-auth-helper.test.ts | 1 | ||||
| -rw-r--r-- | action.yml | 4 | ||||
| -rw-r--r-- | dist/index.js | 4 | ||||
| -rw-r--r-- | src/git-source-settings.ts | 5 | ||||
| -rw-r--r-- | src/input-helper.ts | 1 | ||||
| -rw-r--r-- | src/url-helper.ts | 3 |
7 files changed, 21 insertions, 2 deletions
@@ -62,6 +62,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/ # Default: true ssh-strict: '' + # The user to use when connecting to the remote SSH host. By default 'git' is + # used. + # Default: git + ssh-user: '' + # Whether to configure the token or SSH key with the local git config # Default: true persist-credentials: '' diff --git a/__test__/git-auth-helper.test.ts b/__test__/git-auth-helper.test.ts index 4081cb1..694c0ba 100644 --- a/__test__/git-auth-helper.test.ts +++ b/__test__/git-auth-helper.test.ts @@ -821,6 +821,7 @@ async function setup(testName: string): Promise<void> { sshKey: sshPath ? 'some ssh private key' : '', sshKnownHosts: '', sshStrict: true, + sshUser: '', workflowOrganizationId: 123456, setSafeDirectory: true, githubServerUrl: githubServerUrl @@ -45,6 +45,10 @@ inputs: and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
configure additional hosts.
default: true
+ ssh-user:
+ description: >
+ The user to use when connecting to the remote SSH host. By default 'git' is used.
+ default: git
persist-credentials:
description: 'Whether to configure the token or SSH key with the local git config'
default: true
diff --git a/dist/index.js b/dist/index.js index 35f6780..b210247 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1798,6 +1798,7 @@ function getInputs() { 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 = (core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE'; @@ -2400,7 +2401,8 @@ function getFetchUrl(settings) { 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] return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`; 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 @@ -95,6 +95,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 */ persistCredentials: boolean 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<IGitSourceSettings> { 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] |
