-
Notifications
You must be signed in to change notification settings - Fork 339
/
postgres.go
528 lines (470 loc) · 18.8 KB
/
postgres.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
// Package postgres provides a TrafficVault implementation which uses PostgreSQL as the backend.
package postgres
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import (
"context"
"database/sql"
"encoding/json"
"errors"
"fmt"
"strconv"
"time"
"github.com/apache/trafficcontrol/lib/go-log"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-tc/tovalidate"
"github.com/apache/trafficcontrol/lib/go-util"
"github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/trafficvault"
validation "github.com/go-ozzo/ozzo-validation"
"github.com/go-ozzo/ozzo-validation/is"
"github.com/jmoiron/sqlx"
"github.com/lib/pq"
)
type Error string
func (e Error) Error() string {
return string(e)
}
const (
notImplementedErr = Error("this Traffic Vault functionality is not implemented for the postgres backend")
postgresBackendName = "postgres"
defaultMaxIdleConnections = 10 // if this is higher than MaxDBConnections it will be automatically adjusted below it by the db/sql library
defaultConnMaxLifetimeSeconds = 60
defaultDBQueryTimeoutSecs = 30
defaultHashiCorpVaultLoginPath = "/v1/auth/approle/login"
defaultHashiCorpVaultTimeoutSec = 30
latestVersion = "latest"
)
type Config struct {
DBName string `json:"dbname"`
Hostname string `json:"hostname"`
User string `json:"user"`
Password string `json:"password"`
Port int `json:"port"`
SSL bool `json:"ssl"`
MaxConnections int `json:"max_connections"`
MaxIdleConnections int `json:"max_idle_connections"`
ConnMaxLifetimeSeconds int `json:"conn_max_lifetime_seconds"`
QueryTimeoutSeconds int `json:"query_timeout_seconds"`
AesKeyLocation string `json:"aes_key_location"`
HashiCorpVault *HashiCorpVault `json:"hashicorp_vault"`
}
type HashiCorpVault struct {
Address string `json:"address"`
RoleID string `json:"role_id"`
SecretID string `json:"secret_id"`
LoginPath string `json:"login_path"`
SecretPath string `json:"secret_path"`
TimeoutSec int `json:"timeout_sec"`
Insecure bool `json:"insecure"`
}
type Postgres struct {
cfg Config
db *sqlx.DB
aesKey []byte
}
func checkErrWithContext(prefix string, err error, ctxErr error) error {
e := prefix + err.Error()
if ctxErr != nil {
e = fmt.Sprintf("%s: %s: %s", prefix, ctxErr.Error(), err.Error())
}
return errors.New(e)
}
func (p *Postgres) beginTransaction(ctx context.Context) (*sqlx.Tx, context.Context, context.CancelFunc, error) {
dbCtx, cancelFunc := context.WithTimeout(ctx, time.Duration(p.cfg.QueryTimeoutSeconds)*time.Second)
tx, err := p.db.BeginTxx(dbCtx, nil)
if err != nil {
e := checkErrWithContext("could not begin Traffic Vault PostgreSQL transaction", err, ctx.Err())
cancelFunc()
return nil, nil, nil, e
}
return tx, dbCtx, cancelFunc, nil
}
func (p *Postgres) commitTransaction(tx *sqlx.Tx, ctx context.Context, cancelFunc context.CancelFunc) {
if err := tx.Commit(); err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: committing transaction", err, ctx.Err())
log.Errorln(e)
}
cancelFunc()
}
// GetDeliveryServiceSSLKeys retrieves the SSL keys of the given version for
// the delivery service identified by the given xmlID. If version is empty,
// the implementation should return the latest version.
func (p *Postgres) GetDeliveryServiceSSLKeys(xmlID string, version string, tx *sql.Tx, ctx context.Context) (tc.DeliveryServiceSSLKeysV15, bool, error) {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return tc.DeliveryServiceSSLKeysV15{}, false, err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
var encryptedSslKeys []byte
query := "SELECT data FROM sslkey WHERE deliveryservice=$1 AND version=$2"
if version == "" {
version = "latest"
}
err = tvTx.QueryRow(query, xmlID, version).Scan(&encryptedSslKeys)
if err != nil {
if err == sql.ErrNoRows {
return tc.DeliveryServiceSSLKeysV15{}, false, nil
}
e := checkErrWithContext("Traffic Vault PostgreSQL: executing SELECT SSL Keys query", err, ctx.Err())
return tc.DeliveryServiceSSLKeysV15{}, false, e
}
jsonKeys, err := util.AESDecrypt(encryptedSslKeys, p.aesKey)
if err != nil {
return tc.DeliveryServiceSSLKeysV15{}, false, err
}
sslKey := tc.DeliveryServiceSSLKeysV15{}
err = json.Unmarshal([]byte(jsonKeys), &sslKey)
if err != nil {
return tc.DeliveryServiceSSLKeysV15{}, false, errors.New("unmarshalling ssl keys: " + err.Error())
}
return sslKey, true, nil
}
// PutDeliveryServiceSSLKeys stores the given SSL keys for a delivery service.
func (p *Postgres) PutDeliveryServiceSSLKeys(key tc.DeliveryServiceSSLKeys, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
keyJSON, err := json.Marshal(&key)
if err != nil {
return errors.New("marshalling keys: " + err.Error())
}
// delete the old ssl keys first
oldVersions := []string{strconv.FormatInt(int64(key.Version), 10), latestVersion}
_, err = tvTx.Exec("DELETE FROM sslkey WHERE deliveryservice=$1 and version=ANY($2)", key.DeliveryService, pq.Array(oldVersions))
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing DELETE SSL Key query for INSERT", err, ctx.Err())
return e
}
encryptedKey, err := util.AESEncrypt(keyJSON, p.aesKey)
if err != nil {
return errors.New("encrypting keys: " + err.Error())
}
// insert the new ssl keys now
res, err := tvTx.Exec("INSERT INTO sslkey (deliveryservice, data, cdn, version) VALUES ($1, $2, $3, $4), ($5, $6, $7, $8)", key.DeliveryService, encryptedKey, key.CDN, strconv.FormatInt(int64(key.Version), 10), key.DeliveryService, encryptedKey, key.CDN, latestVersion)
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing INSERT SSL Key query", err, ctx.Err())
return e
}
if rowsAffected, err := res.RowsAffected(); err != nil {
return err
} else if rowsAffected == 0 {
return errors.New("SSL Key: no keys were inserted")
}
return nil
}
// DeleteDeliveryServiceSSLKeys removes the SSL keys of the given version (or latest
// if version is empty) for the delivery service identified by the given xmlID.
func (p *Postgres) DeleteDeliveryServiceSSLKeys(xmlID string, version string, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
if version == "" {
version = latestVersion
}
query := "DELETE FROM sslkey WHERE deliveryservice=$1 AND version=$2"
_, err = tvTx.Exec(query, xmlID, version)
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing DELETE SSL Key query", err, ctx.Err())
return e
}
return nil
}
// DeleteOldDeliveryServiceSSLKeys takes a set of existingXMLIDs as input and will remove
// all SSL keys for delivery services in the CDN identified by the given cdnName that
// do not contain an xmlID in the given set of existingXMLIDs. This method is called
// during a snapshot operation in order to delete SSL keys for delivery services that
// no longer exist.
func (p *Postgres) DeleteOldDeliveryServiceSSLKeys(existingXMLIDs map[string]struct{}, cdnName string, tx *sql.Tx, ctx context.Context) error {
var keys []string
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
if len(existingXMLIDs) == 0 {
keys = append(keys, "")
}
for k, _ := range existingXMLIDs {
keys = append(keys, k)
}
_, err = tvTx.Exec("DELETE FROM sslkey WHERE cdn=$1 AND deliveryservice <> ALL ($2)", cdnName, pq.Array(keys))
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing DELETE OLD SSL Key query", err, ctx.Err())
return e
}
return nil
}
// GetCDNSSLKeys retrieves all the SSL keys for delivery services in the CDN identified
// by the given cdnName.
func (p *Postgres) GetCDNSSLKeys(cdnName string, tx *sql.Tx, ctx context.Context) ([]tc.CDNSSLKey, error) {
var keys []tc.CDNSSLKey
var key tc.CDNSSLKey
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return keys, err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
rows, err := tvTx.Query("SELECT data from sslkey WHERE cdn=$1 AND version=$2", cdnName, latestVersion)
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing GET SSL Keys for CDN query", err, ctx.Err())
return keys, e
}
defer rows.Close()
for rows.Next() {
encryptedSslKeys := []byte{}
if err := rows.Scan(&encryptedSslKeys); err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: scanning CDN SSL keys", err, ctx.Err())
return keys, e
}
jsonKey, err := util.AESDecrypt(encryptedSslKeys, p.aesKey)
if err != nil {
log.Errorf("couldn't decrypt key: %v", err)
continue
}
err = json.Unmarshal([]byte(jsonKey), &key)
if err != nil {
log.Errorf("couldn't unmarshal json key: %v", err)
continue
}
keys = append(keys, key)
}
return keys, nil
}
func (p *Postgres) GetDNSSECKeys(cdnName string, tx *sql.Tx, ctx context.Context) (tc.DNSSECKeysTrafficVault, bool, error) {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return tc.DNSSECKeysTrafficVault{}, false, err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
var encryptedDnssecKey []byte
if err := tvTx.QueryRow("SELECT data FROM dnssec WHERE cdn = $1", cdnName).Scan(&encryptedDnssecKey); err != nil {
if err == sql.ErrNoRows {
return tc.DNSSECKeysTrafficVault{}, false, nil
}
e := checkErrWithContext("Traffic Vault PostgreSQL: executing SELECT DNSSEC keys query", err, ctx.Err())
return tc.DNSSECKeysTrafficVault{}, false, e
}
dnssecJSON, err := util.AESDecrypt(encryptedDnssecKey, p.aesKey)
if err != nil {
return tc.DNSSECKeysTrafficVault{}, false, err
}
dnssecKeys := tc.DNSSECKeysTrafficVault{}
if err := json.Unmarshal([]byte(dnssecJSON), &dnssecKeys); err != nil {
return tc.DNSSECKeysTrafficVault{}, false, errors.New("unmarshalling DNSSEC keys: " + err.Error())
}
return dnssecKeys, true, nil
}
func (p *Postgres) PutDNSSECKeys(cdnName string, keys tc.DNSSECKeysTrafficVault, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
dnssecJSON, err := json.Marshal(&keys)
if err != nil {
return errors.New("marshalling DNSSEC keys: " + err.Error())
}
_, err = tvTx.Exec("DELETE FROM dnssec WHERE cdn = $1", cdnName)
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing DELETE DNSSEC keys query prior to INSERT", err, ctx.Err())
return e
}
encryptedKey, err := util.AESEncrypt(dnssecJSON, p.aesKey)
if err != nil {
return errors.New("encrypting keys: " + err.Error())
}
res, err := tvTx.Exec("INSERT INTO dnssec (cdn, data) VALUES ($1, $2)", cdnName, encryptedKey)
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing INSERT DNSSEC keys query", err, ctx.Err())
return e
}
if rowsAffected, err := res.RowsAffected(); err != nil {
return err
} else if rowsAffected == 0 {
return errors.New("Traffic Vault PostgreSQL: executing INSERT DNSSEC keys query: no rows were inserted")
}
return nil
}
func (p *Postgres) DeleteDNSSECKeys(cdnName string, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
_, err = tvTx.Exec("DELETE FROM dnssec WHERE cdn = $1", cdnName)
if err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing DELETE DNSSEC keys query", err, ctx.Err())
return e
}
return nil
}
func (p *Postgres) GetURLSigKeys(xmlID string, tx *sql.Tx, ctx context.Context) (tc.URLSigKeys, bool, error) {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return tc.URLSigKeys{}, false, err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
return getURLSigKeys(xmlID, tvTx, ctx, p.aesKey)
}
func (p *Postgres) PutURLSigKeys(xmlID string, keys tc.URLSigKeys, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
return putURLSigKeys(xmlID, tvTx, keys, ctx, p.aesKey)
}
func (p *Postgres) DeleteURLSigKeys(xmlID string, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
return deleteURLSigKeys(xmlID, tvTx, ctx)
}
func (p *Postgres) GetURISigningKeys(xmlID string, tx *sql.Tx, ctx context.Context) ([]byte, bool, error) {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return []byte{}, false, err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
return getURISigningKeys(xmlID, tvTx, ctx, p.aesKey)
}
func (p *Postgres) PutURISigningKeys(xmlID string, keysJson []byte, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
return putURISigningKeys(xmlID, tvTx, keysJson, ctx, p.aesKey)
}
func (p *Postgres) DeleteURISigningKeys(xmlID string, tx *sql.Tx, ctx context.Context) error {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
return deleteURISigningKeys(xmlID, tvTx, ctx)
}
func (p *Postgres) Ping(tx *sql.Tx, ctx context.Context) (tc.TrafficVaultPing, error) {
tvTx, dbCtx, cancelFunc, err := p.beginTransaction(ctx)
if err != nil {
return tc.TrafficVaultPing{}, err
}
defer p.commitTransaction(tvTx, dbCtx, cancelFunc)
n := 0
if err := tvTx.QueryRow("SELECT 1").Scan(&n); err != nil {
e := checkErrWithContext("Traffic Vault PostgreSQL: executing ping query", err, dbCtx.Err())
return tc.TrafficVaultPing{}, e
}
if n != 1 {
return tc.TrafficVaultPing{}, fmt.Errorf("Traffic Vault PostgreSQL: executing ping query: expected scanned value 1 but got %d instead", n)
}
return tc.TrafficVaultPing{Status: "OK", Server: p.cfg.Hostname + ":" + strconv.Itoa(p.cfg.Port)}, nil
}
func (p *Postgres) GetBucketKey(bucket string, key string, tx *sql.Tx) ([]byte, bool, error) {
return nil, false, notImplementedErr
}
func init() {
trafficvault.AddBackend(postgresBackendName, postgresLoad)
}
func postgresLoad(b json.RawMessage) (trafficvault.TrafficVault, error) {
pgCfg := Config{}
if err := json.Unmarshal(b, &pgCfg); err != nil {
return nil, errors.New("unmarshalling Postgres config: " + err.Error())
}
if err := validateConfig(pgCfg); err != nil {
return nil, errors.New("validating Postgres config: " + err.Error())
}
if pgCfg.MaxIdleConnections == 0 {
pgCfg.MaxIdleConnections = defaultMaxIdleConnections
}
if pgCfg.ConnMaxLifetimeSeconds == 0 {
pgCfg.ConnMaxLifetimeSeconds = defaultConnMaxLifetimeSeconds
}
if pgCfg.QueryTimeoutSeconds == 0 {
pgCfg.QueryTimeoutSeconds = defaultDBQueryTimeoutSecs
}
if pgCfg.HashiCorpVault != nil {
if pgCfg.HashiCorpVault.LoginPath == "" {
pgCfg.HashiCorpVault.LoginPath = defaultHashiCorpVaultLoginPath
}
if pgCfg.HashiCorpVault.TimeoutSec == 0 {
pgCfg.HashiCorpVault.TimeoutSec = defaultHashiCorpVaultTimeoutSec
}
}
sslStr := "require"
if !pgCfg.SSL {
sslStr = "disable"
}
db, err := sqlx.Open("postgres", fmt.Sprintf("postgres://%s:%s@%s:%d/%s?sslmode=%s&fallback_application_name=trafficvault", pgCfg.User, pgCfg.Password, pgCfg.Hostname, pgCfg.Port, pgCfg.DBName, sslStr))
if err != nil {
return nil, errors.New("opening database: " + err.Error())
}
db.SetMaxOpenConns(pgCfg.MaxConnections)
db.SetMaxIdleConns(pgCfg.MaxIdleConnections)
db.SetConnMaxLifetime(time.Duration(pgCfg.ConnMaxLifetimeSeconds) * time.Second)
ctx, cancel := context.WithTimeout(context.Background(), time.Duration(pgCfg.QueryTimeoutSeconds)*time.Second)
defer cancel()
if err := db.PingContext(ctx); err != nil {
// NOTE: not fatal since Traffic Vault not being available at startup shouldn't be fatal
log.Errorln("pinging the Traffic Vault database: " + err.Error())
} else {
log.Infoln("successfully pinged the Traffic Vault database")
}
aesKey, err := readKey(pgCfg)
if err != nil {
return nil, err
}
return &Postgres{cfg: pgCfg, db: db, aesKey: aesKey}, nil
}
func validateConfig(cfg Config) error {
errs := tovalidate.ToErrors(validation.Errors{
"user": validation.Validate(cfg.User, validation.Required),
"password": validation.Validate(cfg.Password, validation.Required),
"hostname": validation.Validate(cfg.Hostname, validation.Required),
"dbname": validation.Validate(cfg.DBName, validation.Required),
"port": validation.Validate(cfg.Port, validation.By(tovalidate.IsValidPortNumber)),
"max_connections": validation.Validate(cfg.MaxConnections, validation.Min(0)),
"query_timeout_seconds": validation.Validate(cfg.QueryTimeoutSeconds, validation.Min(0)),
})
aesKeyLocSet := cfg.AesKeyLocation != ""
hashiCorpVaultSet := cfg.HashiCorpVault != nil && *cfg.HashiCorpVault != HashiCorpVault{}
if aesKeyLocSet && hashiCorpVaultSet {
errs = append(errs, errors.New("aes_key_location and hashicorp_vault cannot both be set"))
} else if hashiCorpVaultSet {
hashiErrs := tovalidate.ToErrors(validation.Errors{
"address": validation.Validate(cfg.HashiCorpVault.Address, validation.Required, is.URL),
"role_id": validation.Validate(cfg.HashiCorpVault.RoleID, validation.Required),
"secret_id": validation.Validate(cfg.HashiCorpVault.SecretID, validation.Required),
"secret_path": validation.Validate(cfg.HashiCorpVault.SecretPath, validation.Required),
})
errs = append(errs, hashiErrs...)
} else if !aesKeyLocSet {
errs = append(errs, errors.New("one of either aes_key_location or hashicorp_vault is required"))
}
if len(errs) == 0 {
return nil
}
return util.JoinErrs(errs)
}