Repository: clouditor/clouditor
Pull request #474 (2022-01-29 13:54:35)

Implement `HasAtRestEncryption` for `*AtRestEncryption`

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

[![Impacted file tree graph](https://codecov.io/gh/clouditor/clouditor/pull/474/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/474?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor)

```diff
@@            Coverage Diff             @@
##             main     #474      +/-   ##
==========================================
+ Coverage   76.00%   76.05%   +0.05%     
==========================================
  Files          44       44              
  Lines        3750     3750              
==========================================
+ Hits         2850     2852       +2     
+ Misses        774      772       -2     
  Partials      126      126              
```

| Flag | Coverage Δ | |
|---|---|---|
| unittests | `76.05% <100.00%> (+0.05%)` | :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/474?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor) | Coverage Δ | |
|---|---|---|
| [service/discovery/aws/storage.go](https://codecov.io/gh/clouditor/clouditor/pull/474/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-c2VydmljZS9kaXNjb3ZlcnkvYXdzL3N0b3JhZ2UuZ28=) | `83.24% <100.00%> (ø)` | |
| [voc/at\_rest\_encryption.go](https://codecov.io/gh/clouditor/clouditor/pull/474/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor#diff-dm9jL2F0X3Jlc3RfZW5jcnlwdGlvbi5nbw==) | `100.00% <100.00%> (+100.00%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/clouditor/clouditor/pull/474?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/474?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=clouditor). Last update [9e44adc...d346ecb](https://codecov.io/gh/clouditor/clouditor/pull/474?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/service/discovery/aws/storage.go b/service/discovery/aws/storage.go
index fa5b464b..44403f93 100644
--- a/service/discovery/aws/storage.go
+++ b/service/discovery/aws/storage.go
@@ -32,9 +32,10 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
-	"github.com/aws/aws-sdk-go-v2/service/s3/types"
 	"time"
 
+	"github.com/aws/aws-sdk-go-v2/service/s3/types"
+
 	"clouditor.io/clouditor/api/discovery"
 	"clouditor.io/clouditor/voc"
 	"github.com/aws/aws-sdk-go-v2/aws"
@@ -208,7 +209,7 @@ func (d *awsS3Discovery) getEncryptionAtRest(bucket bucket) (e voc.HasAtRestEncr
 		if errors.As(err, &ae) {
 			if ae.ErrorCode() == "ServerSideEncryptionConfigurationNotFoundError" {
 				// This error code is equivalent to "encryption not enabled": set err to nil
-				e = voc.AtRestEncryption{
+				e = &voc.AtRestEncryption{
 					Confidentiality: nil,
 					Algorithm:       "",
 					Enabled:         false,
diff --git a/voc/at_rest_encryption.go b/voc/at_rest_encryption.go
index cc812e93..4af845b6 100644
--- a/voc/at_rest_encryption.go
+++ b/voc/at_rest_encryption.go
@@ -31,7 +31,6 @@ type AtRestEncryption struct {
 	Enabled   bool   `json:"enabled"`
 }
 
-// TODO(all): I (lebogg) think we have to implement the interface for the case of encryption being not enabled?
-func (AtRestEncryption) GetAtRestEncryption() *AtRestEncryption {
-	panic("implement me")
+func (a AtRestEncryption) GetAtRestEncryption() *AtRestEncryption {
+	return &a
 }


Test patch:
diff --git a/service/discovery/aws/storage_test.go b/service/discovery/aws/storage_test.go
index b8a97d13..847c7072 100644
--- a/service/discovery/aws/storage_test.go
+++ b/service/discovery/aws/storage_test.go
@@ -28,13 +28,14 @@
 package aws
 
 import (
-	"clouditor.io/clouditor/voc"
 	"context"
 	"encoding/json"
 	"errors"
 	"testing"
 	"time"
 
+	"clouditor.io/clouditor/voc"
+
 	"github.com/aws/aws-sdk-go-v2/aws"
 	"github.com/aws/aws-sdk-go-v2/service/s3"
 	"github.com/aws/aws-sdk-go-v2/service/s3/types"
@@ -337,10 +338,10 @@ func TestAwsS3Discovery_getEncryptionAtRest(t *testing.T) {
 		encryptionAtRest   voc.HasAtRestEncryption
 		managedEncryption  voc.ManagedKeyEncryption
 		customerEncryption voc.CustomerKeyEncryption
-		atRestEncryption   voc.AtRestEncryption
-		ok                 bool
-		err                error
-		mockAccountID      = "123456789"
+
+		ok            bool
+		err           error
+		mockAccountID = "123456789"
 	)
 
 	d := awsS3Discovery{
@@ -371,10 +372,8 @@ func TestAwsS3Discovery_getEncryptionAtRest(t *testing.T) {
 
 	// Third case: No encryption
 	encryptionAtRest, err = d.getEncryptionAtRest(bucket{name: "mockbucket3"})
-	atRestEncryption, ok = encryptionAtRest.(voc.AtRestEncryption)
-	assert.True(t, ok)
 	assert.Nil(t, err)
-	assert.False(t, atRestEncryption.Enabled)
+	assert.False(t, encryptionAtRest.GetAtRestEncryption().Enabled)
 
 	// 4th case: Connection error
 	d = awsS3Discovery{