Skip to content

Commit 93f5c8b

Browse files
committed
Listing route tables display the association IDs. Close #123.
1 parent 7a12b77 commit 93f5c8b

File tree

8 files changed

+44
-10
lines changed

8 files changed

+44
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Add ACM certificates in infra:
1414
- `awless list certificates`
1515
- `awless create/delete/check certificate domains=my.firstdomain.com,my.seconddomain.com validation-domains=firstdomain.com,seconddomain.com`
16+
- [#123](https://github.com/wallix/awless/issues/123): Listing route tables display the association IDs.
1617

1718
### Fixes
1819
- `awless ssh --through`: no reusing same conn to avoid EOF. Bug: only first user (amazonlinux) was successful (usually ec2-user) !!

aws/conv/convert.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,6 @@ var extractNameValueFn = func(i interface{}) (interface{}, error) {
375375
nameValues = append(nameValues, keyval)
376376
}
377377
return nameValues, nil
378-
379378
}
380379

381380
var extractECSAttributesFn = func(i interface{}) (interface{}, error) {
@@ -389,7 +388,19 @@ var extractECSAttributesFn = func(i interface{}) (interface{}, error) {
389388
keyVals = append(keyVals, keyval)
390389
}
391390
return keyVals, nil
391+
}
392+
393+
var extractRouteTableAssociationsFn = func(i interface{}) (interface{}, error) {
394+
if _, ok := i.([]*ec2.RouteTableAssociation); !ok {
395+
return nil, fmt.Errorf("extract route table associations: not an association slice but a %T", i)
396+
}
397+
var keyVals []*graph.KeyValue
398+
for _, assoc := range i.([]*ec2.RouteTableAssociation) {
399+
keyval := &graph.KeyValue{KeyName: awssdk.StringValue(assoc.RouteTableAssociationId), Value: awssdk.StringValue(assoc.SubnetId)}
392400

401+
keyVals = append(keyVals, keyval)
402+
}
403+
return keyVals, nil
393404
}
394405

395406
var extractFieldFn = func(field string) transformFn {

aws/conv/model.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,12 @@ var awsResourcesDef = map[string]map[string]*propertyTransform{
140140
properties.State: {name: "State", transform: extractValueFn},
141141
},
142142
cloud.RouteTable: {
143-
properties.Name: {name: "Tags", transform: extractTagFn("Name")},
144-
properties.Vpc: {name: "VpcId", transform: extractValueFn},
145-
properties.Routes: {name: "Routes", transform: extractRoutesSliceFn},
146-
properties.Main: {name: "Associations", transform: extractHasATrueBoolInStructSliceFn("Main")},
147-
properties.Tags: {name: "Tags", transform: extractTagsFn},
143+
properties.Name: {name: "Tags", transform: extractTagFn("Name")},
144+
properties.Vpc: {name: "VpcId", transform: extractValueFn},
145+
properties.Routes: {name: "Routes", transform: extractRoutesSliceFn},
146+
properties.Main: {name: "Associations", transform: extractHasATrueBoolInStructSliceFn("Main")},
147+
properties.Associations: {name: "Associations", transform: extractRouteTableAssociationsFn},
148+
properties.Tags: {name: "Tags", transform: extractTagsFn},
148149
},
149150
cloud.AvailabilityZone: {
150151
properties.Name: {name: "ZoneName", transform: extractValueFn},

aws/services/services_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,14 @@ func TestBuildInfraRdfGraph(t *testing.T) {
305305
}
306306

307307
routeTables := []*ec2.RouteTable{
308-
{RouteTableId: awssdk.String("rt_1"), VpcId: awssdk.String("vpc_1"), Associations: []*ec2.RouteTableAssociation{{RouteTableId: awssdk.String("rt_1"), SubnetId: awssdk.String("sub_1")}}},
308+
{
309+
RouteTableId: awssdk.String("rt_1"),
310+
VpcId: awssdk.String("vpc_1"),
311+
Associations: []*ec2.RouteTableAssociation{
312+
{RouteTableId: awssdk.String("rt_1"), SubnetId: awssdk.String("sub_1"), RouteTableAssociationId: awssdk.String("assoc_1")},
313+
{RouteTableId: awssdk.String("rt_1"), SubnetId: awssdk.String("sub_2"), RouteTableAssociationId: awssdk.String("assoc_2"), Main: awssdk.Bool(true)},
314+
},
315+
},
309316
}
310317

311318
images := []*ec2.Image{
@@ -585,6 +592,14 @@ func TestBuildInfraRdfGraph(t *testing.T) {
585592
return p[i].KeyName < p[j].KeyName
586593
})
587594
}
595+
if p, ok := res.Properties[p.Associations].([]*graph.KeyValue); ok {
596+
sort.Slice(p, func(i, j int) bool {
597+
if p[i].KeyName == p[j].KeyName {
598+
return p[i].Value < p[j].Value
599+
}
600+
return p[i].KeyName < p[j].KeyName
601+
})
602+
}
588603
if p, ok := res.Properties[p.InboundRules].([]*graph.FirewallRule); ok {
589604
for _, r := range p {
590605
sort.Strings(r.Sources)
@@ -621,7 +636,7 @@ func TestBuildInfraRdfGraph(t *testing.T) {
621636
"my_key": resourcetest.KeyPair("my_key").Build(),
622637
"igw_1": resourcetest.InternetGw("igw_1").Prop(p.Vpcs, []string{"vpc_2"}).Build(),
623638
"natgw_1": resourcetest.NatGw("natgw_1").Prop(p.Vpc, "vpc_1").Prop(p.Subnet, "sub_1").Build(),
624-
"rt_1": resourcetest.RouteTable("rt_1").Prop(p.Vpc, "vpc_1").Prop(p.Main, false).Build(),
639+
"rt_1": resourcetest.RouteTable("rt_1").Prop(p.Vpc, "vpc_1").Prop(p.Main, true).Prop(p.Associations, []*graph.KeyValue{{KeyName: "assoc_1", Value: "sub_1"}, {KeyName: "assoc_2", Value: "sub_2"}}).Build(),
625640
"lb_1": resourcetest.LoadBalancer("lb_1").Prop(p.Arn, "lb_1").Prop(p.Name, "my_loadbalancer").Prop(p.Vpc, "vpc_1").Build(),
626641
"lb_2": resourcetest.LoadBalancer("lb_2").Prop(p.Arn, "lb_2").Prop(p.Vpc, "vpc_2").Build(),
627642
"lb_3": resourcetest.LoadBalancer("lb_3").Prop(p.Arn, "lb_3").Prop(p.Vpc, "vpc_1").Build(),
@@ -687,7 +702,7 @@ func TestBuildInfraRdfGraph(t *testing.T) {
687702
"lb_3": {"tg_1"},
688703
"my_key": {"inst_4", "inst_6", "launchconfig_arn"},
689704
"natgw_1": {"sub_1"},
690-
"rt_1": {"sub_1"},
705+
"rt_1": {"sub_1", "sub_2"},
691706
"securitygroup_1": {"eni-1", "inst_2", "inst_4", "inst_6", "lb_3"},
692707
"securitygroup_2": {"eni-1", "inst_4", "lb_3"},
693708
"tg_1": {"inst_1"},

cloud/properties/gen_properties.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ const (
3535
Architecture = "Architecture"
3636
Arn = "Arn"
3737
Association = "Association"
38+
Associations = "Associations"
3839
Attachable = "Attachable"
3940
Attached = "Attached"
4041
Attachment = "Attachment"

cloud/rdf/gen_rdf.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
Architecture = "cloud:architecture"
3838
Arn = "cloud:arn"
3939
Association = "cloud:association"
40+
Associations = "cloud:associations"
4041
Attachable = "cloud:attachable"
4142
Attached = "cloud:attached"
4243
Attachment = "cloud:attachment"
@@ -243,6 +244,7 @@ var Labels = map[string]string{
243244
properties.Architecture: Architecture,
244245
properties.Arn: Arn,
245246
properties.Association: Association,
247+
properties.Associations: Associations,
246248
properties.Attachable: Attachable,
247249
properties.Attached: Attached,
248250
properties.Attachment: Attachment,
@@ -449,6 +451,7 @@ var Properties = RDFProperties{
449451
Architecture: {ID: Architecture, RdfType: "rdf:Property", RdfsLabel: "Architecture", RdfsDefinedBy: "rdfs:Literal", RdfsDataType: "xsd:string"},
450452
Arn: {ID: Arn, RdfType: "rdf:Property", RdfsLabel: "Arn", RdfsDefinedBy: "rdfs:Literal", RdfsDataType: "xsd:string"},
451453
Association: {ID: Association, RdfType: "rdf:Property", RdfsLabel: "Association", RdfsDefinedBy: "rdfs:Literal", RdfsDataType: "xsd:string"},
454+
Associations: {ID: Associations, RdfType: "rdf:Property", RdfsLabel: "Associations", RdfsDefinedBy: "rdfs:list", RdfsDataType: "cloud-owl:KeyValue"},
452455
Attachable: {ID: Attachable, RdfType: "rdf:Property", RdfsLabel: "Attachable", RdfsDefinedBy: "rdfs:Literal", RdfsDataType: "xsd:boolean"},
453456
Attached: {ID: Attached, RdfType: "rdf:Property", RdfsLabel: "Attached", RdfsDefinedBy: "rdfs:Literal", RdfsDataType: "xsd:boolean"},
454457
Attachment: {ID: Attachment, RdfType: "rdf:Property", RdfsLabel: "Attachment", RdfsDefinedBy: "rdfs:Literal", RdfsDataType: "xsd:string"},

console/defaults.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ var ColumnsInListing = map[string][]string{
2929
cloud.SecurityGroup: {properties.ID, properties.Vpc, properties.InboundRules, properties.OutboundRules, properties.Name, properties.Description},
3030
cloud.InternetGateway: {properties.ID, properties.Name, properties.Vpcs},
3131
cloud.NatGateway: {properties.ID, properties.State, properties.Vpc, properties.Subnet, properties.Created},
32-
cloud.RouteTable: {properties.ID, properties.Name, properties.Vpc, properties.Main, properties.Routes},
32+
cloud.RouteTable: {properties.ID, properties.Name, properties.Vpc, properties.Main, properties.Routes, properties.Associations},
3333
cloud.Keypair: {properties.ID, properties.Fingerprint},
3434
cloud.Image: {properties.ID, properties.Name, properties.State, properties.Location, properties.Public, properties.Type, properties.Created, properties.Architecture, properties.Hypervisor, properties.Virtualization},
3535
cloud.ImportImageTask: {properties.ID, properties.Description, properties.Image, properties.Progress, properties.State, properties.StateMessage},
@@ -141,6 +141,7 @@ var DefaultsColumnDefinitions = map[string][]ColumnDefinition{
141141
StringColumnDefinition{Prop: properties.Vpc},
142142
StringColumnDefinition{Prop: properties.Main},
143143
RoutesColumnDefinition{StringColumnDefinition: StringColumnDefinition{Prop: properties.Routes}},
144+
KeyValuesColumnDefinition{StringColumnDefinition: StringColumnDefinition{Prop: properties.Associations}},
144145
},
145146
cloud.Keypair: {
146147
StringColumnDefinition{Prop: properties.ID},

gen/aws/properties_definitions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ var PropertiesDefinitions = []property{
3232
{AwlessLabel: "Architecture", RDFLabel: fmt.Sprintf("%s:architecture", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsLiteral, RdfsDataType: rdf.XsdString},
3333
{AwlessLabel: "Arn", RDFLabel: fmt.Sprintf("%s:arn", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsLiteral, RdfsDataType: rdf.XsdString},
3434
{AwlessLabel: "Association", RDFLabel: fmt.Sprintf("%s:association", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsLiteral, RdfsDataType: rdf.XsdString},
35+
{AwlessLabel: "Associations", RDFLabel: fmt.Sprintf("%s:associations", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsList, RdfsDataType: rdf.KeyValue},
3536
{AwlessLabel: "Attachable", RDFLabel: fmt.Sprintf("%s:attachable", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsLiteral, RdfsDataType: rdf.XsdBoolean},
3637
{AwlessLabel: "Attached", RDFLabel: fmt.Sprintf("%s:attached", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsLiteral, RdfsDataType: rdf.XsdBoolean},
3738
{AwlessLabel: "Attachment", RDFLabel: fmt.Sprintf("%s:attachment", rdf.CloudNS), RDFType: rdf.RdfProperty, RdfsDefinedBy: rdf.RdfsLiteral, RdfsDataType: rdf.XsdString},

0 commit comments

Comments
 (0)