Skip to content

Commit 1d96c77

Browse files
cory-millerjoshmgross
andauthoredApr 18, 2024
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 <joshmgross@github.com> * Update action.yml Co-authored-by: Josh Gross <joshmgross@github.com> * Update genfiles --------- Co-authored-by: Josh Gross <joshmgross@github.com>
1 parent cd7d8d6 commit 1d96c77

7 files changed

+21
-2
lines changed
 

‎README.md

+5
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ Please refer to the [release page](https://github.com/actions/checkout/releases/
6262
# Default: true
6363
ssh-strict: ''
6464

65+
# The user to use when connecting to the remote SSH host. By default 'git' is
66+
# used.
67+
# Default: git
68+
ssh-user: ''
69+
6570
# Whether to configure the token or SSH key with the local git config
6671
# Default: true
6772
persist-credentials: ''

‎__test__/git-auth-helper.test.ts

+1
Original file line numberDiff line numberDiff line change
@@ -821,6 +821,7 @@ async function setup(testName: string): Promise<void> {
821821
sshKey: sshPath ? 'some ssh private key' : '',
822822
sshKnownHosts: '',
823823
sshStrict: true,
824+
sshUser: '',
824825
workflowOrganizationId: 123456,
825826
setSafeDirectory: true,
826827
githubServerUrl: githubServerUrl

‎action.yml

+4
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ inputs:
4545
and `CheckHostIP=no` to the SSH command line. Use the input `ssh-known-hosts` to
4646
configure additional hosts.
4747
default: true
48+
ssh-user:
49+
description: >
50+
The user to use when connecting to the remote SSH host. By default 'git' is used.
51+
default: git
4852
persist-credentials:
4953
description: 'Whether to configure the token or SSH key with the local git config'
5054
default: true

‎dist/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1798,6 +1798,7 @@ function getInputs() {
17981798
result.sshKnownHosts = core.getInput('ssh-known-hosts');
17991799
result.sshStrict =
18001800
(core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE';
1801+
result.sshUser = core.getInput('ssh-user');
18011802
// Persist credentials
18021803
result.persistCredentials =
18031804
(core.getInput('persist-credentials') || 'false').toUpperCase() === 'TRUE';
@@ -2400,7 +2401,8 @@ function getFetchUrl(settings) {
24002401
const encodedOwner = encodeURIComponent(settings.repositoryOwner);
24012402
const encodedName = encodeURIComponent(settings.repositoryName);
24022403
if (settings.sshKey) {
2403-
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
2404+
const user = settings.sshUser.length > 0 ? settings.sshUser : 'git';
2405+
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`;
24042406
}
24052407
// "origin" is SCHEME://HOSTNAME[:PORT]
24062408
return `${serviceUrl.origin}/${encodedOwner}/${encodedName}`;

‎src/git-source-settings.ts

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export interface IGitSourceSettings {
9494
*/
9595
sshStrict: boolean
9696

97+
/**
98+
* The SSH user to login as
99+
*/
100+
sshUser: string
101+
97102
/**
98103
* Indicates whether to persist the credentials on disk to enable scripting authenticated git commands
99104
*/

‎src/input-helper.ts

+1
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ export async function getInputs(): Promise<IGitSourceSettings> {
143143
result.sshKnownHosts = core.getInput('ssh-known-hosts')
144144
result.sshStrict =
145145
(core.getInput('ssh-strict') || 'true').toUpperCase() === 'TRUE'
146+
result.sshUser = core.getInput('ssh-user')
146147

147148
// Persist credentials
148149
result.persistCredentials =

‎src/url-helper.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export function getFetchUrl(settings: IGitSourceSettings): string {
1212
const encodedOwner = encodeURIComponent(settings.repositoryOwner)
1313
const encodedName = encodeURIComponent(settings.repositoryName)
1414
if (settings.sshKey) {
15-
return `git@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
15+
const user = settings.sshUser.length > 0 ? settings.sshUser : 'git'
16+
return `${user}@${serviceUrl.hostname}:${encodedOwner}/${encodedName}.git`
1617
}
1718

1819
// "origin" is SCHEME://HOSTNAME[:PORT]

0 commit comments

Comments
 (0)
Failed to load comments.