Skip to content

Commit

Permalink
Add nicer display IDs to more resources (#201)
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitfang authored Jul 22, 2022
1 parent a5aec16 commit a675f88
Show file tree
Hide file tree
Showing 20 changed files with 117 additions and 67 deletions.
5 changes: 3 additions & 2 deletions pkg/provider/aws/autoscaling_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ func TestFetchAutoscalingGroup(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 2)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "autoscaling.AutoScalingGroup",
Region: defaultRegion,
Type: "autoscaling.AutoScalingGroup",
Region: defaultRegion,
DisplayIdPrefix: "testing-0-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand Down
2 changes: 2 additions & 0 deletions pkg/provider/aws/config/elasticache.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ types:
pointer: true
key: Key
value: Value
transformers:
- displayIdArnPrefix("cluster:")
1 change: 1 addition & 0 deletions pkg/provider/aws/config/elb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ types:
id:
name: LoadBalancerArn
pointer: true
displayId: LoadBalancerName
getTagsApi:
call: DescribeTags
inputIDField:
Expand Down
6 changes: 6 additions & 0 deletions pkg/provider/aws/config/iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ types:
field: Tags
key: Key
value: Value
transformers:
- displayIdArnPrefix("oidc-provider/")
- name: Policy
listApi:
call: ListPolicies
Expand All @@ -40,6 +42,8 @@ types:
call: ListSAMLProviderTags
inputIDField: SAMLProviderArn
tags: *tags
transformers:
- displayIdArnPrefix("saml-provider/")
- name: VirtualMFADevice
listApi:
call: ListVirtualMFADevices
Expand All @@ -50,3 +54,5 @@ types:
call: ListMFADeviceTags
inputIDField: SerialNumber
tags: *tags
transformers:
- displayIdArnPrefix("mfa/")
3 changes: 1 addition & 2 deletions pkg/provider/aws/config/lambda.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ types:
outputKey: Functions
sdkType: FunctionConfiguration
id: FunctionArn
displayId: FunctionName
getTagsApi:
call: GetFunction
inputIDField: FunctionName
tags:
style: map
field: Tags
transformers:
- displayIdArnPrefix("function:")
2 changes: 2 additions & 0 deletions pkg/provider/aws/config/sns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ types:
pointer: true
key: Key
value: Value
transformers:
- displayIdArn
70 changes: 42 additions & 28 deletions pkg/provider/aws/ec2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ func TestFetchEC2Instances(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 2)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Instance",
Region: defaultRegion,
Type: "ec2.Instance",
Region: defaultRegion,
DisplayIdPrefix: "i-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -40,8 +41,9 @@ func TestFetchEBSVolumes(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 2)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Volume",
Region: defaultRegion,
Type: "ec2.Volume",
Region: defaultRegion,
DisplayIdPrefix: "vol-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -60,8 +62,9 @@ func TestFetchAddresses(t *testing.T) {
ctx := setupIntegrationTest(t)
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.Address")
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Address",
Region: defaultRegion,
Type: "ec2.Address",
Region: defaultRegion,
DisplayIdPrefix: "eipalloc-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -77,8 +80,9 @@ func TestFetchImages(t *testing.T) {
ctx := setupIntegrationTest(t)
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.Image")
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Image",
Region: defaultRegion,
Type: "ec2.Image",
Region: defaultRegion,
DisplayIdPrefix: "ami-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -97,8 +101,9 @@ func TestFetchKeyPairs(t *testing.T) {
ctx := setupIntegrationTest(t)
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.KeyPair")
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.KeyPair",
Region: defaultRegion,
Type: "ec2.KeyPair",
Region: defaultRegion,
DisplayIdPrefix: "key-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -116,8 +121,9 @@ func TestFetchLaunchTemplates(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 2)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.LaunchTemplate",
Region: defaultRegion,
Type: "ec2.LaunchTemplate",
Region: defaultRegion,
DisplayIdPrefix: "lt-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -134,8 +140,9 @@ func TestFetchNatGateways(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.NatGateway")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.NatGateway",
Region: defaultRegion,
Type: "ec2.NatGateway",
Region: defaultRegion,
DisplayIdPrefix: "nat-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -152,8 +159,9 @@ func TestFetchNetworkAcl(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.NetworkAcl")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.NetworkAcl",
Region: defaultRegion,
Type: "ec2.NetworkAcl",
Region: defaultRegion,
DisplayIdPrefix: "acl-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -170,8 +178,9 @@ func TestFetchNetworkInterface(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.NetworkInterface")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.NetworkInterface",
Region: defaultRegion,
Type: "ec2.NetworkInterface",
Region: defaultRegion,
DisplayIdPrefix: "eni-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -188,8 +197,9 @@ func TestFetchRouteTable(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.RouteTable")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.RouteTable",
Region: defaultRegion,
Type: "ec2.RouteTable",
Region: defaultRegion,
DisplayIdPrefix: "rtb-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -206,8 +216,9 @@ func TestFetchSecurityGroups(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.SecurityGroup")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.SecurityGroup",
Region: defaultRegion,
Type: "ec2.SecurityGroup",
Region: defaultRegion,
DisplayIdPrefix: "sg-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -224,8 +235,9 @@ func TestFetchSnapshots(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.Snapshot")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Snapshot",
Region: defaultRegion,
Type: "ec2.Snapshot",
Region: defaultRegion,
DisplayIdPrefix: "snap-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -242,8 +254,9 @@ func TestFetchSubnets(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.Subnet")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Subnet",
Region: defaultRegion,
Type: "ec2.Subnet",
Region: defaultRegion,
DisplayIdPrefix: "subnet-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -260,8 +273,9 @@ func TestFetchVpcs(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "ec2.Vpc")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "ec2.Vpc",
Region: defaultRegion,
Type: "ec2.Vpc",
Region: defaultRegion,
DisplayIdPrefix: "vpc-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand Down
14 changes: 8 additions & 6 deletions pkg/provider/aws/eks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ import (

func (p *Provider) register_eks(mapping map[string]mapper) {
mapping["eks.Cluster"] = mapper{
FetchFunc: p.fetch_eks_Cluster,
IdField: "Arn",
IsGlobal: false,
FetchFunc: p.fetch_eks_Cluster,
IdField: "Arn",
DisplayIDField: "Name",
IsGlobal: false,
}
mapping["eks.Nodegroup"] = mapper{
FetchFunc: p.fetch_eks_Nodegroup,
IdField: "NodegroupArn",
IsGlobal: false,
FetchFunc: p.fetch_eks_Nodegroup,
IdField: "NodegroupArn",
DisplayIDField: "NodegroupName",
IsGlobal: false,
}
}

Expand Down
10 changes: 6 additions & 4 deletions pkg/provider/aws/eks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ func TestFetchEKSClusters(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 1)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "eks.Cluster",
Region: defaultRegion,
Type: "eks.Cluster",
Region: defaultRegion,
DisplayIdPrefix: "main",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -37,8 +38,9 @@ func TestFetchEKSNodegroup(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 1)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "eks.Nodegroup",
Region: defaultRegion,
Type: "eks.Nodegroup",
Region: defaultRegion,
DisplayIdPrefix: "main-default-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand Down
5 changes: 3 additions & 2 deletions pkg/provider/aws/elasticache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ func TestFetchElasticacheClusters(t *testing.T) {

testingutil.AssertResourceCount(t, resources, "", 1)
testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "elasticache.CacheCluster",
Region: defaultRegion,
Type: "elasticache.CacheCluster",
Region: defaultRegion,
DisplayIdPrefix: "test-0-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand Down
3 changes: 3 additions & 0 deletions pkg/provider/aws/iam.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,21 @@ func (p *Provider) register_iam_manual(mapping map[string]mapper) {
ServiceEndpointID: "iam",
FetchFunc: p.fetch_iam_User,
IdField: "Arn",
DisplayIDField: "UserName",
IsGlobal: true,
}
mapping["iam.InstanceProfile"] = mapper{
ServiceEndpointID: "iam",
FetchFunc: p.fetch_iam_InstanceProfile,
IdField: "Arn",
DisplayIDField: "InstanceProfileName",
IsGlobal: true,
}
mapping["iam.Role"] = mapper{
ServiceEndpointID: "iam",
FetchFunc: p.fetch_iam_Role,
IdField: "Arn",
DisplayIDField: "RoleName",
IsGlobal: true,
}
}
Expand Down
25 changes: 15 additions & 10 deletions pkg/provider/aws/iam_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ func TestFetchInstanceProfiles(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "iam.InstanceProfile")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "iam.InstanceProfile",
Region: globalRegion,
Type: "iam.InstanceProfile",
Region: globalRegion,
DisplayIdPrefix: "test-0-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -40,8 +41,9 @@ func TestFetchOpenIDConnectProviders(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "iam.OpenIDConnectProvider")

resources = testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "iam.OpenIDConnectProvider",
Region: globalRegion,
Type: "iam.OpenIDConnectProvider",
Region: globalRegion,
DisplayIdPrefix: "oidc.eks.",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand Down Expand Up @@ -90,8 +92,9 @@ func TestFetchRoles(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "iam.Role")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "iam.Role",
Region: globalRegion,
Type: "iam.Role",
Region: globalRegion,
DisplayIdPrefix: "test-0-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -112,8 +115,9 @@ func TestFetchUsers(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "iam.User")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "iam.User",
Region: globalRegion,
Type: "iam.User",
Region: globalRegion,
DisplayIdPrefix: "test-0",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand All @@ -134,8 +138,9 @@ func TestFetchVirtualMFADevices(t *testing.T) {
resources := testprovider.FetchResources(ctx.ctx, t, ctx.p, "iam.VirtualMFADevice")

testingutil.AssertResourceFilteredCount(t, resources, 1, testingutil.ResourceFilter{
Type: "iam.VirtualMFADevice",
Region: globalRegion,
Type: "iam.VirtualMFADevice",
Region: globalRegion,
DisplayIdPrefix: "test/test-0-",
Tags: model.Tags{
{
Key: testingutil.TestTag,
Expand Down
Loading

0 comments on commit a675f88

Please sign in to comment.