Skip to content

Commit

Permalink
Updated to machinery v0.0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
CGoodwin90 committed Nov 28, 2023
2 parents 7b29cb2 + 5ce8a2a commit d8b732b
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 35 deletions.
8 changes: 7 additions & 1 deletion cmd/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"context"
"fmt"
s "github.com/uselagoon/machinery/api/schema"

Check failure on line 6 in cmd/environment.go

View workflow job for this annotation

GitHub Actions / goreleaser (1.16)

missing go.sum entry for module providing package github.com/uselagoon/machinery/api/schema (imported by github.com/uselagoon/lagoon-cli/cmd); to add:
"os"
"strings"

Expand All @@ -13,7 +14,6 @@ import (
"github.com/uselagoon/lagoon-cli/pkg/output"
l "github.com/uselagoon/machinery/api/lagoon"
lclient "github.com/uselagoon/machinery/api/lagoon/client"

Check failure on line 16 in cmd/environment.go

View workflow job for this annotation

GitHub Actions / goreleaser (1.16)

missing go.sum entry for module providing package github.com/uselagoon/machinery/api/lagoon/client (imported by github.com/uselagoon/lagoon-cli/cmd); to add:
s "github.com/uselagoon/machinery/api/schema"
)

// @TODO re-enable this at some point if more environment based commands are made available
Expand Down Expand Up @@ -131,10 +131,16 @@ var updateEnvironmentCmd = &cobra.Command{
}
if environmentType != "" {
envType := s.EnvType(strings.ToUpper(environmentType))
if validationErr := s.ValidateType(envType); validationErr != nil {
handleError(validationErr)
}
environmentFlags.EnvironmentType = &envType
}
if deployT != "" {
deployType := s.DeployType(strings.ToUpper(deployT))
if validationErr := s.ValidateType(deployType); validationErr != nil {
handleError(validationErr)
}
environmentFlags.DeployType = &deployType
}

Expand Down
16 changes: 8 additions & 8 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,17 +287,10 @@ var listVariablesCmd = &cobra.Command{
env = append(env, returnNonEmptyString(fmt.Sprintf("%v", envvar.Scope)))
env = append(env, returnNonEmptyString(fmt.Sprintf("%v", envvar.Name)))
if reveal {
env = append(env, returnNonEmptyString(fmt.Sprintf("%v", envvar.Value)))
env = append(env, fmt.Sprintf("%v", envvar.Value))
}
data = append(data, env)
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
return fmt.Errorf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName)
} else {
return fmt.Errorf("There are no variables for project '%s'", cmdProjectName)
}
}
header := []string{
"ID",
"Project",
Expand All @@ -310,6 +303,13 @@ var listVariablesCmd = &cobra.Command{
if reveal {
header = append(header, "Value")
}
if len(data) == 0 {
if cmdProjectEnvironment != "" {
outputOptions.Error = fmt.Sprintf("There are no variables for environment '%s' in project '%s'", cmdProjectEnvironment, cmdProjectName)
} else {
outputOptions.Error = fmt.Sprintf("There are no variables for project '%s'\n", cmdProjectName)
}
}
output.RenderOutput(output.Table{
Header: header,
Data: data,
Expand Down
53 changes: 30 additions & 23 deletions cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,28 @@ var sshEnvCmd = &cobra.Command{
// set the default ssh host and port to the core ssh endpoint
sshHost := lagoonCLIConfig.Lagoons[current].HostName
sshPort := lagoonCLIConfig.Lagoons[current].Port
isPortal := false

// if the config for this lagoon is set to use ssh portal support, handle that here
if lagoonCLIConfig.Lagoons[current].SSHPortal {
lc := client.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
debug)
project, err := lagoon.GetSSHEndpointsByProject(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
// check all the environments for this project
for _, env := range project.Environments {
// if the env name matches the requested environment then check if the deploytarget supports regional ssh endpoints
if env.Name == environmentName {
// if the deploytarget supports regional endpoints, then set these as the host and port for ssh
if env.DeployTarget.SSHHost != "" && env.DeployTarget.SSHPort != "" {
sshHost = env.DeployTarget.SSHHost
sshPort = env.DeployTarget.SSHPort
}
lc := client.New(
lagoonCLIConfig.Lagoons[current].GraphQL,
lagoonCLIConfig.Lagoons[current].Token,
lagoonCLIConfig.Lagoons[current].Version,
lagoonCLIVersion,
debug)
project, err := lagoon.GetSSHEndpointsByProject(context.TODO(), cmdProjectName, lc)
if err != nil {
return err
}
// check all the environments for this project
for _, env := range project.Environments {
// if the env name matches the requested environment then check if the deploytarget supports regional ssh endpoints
if env.Name == environmentName {
// if the deploytarget supports regional endpoints, then set these as the host and port for ssh
if env.DeployTarget.SSHHost != "" && env.DeployTarget.SSHPort != "" {
sshHost = env.DeployTarget.SSHHost
sshPort = env.DeployTarget.SSHPort
isPortal = true
}
}
}
Expand All @@ -88,7 +88,7 @@ var sshEnvCmd = &cobra.Command{
"sshkey": privateKey,
}
if sshConnString {
fmt.Println(generateSSHConnectionString(sshConfig, sshService, sshContainer))
fmt.Println(generateSSHConnectionString(sshConfig, sshService, sshContainer, isPortal))
} else {

// start an interactive ssh session
Expand Down Expand Up @@ -127,8 +127,15 @@ func init() {
}

// generateSSHConnectionString .
func generateSSHConnectionString(lagoon map[string]string, service string, container string) string {
connString := fmt.Sprintf("ssh -t %s-o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\" -p %v %s@%s", lagoon["sshKey"], lagoon["port"], lagoon["username"], lagoon["hostname"])
func generateSSHConnectionString(lagoon map[string]string, service string, container string, isPortal bool) string {
connString := fmt.Sprintf("ssh -t")
if lagoon["sshKey"] != "" {
connString = fmt.Sprintf("%s -i %s", connString, lagoon["sshKey"])
}
if !isPortal {
connString = fmt.Sprintf("%s -o \"UserKnownHostsFile=/dev/null\" -o \"StrictHostKeyChecking=no\"", connString)
}
connString = fmt.Sprintf("%s -p %v %s@%s", connString, lagoon["port"], lagoon["username"], lagoon["hostname"])
if service != "" {
connString = fmt.Sprintf("%s service=%s", connString, service)
}
Expand Down
34 changes: 32 additions & 2 deletions cmd/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func Test_generateSSHConnectionString(t *testing.T) {
lagoon map[string]string
service string
container string
isPortal bool
}
tests := []struct {
name string
Expand Down Expand Up @@ -65,15 +66,44 @@ func Test_generateSSHConnectionString(t *testing.T) {
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`,
want: `ssh -t -i /home/user/.ssh/my-key -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -p 22 [email protected] service=cli container=cli`,
},
{
name: "test5 - sshportal",
args: args{
lagoon: map[string]string{
"hostname": "lagoon.example.com",
"port": "22",
"username": "example-com-main",
"sshKey": "/home/user/.ssh/my-key",
},
isPortal: true,
service: "cli",
container: "cli",
},
want: `ssh -t -i /home/user/.ssh/my-key -p 22 [email protected] service=cli container=cli`,
},
{
name: "test6 - sshportal",
args: args{
lagoon: map[string]string{
"hostname": "lagoon.example.com",
"port": "22",
"username": "example-com-main",
},
isPortal: true,
service: "cli",
container: "cli",
},
want: `ssh -t -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 {
if got := generateSSHConnectionString(tt.args.lagoon, tt.args.service, tt.args.container, tt.args.isPortal); got != tt.want {
t.Errorf("generateSSHConnectionString() = %v, want %v", got, tt.want)
}
})
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/guregu/null v4.0.0+incompatible
// workaround for https://github.com/manifoldco/promptui/issues/98
github.com/nicksnyder/go-i18n v1.10.1 // indirect
github.com/uselagoon/machinery v0.0.12-0.20230828053336-cb8156419c94
github.com/uselagoon/machinery v0.0.13
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3 // indirect
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad // indirect
gopkg.in/alecthomas/kingpin.v3-unstable v3.0.0-20191105091915-95d230a53780 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZm
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/go-bindata/go-bindata v3.1.2+incompatible h1:5vjJMVhowQdPzjE1LdxyFF7YFTXg5IgGVW4gBr5IbvE=
github.com/go-bindata/go-bindata v3.1.2+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/golang-jwt/jwt v3.2.2+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3 h1:I4BOK3PBMjhWfQM2zPJKK7lOBGsrsvOB7kBELP33hiE=
github.com/golang/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand Down Expand Up @@ -115,6 +116,7 @@ github.com/uselagoon/machinery v0.0.12-0.20230825064934-e3ebd4b50b51 h1:xGymM19k
github.com/uselagoon/machinery v0.0.12-0.20230825064934-e3ebd4b50b51/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.12-0.20230828053336-cb8156419c94 h1:GZQox2sqLVBPyCQqG7A163oFCMJ/+Egkoa1u/RXxHdU=
github.com/uselagoon/machinery v0.0.12-0.20230828053336-cb8156419c94/go.mod h1:IXLxlkahEAEgpCmu9Xa/Wmjo6ja4Aoq7tf8G7VrileE=
github.com/uselagoon/machinery v0.0.13/go.mod h1:h/qeMWQR4Qqu33x+8AulNDeolEwvb/G+aIsn/jyUtwk=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down
4 changes: 4 additions & 0 deletions pkg/output/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Options struct {
JSON bool
Pretty bool
Debug bool
Error string
}

// Result .
Expand Down Expand Up @@ -125,6 +126,9 @@ func RenderOutput(data Table, opts Options) {
RenderJSON(returnedData, opts)
} else {
// otherwise render a table
if opts.Error != "" {
os.Stderr.WriteString(opts.Error)
}
table := tablewriter.NewWriter(os.Stdout)
opts.Header = !opts.Header
if opts.Header {
Expand Down

0 comments on commit d8b732b

Please sign in to comment.