Repository: clouditor/clouditor
Pull request #346 (2021-11-04 10:01:07)

Minor enhancements

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

[![Impacted file tree graph](https://codecov.io/gh/clouditor/clouditor/pull/346/graphs/tree.svg?width=650&height=150&src=pr&token=syrXsw5LTX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)](https://codecov.io/gh/clouditor/clouditor/pull/346?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)

```diff
@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
+ Coverage   65.91%   66.00%   +0.09%     
==========================================
  Files          38       38              
  Lines        2215     2221       +6     
==========================================
+ Hits         1460     1466       +6     
  Misses        634      634              
  Partials      121      121              
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `66.00% <100.00%> (+0.09%)` | :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/346?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) | Coverage Δ | |
|---|---|---|
| [service/discovery/azure/iac\_template.go](https://codecov.io/gh/clouditor/clouditor/pull/346/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvYXp1cmUvaWFjX3RlbXBsYXRlLmdv) | `82.30% <100.00%> (+0.41%)` | :arrow_up: |
| [service/discovery/discovery.go](https://codecov.io/gh/clouditor/clouditor/pull/346/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvZGlzY292ZXJ5Lmdv) | `51.42% <100.00%> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/clouditor/clouditor/pull/346?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/346?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Last update [58a7e43...e0232ea](https://codecov.io/gh/clouditor/clouditor/pull/346?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/api/discovery/discovery.pb.go b/api/discovery/discovery.pb.go
index c4854d18..f806ea89 100644
--- a/api/discovery/discovery.pb.go
+++ b/api/discovery/discovery.pb.go
@@ -185,7 +185,7 @@ type QueryResponse struct {
 	sizeCache     protoimpl.SizeCache
 	unknownFields protoimpl.UnknownFields
 
-	Result *structpb.ListValue `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"`
+	Results *structpb.ListValue `protobuf:"bytes,1,opt,name=results,proto3" json:"results,omitempty"`
 }
 
 func (x *QueryResponse) Reset() {
@@ -220,9 +220,9 @@ func (*QueryResponse) Descriptor() ([]byte, []int) {
 	return file_discovery_proto_rawDescGZIP(), []int{3}
 }
 
-func (x *QueryResponse) GetResult() *structpb.ListValue {
+func (x *QueryResponse) GetResults() *structpb.ListValue {
 	if x != nil {
-		return x.Result
+		return x.Results
 	}
 	return nil
 }
@@ -244,26 +244,26 @@ var file_discovery_proto_rawDesc = []byte{
 	0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x66,
 	0x69, 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01,
 	0x28, 0x09, 0x52, 0x0c, 0x66, 0x69, 0x6c, 0x74, 0x65, 0x72, 0x65, 0x64, 0x54, 0x79, 0x70, 0x65,
-	0x22, 0x43, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
-	0x65, 0x12, 0x32, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28,
-	0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
-	0x62, 0x75, 0x66, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x06, 0x72,
-	0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, 0xdb, 0x01, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76,
-	0x65, 0x72, 0x79, 0x12, 0x6f, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x20, 0x2e, 0x63,
-	0x6c, 0x6f, 0x75, 0x64, 0x69, 0x74, 0x6f, 0x72, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74, 0x44, 0x69,
-	0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21,
+	0x22, 0x45, 0x0a, 0x0d, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
+	0x65, 0x12, 0x34, 0x0a, 0x07, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x18, 0x01, 0x20, 0x01,
+	0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74,
+	0x6f, 0x62, 0x75, 0x66, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x07,
+	0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x73, 0x32, 0xdb, 0x01, 0x0a, 0x09, 0x44, 0x69, 0x73, 0x63,
+	0x6f, 0x76, 0x65, 0x72, 0x79, 0x12, 0x6f, 0x0a, 0x05, 0x53, 0x74, 0x61, 0x72, 0x74, 0x12, 0x20,
 	0x2e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x69, 0x74, 0x6f, 0x72, 0x2e, 0x53, 0x74, 0x61, 0x72, 0x74,
-	0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
-	0x65, 0x22, 0x21, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x22, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x64,
-	0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x3a, 0x01,
-	0x2a, 0x62, 0x01, 0x2a, 0x12, 0x5d, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12, 0x17, 0x2e,
-	0x63, 0x6c, 0x6f, 0x75, 0x64, 0x69, 0x74, 0x6f, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52,
-	0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x69, 0x74,
-	0x6f, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
-	0x22, 0x21, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x22, 0x13, 0x2f, 0x76, 0x31, 0x2f, 0x64, 0x69,
-	0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x3a, 0x01, 0x2a,
-	0x62, 0x01, 0x2a, 0x42, 0x0f, 0x5a, 0x0d, 0x61, 0x70, 0x69, 0x2f, 0x64, 0x69, 0x73, 0x63, 0x6f,
-	0x76, 0x65, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
+	0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
+	0x1a, 0x21, 0x2e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x69, 0x74, 0x6f, 0x72, 0x2e, 0x53, 0x74, 0x61,
+	0x72, 0x74, 0x44, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f,
+	0x6e, 0x73, 0x65, 0x22, 0x21, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x22, 0x13, 0x2f, 0x76, 0x31,
+	0x2f, 0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2f, 0x73, 0x74, 0x61, 0x72, 0x74,
+	0x3a, 0x01, 0x2a, 0x62, 0x01, 0x2a, 0x12, 0x5d, 0x0a, 0x05, 0x51, 0x75, 0x65, 0x72, 0x79, 0x12,
+	0x17, 0x2e, 0x63, 0x6c, 0x6f, 0x75, 0x64, 0x69, 0x74, 0x6f, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72,
+	0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x63, 0x6c, 0x6f, 0x75, 0x64,
+	0x69, 0x74, 0x6f, 0x72, 0x2e, 0x51, 0x75, 0x65, 0x72, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e,
+	0x73, 0x65, 0x22, 0x21, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x1b, 0x22, 0x13, 0x2f, 0x76, 0x31, 0x2f,
+	0x64, 0x69, 0x73, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x2f, 0x71, 0x75, 0x65, 0x72, 0x79, 0x3a,
+	0x01, 0x2a, 0x62, 0x01, 0x2a, 0x42, 0x0f, 0x5a, 0x0d, 0x61, 0x70, 0x69, 0x2f, 0x64, 0x69, 0x73,
+	0x63, 0x6f, 0x76, 0x65, 0x72, 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
 }
 
 var (
@@ -287,7 +287,7 @@ var file_discovery_proto_goTypes = []interface{}{
 	(*structpb.ListValue)(nil),     // 4: google.protobuf.ListValue
 }
 var file_discovery_proto_depIdxs = []int32{
-	4, // 0: clouditor.QueryResponse.result:type_name -> google.protobuf.ListValue
+	4, // 0: clouditor.QueryResponse.results:type_name -> google.protobuf.ListValue
 	0, // 1: clouditor.Discovery.Start:input_type -> clouditor.StartDiscoveryRequest
 	2, // 2: clouditor.Discovery.Query:input_type -> clouditor.QueryRequest
 	1, // 3: clouditor.Discovery.Start:output_type -> clouditor.StartDiscoveryResponse
diff --git a/openapi/discovery/openapi.yaml b/openapi/discovery/openapi.yaml
index 9ba2bdc0..43ed4917 100644
--- a/openapi/discovery/openapi.yaml
+++ b/openapi/discovery/openapi.yaml
@@ -57,7 +57,7 @@ components:
                     type: string
         QueryResponse:
             properties:
-                result:
+                results:
                     $ref: '#/components/schemas/ListValue'
         StartDiscoveryRequest:
             properties: {}
diff --git a/proto/README.md b/proto/README.md
index 9cdb988a..e52f8570 100644
--- a/proto/README.md
+++ b/proto/README.md
@@ -1,36 +1,37 @@
-- # Protobuf API
-- 
-- ## Style Conventions
-- 
-- This folder contains all protobuf files that we have defined. We follow the Google Cloud's [API design
-- guide](https://cloud.google.com/apis/design/), including the following conventions:
-- 
-- * Ordering:
--   1. _syntax, package, import, option_ statements
--   2. overview documentation
--   3. _service_ definition(s)
--   4. request and response messages (ordered as respective methods)
--   5. resource messages while parents are defined before child resources
-- * File names: 
--   * <lower_case_underscore_separated_names>.proto
--   * File name corresponding to (single) service
-- * proto file only containing resources, consider naming this file simply as resources.proto
-- * ENUM (Scale): The first value should be named ENUM_TYPE_UNSPECIFIED
-- * Commenting: Comment services, RPCs and messages
-- * Request and response messages
--   * **Standard methods** use request and response messages according to the following table (see [Cloud APIs Naming conventions](https://cloud.google.com/apis/design/naming_convention#method_names)). 
-- 
-| -   | Method name | Request Body      | Response Body         |
-| --- | ----------- | ----------------- | --------------------- |
-| -   | ListBooks   | ListBooksRequest  | List*Response         |
-| -   | GetBook     | GetBookRequest    | Book                  |
-| -   | CreateBook  | CreateBookRequest | Book                  |
-| -   | UpdateBook  | UpdateBookRequest | Book                  |
-| -   | RenameBook  | RenameBookRequest | RenameBookResponse    |
-| -   | DeleteBook  | DeleteBookRequest | google.brotobuf.Empty |
--   * A **custom method** should have a response message even if it is empty (see [Cloud APIs Common design patterns](https://cloud.google.com/apis/design/design_patterns#empty_responses)).
--   * If we *transfer* a single resource, e.g. in the case of `StoreEvidence`, it is not necessary to create an additional `StoreEvidenceRequest`, instead `Evidence` can be used.
-- 
-- ## Generate Go files
-- 
-- In order to generate all necessary Go files, the command `go generate ./...` can be used.
\ No newline at end of file
+# Protobuf API
+
+## Style Conventions
+
+This folder contains all protobuf files that we have defined. We follow the Google Cloud's [API design
+guide](https://cloud.google.com/apis/design/), including the following conventions:
+
+* Ordering:
+  1. _syntax, package, import, option_ statements
+  2. overview documentation
+  3. _service_ definition(s)
+  4. request and response messages (ordered as respective methods)
+  5. resource messages while parents are defined before child resources
+* File names: 
+  * <lower_case_underscore_separated_names>.proto
+  * File name corresponding to (single) service
+* proto file only containing resources, consider naming this file simply as resources.proto
+* ENUM (Scale): The first value should be named ENUM_TYPE_UNSPECIFIED
+* Commenting: Comment services, RPCs and messages
+* Request and response messages
+  * **Standard methods** use request and response messages according to the following table (see [Cloud APIs Naming conventions](https://cloud.google.com/apis/design/naming_convention#method_names)). 
+
+| Method name | Request Body      | Response Body         |
+| ----------- | ----------------- | --------------------- |
+| ListBooks   | ListBooksRequest  | List*Response         |
+| GetBook     | GetBookRequest    | Book                  |
+| CreateBook  | CreateBookRequest | Book                  |
+| UpdateBook  | UpdateBookRequest | Book                  |
+| RenameBook  | RenameBookRequest | RenameBookResponse    |
+| DeleteBook  | DeleteBookRequest | google.brotobuf.Empty |
+
+* A **custom method** should have a response message even if it is empty (see [Cloud APIs Common design patterns](https://cloud.google.com/apis/design/design_patterns#empty_responses)).
+* If we *transfer* a single resource, e.g. in the case of `StoreEvidence`, it is not necessary to create an additional `StoreEvidenceRequest`, instead `Evidence` can be used.
+
+## Generate Go files
+
+In order to generate all necessary Go files, the command `go generate ./...` can be used.
diff --git a/proto/discovery.proto b/proto/discovery.proto
index d83e0ae5..de185357 100644
--- a/proto/discovery.proto
+++ b/proto/discovery.proto
@@ -60,4 +60,4 @@ message StartDiscoveryResponse { bool successful = 1; }
 
 message QueryRequest { string filtered_type = 1; }
 
-message QueryResponse { google.protobuf.ListValue result = 1; }
\ No newline at end of file
+message QueryResponse { google.protobuf.ListValue results = 1; }
\ No newline at end of file
diff --git a/service/discovery/azure/iac_template.go b/service/discovery/azure/iac_template.go
index c6604fa3..d9461f64 100644
--- a/service/discovery/azure/iac_template.go
+++ b/service/discovery/azure/iac_template.go
@@ -230,7 +230,6 @@ func (d *azureIacTemplateDiscovery) handleObjectStorage(resourceValue map[string
 		return nil, fmt.Errorf("cannot get atRestEncryption for storage account resource from IaC template: %v", err)
 	}
 
-
 	storage = &voc.ObjectStorage{
 		Storage: &voc.Storage{
 			CloudResource: &voc.CloudResource{
@@ -424,6 +423,9 @@ func (d *azureIacTemplateDiscovery) handleLoadBalancer(resourceValue map[string]
 					Name:         name,
 					CreationTime: 0, // No creation time available
 					Type:         []string{"LoadBalancer", "NetworkService", "Resource"},
+					GeoLocation: voc.GeoLocation{
+						Region: resourceValue["location"].(string),
+					},
 				},
 			},
 			Compute: []voc.ResourceID{},
@@ -485,6 +487,9 @@ func (d *azureIacTemplateDiscovery) handleVirtualMachine(resourceValue map[strin
 				Name:         name,
 				CreationTime: 0, // No creation time available
 				Type:         []string{"VirtualMachine", "Compute", "Resource"},
+				GeoLocation: voc.GeoLocation{
+					Region: resourceValue["location"].(string),
+				},
 			},
 		},
 		BootLog: &voc.BootLog{
diff --git a/service/discovery/discovery.go b/service/discovery/discovery.go
index 0f88d579..0ab09766 100644
--- a/service/discovery/discovery.go
+++ b/service/discovery/discovery.go
@@ -262,7 +262,7 @@ func (s Service) Query(_ context.Context, request *discovery.QueryRequest) (resp
 	}
 
 	return &discovery.QueryResponse{
-		Result: &structpb.ListValue{Values: r},
+		Results: &structpb.ListValue{Values: r},
 	}, nil
 }
 


Test patch:
diff --git a/service/discovery/azure/iac_template_test.go b/service/discovery/azure/iac_template_test.go
index 05a316f9..e46eccb4 100644
--- a/service/discovery/azure/iac_template_test.go
+++ b/service/discovery/azure/iac_template_test.go
@@ -365,6 +365,26 @@ func TestVmProperties(t *testing.T) {
 	assert.Equal(t, "vm-1-2", resourceVM.Name)
 	assert.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/res1/providers/Microsoft.Compute/virtualMachines/vm-1-2", (string)(resourceVM.GetID()))
 	assert.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/res1/providers/Microsoft.Compute/disks/blockStorage3", (string)(resourceVM.BlockStorage[0]))
+	assert.Equal(t, "eastus", resourceVM.GeoLocation.Region)
 	assert.True(t, resourceVM.BootLog.Enabled)
 	assert.False(t, resourceVM.OSLog.Enabled)
 }
+
+func TestLoadBalancerProperties(t *testing.T) {
+	d := azure.NewAzureIacTemplateDiscovery(
+		azure.WithSender(&mockIacTemplateSender{}),
+		azure.WithAuthorizer(&mockAuthorizer{}),
+	)
+
+	list, err := d.List()
+
+	assert.Nil(t, err)
+	assert.NotNil(t, list)
+
+	resourceLoadBalancer, ok := list[6].(*voc.LoadBalancer)
+	assert.True(t, ok)
+	assert.Equal(t, "kubernetes", resourceLoadBalancer.Name)
+	assert.Equal(t, "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/res2/providers/Microsoft.Network/loadBalancers/kubernetes", (string)(resourceLoadBalancer.GetID()))
+	assert.Equal(t, "LoadBalancer", resourceLoadBalancer.Type[0])
+	assert.Equal(t, "eastus", resourceLoadBalancer.GeoLocation.Region)
+}
diff --git a/service/discovery/discovery_test.go b/service/discovery/discovery_test.go
index 5fbc24d6..9daf1f38 100644
--- a/service/discovery/discovery_test.go
+++ b/service/discovery/discovery_test.go
@@ -167,7 +167,7 @@ func TestQuery(t *testing.T) {
 			if err != nil {
 				return
 			}
-			assert.Equal(t, tt.numberOfQueriedResources, len(response.Result.Values))
+			assert.Equal(t, tt.numberOfQueriedResources, len(response.Results.Values))
 		})
 		// If a bad resource was added it will be removed. Otherwise no-op
 		delete(s.resources, "MockResourceId")