Skip to content

Commit

Permalink
Fixes broken "update" command after upgrading to AWS SDK v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugene Dementyev authored and ekini committed Oct 8, 2021
1 parent 7ae258d commit 2ccbb13
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions lib/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,47 +73,47 @@ func TraverseProfiles(profiles []ProfileConfig, noProfilePrefix bool) ([]Process
linq.From(summary.Instances).OrderBy(instanceNameSorter). // sort by name first
ThenBy(instanceLaunchTimeSorter). // then by launch time
GroupBy(func(i interface{}) interface{} { // and then group by vpc
vpcID := i.(*types.Instance).VpcId
vpcID := i.(types.Instance).VpcId
return aws.ToString(vpcID)
}, func(i interface{}) interface{} {
return i.(*types.Instance)
return i.(types.Instance)
}).ToSlice(&vpcInstances)

var commonBastions []*types.Instance
var commonBastions []types.Instance
linq.From(summary.Instances).OrderBy(instanceNameSorter). // sort by name first
ThenBy(instanceLaunchTimeSorter). // then by launch time
Where(
func(f interface{}) bool {
return isBastionFromTags(f.(*types.Instance).Tags, true) // check for global tag as well
return isBastionFromTags(f.(types.Instance).Tags, true) // check for global tag as well
},
).ToSlice(&commonBastions)

ctx.Debugf("Found %d common (global) bastions", len(commonBastions))

for _, vpcGroup := range vpcInstances { // take the instances grouped by vpc and iterate
var vpcBastions []*types.Instance
var vpcBastions []types.Instance
linq.From(vpcGroup.Group).Where(
func(f interface{}) bool {
return isBastionFromTags(f.(*types.Instance).Tags, false) // "false" means don't check for global tag
return isBastionFromTags(f.(types.Instance).Tags, false) // "false" means don't check for global tag
},
).ToSlice(&vpcBastions)

ctx.WithField("vpc", vpcGroup.Key).Debugf("Found %d bastions", len(vpcBastions))

var nameInstances []linq.Group
linq.From(vpcGroup.Group).GroupBy(func(i interface{}) interface{} { // now group them by name
instanceName := getNameFromTags(i.(*types.Instance).Tags)
instanceName := getNameFromTags(i.(types.Instance).Tags)
return instanceName
}, func(i interface{}) interface{} {
return i.(*types.Instance)
return i.(types.Instance)
}).ToSlice(&nameInstances)

// now we have instances, grouped by vpc and name
for _, nameGroup := range nameInstances {
instanceName := nameGroup.Key.(string)

for n, instance := range nameGroup.Group {
instance := instance.(*types.Instance)
instance := instance.(types.Instance)
var entry = SSHEntry{
InstanceID: aws.ToString(instance.InstanceId),
ProfileConfig: ProfileConfig{
Expand Down
10 changes: 5 additions & 5 deletions lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ func (w weights) Len() int { return len(w) }
func (w weights) Less(i, j int) bool { return w[i].Weight < w[j].Weight }
func (w weights) Swap(i, j int) { w[i], w[j] = w[j], w[i] }

func findBestBastion(instanceName string, bastions []*types.Instance) *types.Instance {
func findBestBastion(instanceName string, bastions []types.Instance) *types.Instance {
// skip instances with bastionCanonicalName in name
if !strings.Contains(instanceName, bastionCanonicalName) && len(bastions) > 0 {
if len(bastions) == 1 {
return bastions[0]
return &bastions[0]
}

var weights weights
Expand All @@ -101,7 +101,7 @@ func findBestBastion(instanceName string, bastions []*types.Instance) *types.Ins
// sort by weiht
sort.Sort(weights)
// return the first one
return bastions[weights[0].Index]
return &bastions[weights[0].Index]
}

return nil
Expand All @@ -122,11 +122,11 @@ func getInstanceCanonicalName(profile, instanceName, instanceIndex string) strin
}

func instanceLaunchTimeSorter(i interface{}) interface{} { // sorts by launch time
launched := aws.ToTime(i.(*types.Instance).LaunchTime)
launched := aws.ToTime(i.(types.Instance).LaunchTime)
return launched.Unix()
}

func instanceNameSorter(i interface{}) interface{} { // sort by instance name
instanceName := getNameFromTags(i.(*types.Instance).Tags)
instanceName := getNameFromTags(i.(types.Instance).Tags)
return instanceName
}

0 comments on commit 2ccbb13

Please sign in to comment.