Repository: clouditor/clouditor
Pull request #767 (2022-07-28 12:15:08)

Add discoverer component name 

codecov[bot]: # [Codecov](https://codecov.io/gh/clouditor/clouditor/pull/767?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) Report
> Merging [#767](https://codecov.io/gh/clouditor/clouditor/pull/767?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (61c19c3) into [main](https://codecov.io/gh/clouditor/clouditor/commit/aa2e25bdb7bf010ba47372589af42075c3e7a18f?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) (aa2e25b) will **increase** coverage by `0.03%`.
> The diff coverage is `100.00%`.

```diff
@@            Coverage Diff             @@
##             main     #767      +/-   ##
==========================================
+ Coverage   80.93%   80.96%   +0.03%     
==========================================
  Files          70       70              
  Lines        6041     6053      +12     
==========================================
+ Hits         4889     4901      +12     
  Misses        906      906              
  Partials      246      246              
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `80.96% <100.00%> (+0.03%)` | :arrow_up: |

Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#carryforward-flags-in-the-pull-request-comment) to find out more.

| [Impacted Files](https://codecov.io/gh/clouditor/clouditor/pull/767?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) | Coverage Δ | |
|---|---|---|
| [service/discovery/azure/azure.go](https://codecov.io/gh/clouditor/clouditor/pull/767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvYXp1cmUvYXp1cmUuZ28=) | `81.03% <100.00%> (ø)` | |
| [service/discovery/azure/compute.go](https://codecov.io/gh/clouditor/clouditor/pull/767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvYXp1cmUvY29tcHV0ZS5nbw==) | `91.97% <100.00%> (+0.17%)` | :arrow_up: |
| [service/discovery/azure/network.go](https://codecov.io/gh/clouditor/clouditor/pull/767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvYXp1cmUvbmV0d29yay5nbw==) | `91.66% <100.00%> (+0.21%)` | :arrow_up: |
| [service/discovery/azure/storage.go](https://codecov.io/gh/clouditor/clouditor/pull/767/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvYXp1cmUvc3RvcmFnZS5nbw==) | `88.31% <100.00%> (+0.12%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/clouditor/clouditor/pull/767?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/clouditor/clouditor/pull/767?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Last update [aa2e25b...61c19c3](https://codecov.io/gh/clouditor/clouditor/pull/767?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor).


Patch:
diff --git a/go.mod b/go.mod
index d18cfae7..be29058d 100644
--- a/go.mod
+++ b/go.mod
@@ -43,7 +43,7 @@ require (
 require (
 	github.com/aws/aws-sdk-go-v2 v1.16.7
 	github.com/aws/aws-sdk-go-v2/config v1.15.0
-	github.com/aws/aws-sdk-go-v2/service/ec2 v1.50.0
+	github.com/aws/aws-sdk-go-v2/service/ec2 v1.49.0
 	github.com/aws/aws-sdk-go-v2/service/lambda v1.23.0
 	github.com/aws/aws-sdk-go-v2/service/s3 v1.27.1
 	github.com/aws/aws-sdk-go-v2/service/sts v1.16.0
diff --git a/go.sum b/go.sum
index 8fa6b861..8af44db2 100644
--- a/go.sum
+++ b/go.sum
@@ -180,8 +180,8 @@ github.com/aws/aws-sdk-go-v2/internal/ini v1.3.7 h1:QOMEP8jnO8sm0SX/4G7dbaIq2eEP
 github.com/aws/aws-sdk-go-v2/internal/ini v1.3.7/go.mod h1:P5sjYYf2nc5dE6cZIzEMsVtq6XeLD7c4rM+kQJPrByA=
 github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.5 h1:tEEHn+PGAxRVqMPEhtU8oCSW/1Ge3zP5nUgPrGQNUPs=
 github.com/aws/aws-sdk-go-v2/internal/v4a v1.0.5/go.mod h1:aIwFF3dUk95ocCcA3zfk3nhz0oLkpzHFWuMp8l/4nNs=
-github.com/aws/aws-sdk-go-v2/service/ec2 v1.50.0 h1:OMzx7qC+hOYJoQYq7RnYkjgCnKTsdIcEM08AUtsXH6A=
-github.com/aws/aws-sdk-go-v2/service/ec2 v1.50.0/go.mod h1:VoBcwURHnJVCWuXHdqVuG03i2lUlHJ5DTTqDSyCdEcc=
+github.com/aws/aws-sdk-go-v2/service/ec2 v1.49.0 h1:X+FiYw5iyCDaqa9+tMZlqcIB7PudQOXR+FOlbIoa7XE=
+github.com/aws/aws-sdk-go-v2/service/ec2 v1.49.0/go.mod h1:VoBcwURHnJVCWuXHdqVuG03i2lUlHJ5DTTqDSyCdEcc=
 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3 h1:4n4KCtv5SUoT5Er5XV41huuzrCqepxlW3SDI9qHQebc=
 github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.9.3/go.mod h1:gkb2qADY+OHaGLKNTYxMaQNacfeyQpZ4csDTQMeFmcw=
 github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.1.9 h1:gVv2vXOMqJeR4ZHHV32K7LElIJIIzyw/RU1b0lSfWTQ=
diff --git a/service/discovery/azure/azure.go b/service/discovery/azure/azure.go
index 7f93ed54..57423536 100644
--- a/service/discovery/azure/azure.go
+++ b/service/discovery/azure/azure.go
@@ -42,6 +42,12 @@ import (
 	"clouditor.io/clouditor/internal/util"
 )
 
+const (
+	StorageComponent = "storage"
+	ComputeComponent = "compute"
+	NetworkComponent = "network"
+)
+
 var (
 	log *logrus.Entry
 
@@ -72,9 +78,10 @@ func init() {
 type azureDiscovery struct {
 	isAuthorized bool
 
-	sub           armsubscription.Subscription
-	cred          azcore.TokenCredential
-	clientOptions arm.ClientOptions
+	sub                 armsubscription.Subscription
+	cred                azcore.TokenCredential
+	clientOptions       arm.ClientOptions
+	discovererComponent string
 }
 
 func (a *azureDiscovery) authorize() (err error) {
@@ -115,7 +122,7 @@ func (a *azureDiscovery) authorize() (err error) {
 	// get first subscription
 	a.sub = *subList[0]
 
-	log.Infof("Using %s as subscription", *a.sub.SubscriptionID)
+	log.Infof("Azure %s discoverer uses %s as subscription", a.discovererComponent, *a.sub.SubscriptionID)
 
 	a.isAuthorized = true
 
diff --git a/service/discovery/azure/compute.go b/service/discovery/azure/compute.go
index 730de642..69e696fe 100644
--- a/service/discovery/azure/compute.go
+++ b/service/discovery/azure/compute.go
@@ -47,7 +47,11 @@ type azureComputeDiscovery struct {
 }
 
 func NewAzureComputeDiscovery(opts ...DiscoveryOption) discovery.Discoverer {
-	d := &azureComputeDiscovery{}
+	d := &azureComputeDiscovery{
+		azureDiscovery{
+			discovererComponent: ComputeComponent,
+		},
+	}
 
 	// Apply options
 	for _, opt := range opts {
diff --git a/service/discovery/azure/network.go b/service/discovery/azure/network.go
index 8877506f..518892df 100644
--- a/service/discovery/azure/network.go
+++ b/service/discovery/azure/network.go
@@ -41,7 +41,11 @@ type azureNetworkDiscovery struct {
 }
 
 func NewAzureNetworkDiscovery(opts ...DiscoveryOption) discovery.Discoverer {
-	d := &azureNetworkDiscovery{}
+	d := &azureNetworkDiscovery{
+		azureDiscovery{
+			discovererComponent: NetworkComponent,
+		},
+	}
 
 	// Apply options
 	for _, opt := range opts {
@@ -208,8 +212,8 @@ func LoadBalancerPorts(lb *armnetwork.LoadBalancer) (loadBalancerPorts []uint16)
 	return loadBalancerPorts
 }
 
-//// Returns all restricted ports for the network interface
-//func (d *azureNetworkDiscovery) getRestrictedPorts(ni *network.Interface) string {
+// // Returns all restricted ports for the network interface
+// func (d *azureNetworkDiscovery) getRestrictedPorts(ni *network.Interface) string {
 //
 //     var restrictedPorts []string
 //
@@ -243,9 +247,9 @@ func LoadBalancerPorts(lb *armnetwork.LoadBalancer) (loadBalancerPorts []uint16)
 //     restrictedPortsClean := deleteDuplicatesFromSlice(restrictedPorts)
 //
 //     return strings.Join(restrictedPortsClean, ",")
-//}
+// }
 //
-//func deleteDuplicatesFromSlice(intSlice []string) []string {
+// func deleteDuplicatesFromSlice(intSlice []string) []string {
 //     keys := make(map[string]bool)
 //     var list []string
 //     for _, entry := range intSlice {
@@ -255,7 +259,7 @@ func LoadBalancerPorts(lb *armnetwork.LoadBalancer) (loadBalancerPorts []uint16)
 //             }
 //     }
 //     return list
-//}
+// }
 
 func (d *azureNetworkDiscovery) publicIPAddressFromLoadBalancer(lb *armnetwork.LoadBalancer) []string {
 
diff --git a/service/discovery/azure/storage.go b/service/discovery/azure/storage.go
index 04244711..abe50905 100644
--- a/service/discovery/azure/storage.go
+++ b/service/discovery/azure/storage.go
@@ -49,7 +49,11 @@ type azureStorageDiscovery struct {
 }
 
 func NewAzureStorageDiscovery(opts ...DiscoveryOption) discovery.Discoverer {
-	d := &azureStorageDiscovery{}
+	d := &azureStorageDiscovery{
+		azureDiscovery{
+			discovererComponent: StorageComponent,
+		},
+	}
 
 	// Apply options
 	for _, opt := range opts {


Test patch:
diff --git a/service/discovery/azure/compute_test.go b/service/discovery/azure/compute_test.go
index 9ea23c5c..88656c0c 100644
--- a/service/discovery/azure/compute_test.go
+++ b/service/discovery/azure/compute_test.go
@@ -38,6 +38,7 @@ import (
 	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/appservice/armappservice/v2"
 	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription"
 
+	"clouditor.io/clouditor/api/discovery"
 	"clouditor.io/clouditor/internal/util"
 	"clouditor.io/clouditor/voc"
 
@@ -179,6 +180,64 @@ func (m mockComputeSender) Do(req *http.Request) (res *http.Response, err error)
 	return m.mockSender.Do(req)
 }
 
+func TestNewAzureComputeDiscovery(t *testing.T) {
+	type args struct {
+		opts []DiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want discovery.Discoverer
+	}{
+		{
+			name: "Empty input",
+			args: args{
+				opts: nil,
+			},
+			want: &azureComputeDiscovery{
+				azureDiscovery{
+					discovererComponent: ComputeComponent,
+				},
+			},
+		},
+		{
+			name: "With sender",
+			args: args{
+				opts: []DiscoveryOption{WithSender(mockComputeSender{})},
+			},
+			want: &azureComputeDiscovery{
+				azureDiscovery{
+					clientOptions: arm.ClientOptions{
+						ClientOptions: policy.ClientOptions{
+							Transport: mockComputeSender{},
+						},
+					},
+					discovererComponent: ComputeComponent,
+				},
+			},
+		},
+		{
+			name: "With authorizer",
+			args: args{
+				opts: []DiscoveryOption{WithAuthorizer(&mockAuthorizer{})},
+			},
+			want: &azureComputeDiscovery{
+				azureDiscovery{
+					cred:                &mockAuthorizer{},
+					discovererComponent: ComputeComponent,
+				},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := NewAzureComputeDiscovery(tt.args.opts...)
+			assert.Equal(t, tt.want, d)
+			assert.Equal(t, "Azure Compute", d.Name())
+		})
+	}
+}
+
 func TestAzureComputeAuthorizer(t *testing.T) {
 
 	d := NewAzureComputeDiscovery()
@@ -719,7 +778,7 @@ func Test_azureComputeDiscovery_discoverVirtualMachines(t *testing.T) {
 		wantErr assert.ErrorAssertionFunc
 	}{
 		// TODO(anatheka): Wo kommt die panic her?
-		//{
+		// {
 		//	name: "Error list pages",
 		//	fields: fields{
 		//		azureDiscovery: azureDiscovery{
@@ -731,7 +790,7 @@ func Test_azureComputeDiscovery_discoverVirtualMachines(t *testing.T) {
 		//	wantErr: func(t assert.TestingT, err error, i ...interface{}) bool {
 		//		return assert.ErrorContains(t, err, ErrGettingNextPage.Error())
 		//	},
-		//},
+		// },
 		{
 			name: "No error",
 			fields: fields{
diff --git a/service/discovery/azure/network_test.go b/service/discovery/azure/network_test.go
index 0b4c214b..4bcefb55 100644
--- a/service/discovery/azure/network_test.go
+++ b/service/discovery/azure/network_test.go
@@ -362,7 +362,11 @@ func TestNewAzureNetworkDiscovery(t *testing.T) {
 			args: args{
 				opts: nil,
 			},
-			want: &azureNetworkDiscovery{},
+			want: &azureNetworkDiscovery{
+				azureDiscovery{
+					discovererComponent: NetworkComponent,
+				},
+			},
 		},
 		{
 			name: "With sender",
@@ -376,6 +380,7 @@ func TestNewAzureNetworkDiscovery(t *testing.T) {
 							Transport: mockNetworkSender{},
 						},
 					},
+					discovererComponent: NetworkComponent,
 				},
 			},
 		},
@@ -386,7 +391,8 @@ func TestNewAzureNetworkDiscovery(t *testing.T) {
 			},
 			want: &azureNetworkDiscovery{
 				azureDiscovery{
-					cred: &mockAuthorizer{},
+					cred:                &mockAuthorizer{},
+					discovererComponent: NetworkComponent,
 				},
 			},
 		},
diff --git a/service/discovery/azure/storage_test.go b/service/discovery/azure/storage_test.go
index f6b3f89f..00b14cb8 100644
--- a/service/discovery/azure/storage_test.go
+++ b/service/discovery/azure/storage_test.go
@@ -37,6 +37,7 @@ import (
 	"github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/subscription/armsubscription"
 	"k8s.io/apimachinery/pkg/util/json"
 
+	"clouditor.io/clouditor/api/discovery"
 	"clouditor.io/clouditor/internal/util"
 	"clouditor.io/clouditor/voc"
 
@@ -274,6 +275,64 @@ func (m mockStorageSender) Do(req *http.Request) (res *http.Response, err error)
 	return m.mockSender.Do(req)
 }
 
+func TestNewAzureStorageDiscovery(t *testing.T) {
+	type args struct {
+		opts []DiscoveryOption
+	}
+	tests := []struct {
+		name string
+		args args
+		want discovery.Discoverer
+	}{
+		{
+			name: "Empty input",
+			args: args{
+				opts: nil,
+			},
+			want: &azureStorageDiscovery{
+				azureDiscovery{
+					discovererComponent: StorageComponent,
+				},
+			},
+		},
+		{
+			name: "With sender",
+			args: args{
+				opts: []DiscoveryOption{WithSender(mockStorageSender{})},
+			},
+			want: &azureStorageDiscovery{
+				azureDiscovery{
+					clientOptions: arm.ClientOptions{
+						ClientOptions: policy.ClientOptions{
+							Transport: mockStorageSender{},
+						},
+					},
+					discovererComponent: StorageComponent,
+				},
+			},
+		},
+		{
+			name: "With authorizer",
+			args: args{
+				opts: []DiscoveryOption{WithAuthorizer(&mockAuthorizer{})},
+			},
+			want: &azureStorageDiscovery{
+				azureDiscovery{
+					cred:                &mockAuthorizer{},
+					discovererComponent: StorageComponent,
+				},
+			},
+		},
+	}
+	for _, tt := range tests {
+		t.Run(tt.name, func(t *testing.T) {
+			d := NewAzureStorageDiscovery(tt.args.opts...)
+			assert.Equal(t, tt.want, d)
+			assert.Equal(t, "Azure Storage Account", d.Name())
+		})
+	}
+}
+
 func TestAzureStorageAuthorizer(t *testing.T) {
 
 	d := NewAzureStorageDiscovery()