Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
rollback: name-tag target type change
Browse files Browse the repository at this point in the history
Signed-off-by: danmx <[email protected]>
  • Loading branch information
danmx committed Jun 21, 2020
1 parent f4bb243 commit edf42bb
Show file tree
Hide file tree
Showing 6 changed files with 125 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
- **deps:** update l.gcr.io/google/bazel docker tag to v3.3.0
- **pre-commit:** add go mod tidy to update_deps

### Rollback
- name-tag target type change

### Update
- **go:** version 1.14.4

Expand Down
2 changes: 1 addition & 1 deletion cmd/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ func init() {
rootCmd.AddCommand(sessionCmd)

sessionCmd.Flags().String("target", "", "specify the target depending on the type")
sessionCmd.Flags().String("type", aws.TargetTypeInstanceID, fmt.Sprintf("specify target type: %s/%s/%s", aws.TargetTypeInstanceID, aws.TargetTypePrivateDNS, aws.TargetTypeName))
sessionCmd.Flags().String("type", aws.TargetTypeInstanceID, fmt.Sprintf("specify target type: %s/%s/%s/%s (deprecated)", aws.TargetTypeInstanceID, aws.TargetTypePrivateDNS, aws.TargetTypeName, aws.DeprecatedTargetTypeName))
}
2 changes: 1 addition & 1 deletion cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func init() {
rootCmd.AddCommand(sshCmd)

sshCmd.Flags().String("target", "", "specify the target depending on the type")
sshCmd.Flags().String("type", aws.TargetTypeInstanceID, fmt.Sprintf("specify target type: %s/%s/%s", aws.TargetTypeInstanceID, aws.TargetTypePrivateDNS, aws.TargetTypeName))
sshCmd.Flags().String("type", aws.TargetTypeInstanceID, fmt.Sprintf("specify target type: %s/%s/%s/%s (deprecated)", aws.TargetTypeInstanceID, aws.TargetTypePrivateDNS, aws.TargetTypeName, aws.DeprecatedTargetTypeName))
sshCmd.Flags().Bool("gen-key-pair", false, fmt.Sprintf("generate a temporary key pair that will be send and used. By default use %s as an identity file", path.Join(workDir, tempKeyName)))
sshCmd.Flags().String("gen-key-dir", workDir, "the directory where temporary keys will be generated")
sshCmd.Flags().String("os-user", "ec2-user", "specify an instance OS user which will be using sent public key")
Expand Down
13 changes: 13 additions & 0 deletions pkg/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const (
TargetTypePrivateDNS = "private-dns"
// TargetTypeName points to a name type
TargetTypeName = "name"
// DeprecatedTargetTypeName points to a name type
DeprecatedTargetTypeName = "name-tag"
)

// NewWithConfig will generate an AWS Provider with given configuration
Expand Down Expand Up @@ -184,6 +186,17 @@ func (p *Provider) getInstance(targetType, target string) (*ec2.Instance, error)
Values: []*string{aws.String("running")},
},
}
case DeprecatedTargetTypeName:
filters = []*ec2.Filter{
{
Name: aws.String("tag:Name"),
Values: []*string{&target},
},
{
Name: aws.String("instance-state-name"),
Values: []*string{aws.String("running")},
},
}
default:
log.WithFields(log.Fields{
"target": target,
Expand Down
11 changes: 11 additions & 0 deletions pkg/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,15 @@ func TestStart(t *testing.T) {
m.EXPECT().StartSession(gomock.Eq(*input.TargetType), gomock.Eq(*input.Target)).Return(nil),
)
assert.NoError(t, input.start(m))
// Deprecated Name
targetType = aws.DeprecatedTargetTypeName
gomock.InOrder(
m.EXPECT().NewWithConfig(gomock.Eq(&aws.Config{
Region: *input.Region,
Profile: *input.Profile,
MFAToken: *input.MFAToken,
})).Return(nil),
m.EXPECT().StartSession(gomock.Eq(*input.TargetType), gomock.Eq(*input.Target)).Return(nil),
)
assert.NoError(t, input.start(m))
}
96 changes: 96 additions & 0 deletions pkg/ssh/ssh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

// TestStart verifies start ssh method
func TestStart(t *testing.T) {
// Instance
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := NewMockCloudSSH(ctrl) // skipcq: SCC-compile
Expand Down Expand Up @@ -57,4 +58,99 @@ func TestStart(t *testing.T) {
)

assert.NoError(t, input.start(m))

// DNS
target = "test.local"
targetType = aws.TargetTypePrivateDNS
input = StartInput{
MFAToken: &mfa,
Region: &region,
Profile: &profile,
Target: &target,
TargetType: &targetType,
PortNumber: &port,
PublicKey: &pubKey,
OSUser: &osUser,
GenKeyPair: &genKey,
}

gomock.InOrder(
m.EXPECT().NewWithConfig(gomock.Eq(&aws.Config{
Region: *input.Region,
Profile: *input.Profile,
MFAToken: *input.MFAToken,
})).Return(nil),
m.EXPECT().StartSSH(
gomock.Eq(*input.TargetType),
gomock.Eq(*input.Target),
gomock.Eq(*input.OSUser),
gomock.Eq(*input.PortNumber),
gomock.Any(),
).Return(nil),
)

assert.NoError(t, input.start(m))

// Name
target = "Backend"
targetType = aws.TargetTypePrivateDNS
input = StartInput{
MFAToken: &mfa,
Region: &region,
Profile: &profile,
Target: &target,
TargetType: &targetType,
PortNumber: &port,
PublicKey: &pubKey,
OSUser: &osUser,
GenKeyPair: &genKey,
}

gomock.InOrder(
m.EXPECT().NewWithConfig(gomock.Eq(&aws.Config{
Region: *input.Region,
Profile: *input.Profile,
MFAToken: *input.MFAToken,
})).Return(nil),
m.EXPECT().StartSSH(
gomock.Eq(*input.TargetType),
gomock.Eq(*input.Target),
gomock.Eq(*input.OSUser),
gomock.Eq(*input.PortNumber),
gomock.Any(),
).Return(nil),
)

assert.NoError(t, input.start(m))

// Deprecated Name
targetType = aws.DeprecatedTargetTypeName
input = StartInput{
MFAToken: &mfa,
Region: &region,
Profile: &profile,
Target: &target,
TargetType: &targetType,
PortNumber: &port,
PublicKey: &pubKey,
OSUser: &osUser,
GenKeyPair: &genKey,
}

gomock.InOrder(
m.EXPECT().NewWithConfig(gomock.Eq(&aws.Config{
Region: *input.Region,
Profile: *input.Profile,
MFAToken: *input.MFAToken,
})).Return(nil),
m.EXPECT().StartSSH(
gomock.Eq(*input.TargetType),
gomock.Eq(*input.Target),
gomock.Eq(*input.OSUser),
gomock.Eq(*input.PortNumber),
gomock.Any(),
).Return(nil),
)

assert.NoError(t, input.start(m))
}

0 comments on commit edf42bb

Please sign in to comment.