Skip to content
This repository was archived by the owner on Sep 30, 2020. It is now read-only.

Commit 1ceb039

Browse files
committed
refactoring: Make the Compact func and the KMS ecryption interface
which is used for compacting TLSassets more open to be reused from other packages This makes implementing the upcoming node pools feature a bit easier.
1 parent ef94360 commit 1ceb039

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

config/config.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func newDefaultCluster() *Cluster {
9393
}
9494
}
9595

96-
func newDefaultClusterWithDeps(encSvc encryptService) *Cluster {
96+
func newDefaultClusterWithDeps(encSvc EncryptService) *Cluster {
9797
cluster := newDefaultCluster()
9898
cluster.providedEncryptService = encSvc
9999
return cluster
@@ -200,7 +200,7 @@ type Cluster struct {
200200
ElasticFileSystemID string `yaml:"elasticFileSystemId,omitempty"`
201201
SSHAuthorizedKeys []string `yaml:"sshAuthorizedKeys,omitempty"`
202202
Experimental Experimental `yaml:"experimental"`
203-
providedEncryptService encryptService
203+
providedEncryptService EncryptService
204204
IsChinaRegion bool
205205
}
206206

@@ -449,14 +449,14 @@ func (c Cluster) stackConfig(opts StackTemplateOptions, compressUserData bool) (
449449
WithCredentialsChainVerboseErrors(true)
450450

451451
// TODO Cleaner way to inject this dependency
452-
var kmsSvc encryptService
452+
var kmsSvc EncryptService
453453
if c.providedEncryptService != nil {
454454
kmsSvc = c.providedEncryptService
455455
} else {
456456
kmsSvc = kms.New(session.New(awsConfig))
457457
}
458458

459-
compactAssets, err := assets.compact(stackConfig.Config, kmsSvc)
459+
compactAssets, err := assets.Compact(stackConfig.Config.KMSKeyARN, kmsSvc)
460460
if err != nil {
461461
return nil, fmt.Errorf("failed to compress TLS assets: %v", err)
462462
}

config/tls_config.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -237,19 +237,19 @@ func (r *RawTLSAssets) WriteToDir(dirname string, includeCAKey bool) error {
237237
return nil
238238
}
239239

240-
type encryptService interface {
240+
type EncryptService interface {
241241
Encrypt(*kms.EncryptInput) (*kms.EncryptOutput, error)
242242
}
243243

244-
func (r *RawTLSAssets) compact(cfg *Config, kmsSvc encryptService) (*CompactTLSAssets, error) {
244+
func (r *RawTLSAssets) Compact(kMSKeyARN string, kmsSvc EncryptService) (*CompactTLSAssets, error) {
245245
var err error
246246
compact := func(data []byte) string {
247247
if err != nil {
248248
return ""
249249
}
250250

251251
encryptInput := kms.EncryptInput{
252-
KeyId: aws.String(cfg.KMSKeyARN),
252+
KeyId: aws.String(kMSKeyARN),
253253
Plaintext: data,
254254
}
255255

config/user_data_config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestCloudConfigTemplating(t *testing.T) {
3737
t.Fatalf("Failed to create config: %v", err)
3838
}
3939

40-
compactAssets, err := assets.compact(cfg, &dummyEncryptService{})
40+
compactAssets, err := assets.Compact(cfg.KMSKeyARN, &dummyEncryptService{})
4141
if err != nil {
4242
t.Fatalf("failed to compress TLS assets: %v", err)
4343
}

0 commit comments

Comments
 (0)