Skip to content

Commit 9a9c4aa

Browse files
authored
Refactor/config and logging (#5)
* config | Refactor about how to access configuration value * logging | Refactor about how to get logger
1 parent 3261d89 commit 9a9c4aa

File tree

8 files changed

+88
-73
lines changed

8 files changed

+88
-73
lines changed

cmd/root.go

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,9 @@ import (
1313
"awssh/internal/logging"
1414
)
1515

16-
var (
17-
usePublicIP bool
18-
appConfig *config.Config
19-
)
20-
2116
// MakeRoot used to create a root command functionality
2217
func MakeRoot() *cobra.Command {
23-
24-
appConfig = config.Get()
25-
26-
var command = &cobra.Command{
18+
var cmd = &cobra.Command{
2719
Use: "awssh",
2820
Short: "awssh is a simple CLI to ssh'ing EC2",
2921
Long: "awssh is a simple CLI providing an ssh access to EC2 utilizing ec2-instance-connect",
@@ -45,18 +37,11 @@ func MakeRoot() *cobra.Command {
4537
`,
4638
}
4739

48-
command.Args = cobra.MaximumNArgs(1)
49-
command.Run = runSSHAccess
50-
51-
command.Flags().BoolVarP(&appConfig.Debug, "debug", "d", appConfig.Debug, "Enabled debug mode")
52-
command.Flags().StringVar(&appConfig.Region, "region", appConfig.Region, "Default AWS region to be used. Either set AWS_REGION or AWS_DEFAULT_REGION")
53-
command.Flags().StringVarP(&appConfig.Tags, "tags", "t", appConfig.Tags, "A comma-separated key-value pairs of EC2 tags. Ex: 'Name=ec2,Environment=staging'")
54-
command.Flags().StringVarP(&appConfig.SSHUsername, "ssh-username", "u", appConfig.SSHUsername, "EC2 SSH username")
55-
command.Flags().StringVarP(&appConfig.SSHPort, "ssh-port", "p", appConfig.SSHPort, "An EC2 instance ssh port")
56-
command.Flags().StringVarP(&appConfig.SSHOpts, "ssh-opts", "o", appConfig.SSHOpts, "An additional ssh options")
57-
command.Flags().BoolVarP(&usePublicIP, "use-public-ip", "", false, "Use public IP to access the EC2 instance")
40+
cmd.Args = cobra.MaximumNArgs(1)
41+
cmd.Run = runSSHAccess
5842

59-
return command
43+
config.AddEC2AccessFlags(cmd.Flags())
44+
return cmd
6045
}
6146

6247
func validateInstanceIDArgs(args []string) (err error) {
@@ -70,7 +55,7 @@ func validateInstanceIDArgs(args []string) (err error) {
7055
}
7156

7257
func runSSHAccess(cmd *cobra.Command, args []string) {
73-
logging.NewLogger(appConfig.Debug)
58+
logging.NewLogger(config.GetDebugMode())
7459

7560
err := validateInstanceIDArgs(args)
7661

@@ -80,7 +65,7 @@ func runSSHAccess(cmd *cobra.Command, args []string) {
8065

8166
var target *aws.EC2Instance
8267

83-
session := aws.NewSession(appConfig.Region)
68+
session := aws.NewSession(config.GetRegion())
8469

8570
if len(args) > 0 {
8671
instances, err := aws.GetInstanceWithID(session, args[0])
@@ -90,7 +75,7 @@ func runSSHAccess(cmd *cobra.Command, args []string) {
9075

9176
target = instances[0]
9277
} else {
93-
instances, err := aws.GetInstanceWithTag(session, appConfig.Tags)
78+
instances, err := aws.GetInstanceWithTag(session, config.GetEC2Tags())
9479
if err != nil {
9580
logging.ExitWithError(err)
9681
}
@@ -101,7 +86,7 @@ func runSSHAccess(cmd *cobra.Command, args []string) {
10186
}
10287
}
10388

104-
err = target.Connect(usePublicIP)
89+
err = target.Connect(config.GetUsePublicIP())
10590
if err != nil {
10691
logging.ExitWithError(err)
10792
}

config/config.go

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,71 @@ import (
44
"log"
55

66
"github.com/joeshaw/envdecode"
7+
flag "github.com/spf13/pflag"
78
)
89

910
// Config represent the application configuration
10-
type Config struct {
11+
type config struct {
1112
Debug bool `env:"AWSSH_DEBUG,default=0"`
12-
Tags string `env:"AWSS_TAGS,default=Name=*"`
13+
Tags string `env:"AWSSH_TAGS,default=Name=*"`
1314
SSHUsername string `env:"AWSSH_SSH_USERNAME,default=ec2-user"`
1415
SSHPort string `env:"AWSSH_SSH_PORT,default=22"`
1516
SSHOpts string `env:"AWSSH_SSH_OPTS,default=-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=5"`
17+
UsePublicIP bool `env:"AWSSH_USE_PUBLIC_IP,default=0"`
1618
Region string `env:"AWS_DEFAULT_REGION"`
1719
}
1820

19-
var appConfig Config
21+
var appConfig config
2022

2123
// Load used to load the application configuration
2224
func Load() {
23-
2425
if err := envdecode.Decode(&appConfig); err != nil {
2526
log.Fatal("Can't load config: ", err)
2627
}
2728
}
2829

29-
// Get used to get the application configuration
30-
func Get() *Config {
31-
return &appConfig
30+
// AddEC2AccessFlags to populate flags used for accessing EC2
31+
func AddEC2AccessFlags(flagSet *flag.FlagSet) {
32+
flagSet.BoolVarP(&appConfig.Debug, "debug", "d", appConfig.Debug, "Enabled debug mode")
33+
flagSet.StringVar(&appConfig.Region, "region", appConfig.Region, "Default AWS region to be used. Either set AWS_REGION or AWS_DEFAULT_REGION")
34+
flagSet.StringVarP(&appConfig.Tags, "tags", "t", appConfig.Tags, "A comma-separated key-value pairs of EC2 tags. Ex: 'Name=ec2,Environment=staging'")
35+
flagSet.StringVarP(&appConfig.SSHUsername, "ssh-username", "u", appConfig.SSHUsername, "EC2 SSH username")
36+
flagSet.StringVarP(&appConfig.SSHPort, "ssh-port", "p", appConfig.SSHPort, "An EC2 instance ssh port")
37+
flagSet.StringVarP(&appConfig.SSHOpts, "ssh-opts", "o", appConfig.SSHOpts, "An additional ssh options")
38+
flagSet.BoolVarP(&appConfig.UsePublicIP, "use-public-ip", "", appConfig.UsePublicIP, "Use public IP to access the EC2 instance")
39+
}
40+
41+
// GetDebugMode get the debug mode flag
42+
func GetDebugMode() bool {
43+
return appConfig.Debug
44+
}
45+
46+
// GetRegion get AWS region
47+
func GetRegion() string {
48+
return appConfig.Region
49+
}
50+
51+
// GetEC2Tags get EC2 tags
52+
func GetEC2Tags() string {
53+
return appConfig.Tags
54+
}
55+
56+
// GetSSHUsername get SSH username
57+
func GetSSHUsername() string {
58+
return appConfig.SSHUsername
59+
}
60+
61+
// GetSSHPort get SSH port
62+
func GetSSHPort() string {
63+
return appConfig.SSHPort
64+
}
65+
66+
// GetSSHOpts get SSH optional argument
67+
func GetSSHOpts() string {
68+
return appConfig.SSHOpts
69+
}
70+
71+
// GetUsePublicIP get the flag to access EC2 for using public ip or not
72+
func GetUsePublicIP() bool {
73+
return appConfig.UsePublicIP
3274
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ require (
99
github.com/manifoldco/promptui v0.7.0
1010
github.com/morikuni/aec v1.0.0
1111
github.com/spf13/cobra v1.0.0
12+
github.com/spf13/pflag v1.0.3
13+
github.com/spf13/viper v1.4.0
1214
go.uber.org/zap v1.10.0
1315
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
1416
)

go.sum

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2828
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2929
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
3030
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
31+
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
3132
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
3233
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
3334
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
@@ -48,6 +49,7 @@ github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoA
4849
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
4950
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
5051
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
52+
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
5153
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
5254
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
5355
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
@@ -72,6 +74,7 @@ github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
7274
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
7375
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a h1:weJVJJRzAJBFRlAiJQROKQs8oC9vOxvm4rZmBBk0ONw=
7476
github.com/lunixbochs/vtclean v0.0.0-20180621232353-2d01aacdc34a/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
77+
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
7578
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
7679
github.com/manifoldco/promptui v0.7.0 h1:3l11YT8tm9MnwGFQ4kETwkzpAwY2Jt9lCrumCUW4+z4=
7780
github.com/manifoldco/promptui v0.7.0/go.mod h1:n4zTdgP0vr0S3w7/O/g98U+e0gwLScEXGwov2nIKuGQ=
@@ -81,11 +84,13 @@ github.com/mattn/go-isatty v0.0.4 h1:bnP0vzxcAdeI1zdubAl5PjU6zsERjGZb7raWodagDYs
8184
github.com/mattn/go-isatty v0.0.4/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
8285
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
8386
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
87+
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
8488
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
8589
github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A=
8690
github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc=
8791
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
8892
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
93+
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
8994
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
9095
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
9196
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
@@ -107,13 +112,17 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
107112
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
108113
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
109114
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
115+
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
110116
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
117+
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
111118
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
112119
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
113120
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
121+
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
114122
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
115123
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
116124
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
125+
github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
117126
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
118127
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
119128
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

internal/aws/aws.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,31 @@ import (
1818
// in particularly when you need to use AWS_PROFILE located in ~/.aws/config
1919
// you need to set AWS_SDK_LOAD_CONFIG=1
2020
func NewSession(region string) (session *aws_session.Session) {
21-
logger := logging.Get()
22-
2321
session = aws_session.Must(aws_session.NewSession(&aws.Config{
2422
Region: aws.String(region),
2523
}))
2624

27-
logger.Debugf("Region: %s", *session.Config.Region)
25+
logging.Logger().Debugf("Region: %s", *session.Config.Region)
2826

2927
return
3028
}
3129

3230
// GetInstanceWithID used to get instance with InstanceID input
3331
func GetInstanceWithID(session *aws_session.Session, instanceID string) (ec2Instances []*EC2Instance, err error) {
34-
35-
logger := logging.Get()
36-
3732
input := &ec2.DescribeInstancesInput{
3833
InstanceIds: []*string{
3934
aws.String(instanceID),
4035
},
4136
}
4237

43-
logger.Debugf("Filter EC2 instances with InstanceID: %s", instanceID)
38+
logging.Logger().Debugf("Filter EC2 instances with InstanceID: %s", instanceID)
4439
ec2Instances, err = getInstance(session, input)
4540

4641
return
4742
}
4843

4944
// GetInstanceWithTag used to get instance with key-value pair tags input (ex: Environment=production,ProductDomain=VirtualProduct)
5045
func GetInstanceWithTag(session *aws_session.Session, tags string) (ec2Instances []*EC2Instance, err error) {
51-
52-
logger := logging.Get()
53-
5446
filters, err := prepareFilters(tags)
5547

5648
if err != nil {
@@ -61,7 +53,7 @@ func GetInstanceWithTag(session *aws_session.Session, tags string) (ec2Instances
6153
Filters: filters,
6254
}
6355

64-
logger.Debugf("Filter EC2 instances with tags: %s", tags)
56+
logging.Logger().Debugf("Filter EC2 instances with tags: %s", tags)
6557
ec2Instances, err = getInstance(session, input)
6658

6759
return
@@ -70,8 +62,6 @@ func GetInstanceWithTag(session *aws_session.Session, tags string) (ec2Instances
7062
// prepareFilters used to form a proper AWS filter tags format
7163
// from a raw tags input format
7264
func prepareFilters(rawTags string) (filters []*ec2.Filter, err error) {
73-
logger := logging.Get()
74-
7565
awsTags := make(map[string][]*string)
7666

7767
splitTags := strings.Split(rawTags, ",")
@@ -103,17 +93,14 @@ func prepareFilters(rawTags string) (filters []*ec2.Filter, err error) {
10393
filters = append(filters, f)
10494
}
10595

106-
logger.Debugf("Use the following filters to filter EC2 instances: %v", filters)
96+
logging.Logger().Debugf("Use the following filters to filter EC2 instances: %v", filters)
10797

10898
return
10999
}
110100

111101
// getInstance handle the underlaying to gather the EC2 instances
112102
// following with the DescribeInstances method
113103
func getInstance(session *aws_session.Session, input *ec2.DescribeInstancesInput) (ec2Instances []*EC2Instance, err error) {
114-
115-
logger := logging.Get()
116-
117104
svc := ec2.New(session)
118105
result, err := svc.DescribeInstances(input)
119106

@@ -134,7 +121,7 @@ func getInstance(session *aws_session.Session, input *ec2.DescribeInstancesInput
134121
}
135122
}
136123

137-
logger.Debugf("Found %d EC2 instances on region %s", len(ec2Instances), *session.Config.Region)
124+
logging.Logger().Debugf("Found %d EC2 instances on region %s", len(ec2Instances), *session.Config.Region)
138125

139126
return
140127
}

internal/aws/instance.go

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,15 @@ func NewEC2Instance(session *aws_session.Session, instance *ec2.Instance) *EC2In
5757
// sendSSHPublicKey is an extend method to do ec2-instance-connect task
5858
// for sending SSH Public Key to the AWS API Server
5959
func (e *EC2Instance) sendSSHPublicKey(publicKey string) (err error) {
60-
appConfig := config.Get()
61-
logger := logging.Get()
62-
6360
svc := ec2instanceconnect.New(e.session)
6461
input := &ec2instanceconnect.SendSSHPublicKeyInput{
6562
InstanceId: aws.String(e.InstanceID),
6663
SSHPublicKey: aws.String(publicKey),
67-
InstanceOSUser: aws.String(appConfig.SSHUsername),
64+
InstanceOSUser: aws.String(config.GetSSHUsername()),
6865
AvailabilityZone: aws.String(e.AvailabilityZone),
6966
}
7067

71-
logger.Debugf("Sending SSH Public Key for EC2 instance '%s' (%s)", e.Name, e.InstanceID)
68+
logging.Logger().Debugf("Sending SSH Public Key for EC2 instance '%s' (%s)", e.Name, e.InstanceID)
7269

7370
_, err = svc.SendSSHPublicKey(input)
7471
if err != nil {
@@ -103,10 +100,7 @@ func (e *EC2Instance) sendSSHPublicKey(publicKey string) (err error) {
103100
func (e *EC2Instance) Connect(usePublicIP bool) (err error) {
104101
var ipAddr string
105102

106-
appConfig := config.Get()
107-
logger := logging.Get()
108-
109-
logger.Debugf("Select EC2 instance '%s' (%s)", e.Name, e.InstanceID)
103+
logging.Logger().Debugf("Select EC2 instance '%s' (%s)", e.Name, e.InstanceID)
110104

111105
sshSession, err := ssh.NewSession(e.InstanceID)
112106

@@ -126,21 +120,21 @@ func (e *EC2Instance) Connect(usePublicIP bool) (err error) {
126120
return fmt.Errorf("Could not find public IP for EC2 instance target '%s' (%s)", e.Name, e.InstanceID)
127121
}
128122

129-
logger.Debugf("Use public IP to connect to the EC2 instance target '%s' (%s): %s", e.Name, e.InstanceID, e.PublicIP)
123+
logging.Logger().Debugf("Use public IP to connect to the EC2 instance target '%s' (%s): %s", e.Name, e.InstanceID, e.PublicIP)
130124
ipAddr = e.PublicIP
131125
}
132126

133-
logger.Debugf("Establish an SSH connection to the EC2 instance target '%s' (%s)", e.Name, e.InstanceID)
127+
logging.Logger().Debugf("Establish an SSH connection to the EC2 instance target '%s' (%s)", e.Name, e.InstanceID)
134128

135129
sshArgs := []string{
136130
"-l",
137-
appConfig.SSHUsername,
131+
config.GetSSHUsername(),
138132
"-p",
139-
appConfig.SSHPort,
133+
config.GetSSHPort(),
140134
ipAddr,
141135
}
142136

143-
sshOpts := strings.Split(appConfig.SSHOpts, " ")
137+
sshOpts := strings.Split(config.GetSSHOpts(), " ")
144138
sshArgs = append(sshArgs, sshOpts...)
145139

146140
fmt.Printf("Running command: ssh %s\n", strings.Join(sshArgs[:], " "))

internal/logging/logging.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ func NewLogger(debugMode bool) *zap.SugaredLogger {
3838
return appLogger
3939
}
4040

41-
// Get used to get the application logger
42-
func Get() *zap.SugaredLogger {
41+
// Logger used to get the application logger
42+
func Logger() (log *zap.SugaredLogger) {
4343
defer appLogger.Sync() // nolint: errcheck
44-
return appLogger
44+
return
4545
}
4646

4747
// ExitWithError will terminate execution with an error result

0 commit comments

Comments
 (0)