-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from uselagoon/ssh-in-config
Feat: Support for SSH key definition in configuration file
- Loading branch information
Showing
11 changed files
with
176 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package cmd | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func Test_generateSSHConnectionString(t *testing.T) { | ||
type args struct { | ||
project string | ||
environment string | ||
lagoon map[string]string | ||
service string | ||
container string | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want string | ||
}{ | ||
{ | ||
name: "test1 - no service or container", | ||
args: args{ | ||
lagoon: map[string]string{ | ||
"hostname": "lagoon.example.com", | ||
"port": "22", | ||
"username": "example-com-main", | ||
}, | ||
}, | ||
want: `ssh -t -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 22 [email protected]`, | ||
}, | ||
{ | ||
name: "test1 - service only, no container", | ||
args: args{ | ||
lagoon: map[string]string{ | ||
"hostname": "lagoon.example.com", | ||
"port": "22", | ||
"username": "example-com-main", | ||
}, | ||
service: "cli", | ||
}, | ||
want: `ssh -t -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 22 [email protected] service=cli`, | ||
}, | ||
{ | ||
name: "test3 - service and container", | ||
args: args{ | ||
lagoon: map[string]string{ | ||
"hostname": "lagoon.example.com", | ||
"port": "22", | ||
"username": "example-com-main", | ||
}, | ||
service: "nginx-php", | ||
container: "php", | ||
}, | ||
want: `ssh -t -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 22 [email protected] service=nginx-php container=php`, | ||
}, | ||
{ | ||
name: "test4", | ||
args: args{ | ||
lagoon: map[string]string{ | ||
"hostname": "lagoon.example.com", | ||
"port": "22", | ||
"username": "example-com-main", | ||
"sshKey": "/home/user/.ssh/my-key", | ||
}, | ||
service: "cli", | ||
container: "cli", | ||
}, | ||
want: `ssh -t /home/user/.ssh/my-key-o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 22 [email protected] service=cli container=cli`, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cmdProjectName = tt.args.project | ||
cmdProjectEnvironment = tt.args.environment | ||
|
||
if got := generateSSHConnectionString(tt.args.lagoon, tt.args.service, tt.args.container); got != tt.want { | ||
t.Errorf("generateSSHConnectionString() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.