@@ -317,27 +317,21 @@ func (rm *resourceManager) addPutFieldsToSpec(
317
317
// This method is not supported in every region, ignore any errors if
318
318
// we attempt to describe this property in a region in which it's not
319
319
// supported.
320
- if awsErr , ok := ackerr .AWSError (err ); ! ok || (awsErr .Code () != "MethodNotAllowed" && awsErr .Code () != "UnsupportedArgument" ) {
320
+ if awsErr , ok := ackerr .AWSError (err ); ok && (awsErr .Code () == "MethodNotAllowed" || awsErr .Code () == "UnsupportedArgument" ) {
321
+ getAccelerateResponse = & svcsdk.GetBucketAccelerateConfigurationOutput {}
322
+ } else {
321
323
return err
322
324
}
323
325
}
324
- if getAccelerateResponse .Status != nil && * getAccelerateResponse .Status != "" {
325
- ko .Spec .Accelerate = rm .setResourceAccelerate (r , getAccelerateResponse )
326
- } else if (getAccelerateResponse .Status == nil || * getAccelerateResponse .Status == "" ) && ko .Spec .Accelerate != nil {
327
- ko .Spec .Accelerate = & svcapitypes.AccelerateConfiguration {}
328
- }
326
+ ko .Spec .Accelerate = rm .setResourceAccelerate (r , getAccelerateResponse )
329
327
330
328
listAnalyticsResponse , err := rm .sdkapi .ListBucketAnalyticsConfigurationsWithContext (ctx , rm .newListBucketAnalyticsPayload (r ))
331
329
if err != nil {
332
330
return err
333
331
}
334
- if listAnalyticsResponse != nil && len (listAnalyticsResponse .AnalyticsConfigurationList ) > 0 {
335
- ko .Spec .Analytics = make ([]* svcapitypes.AnalyticsConfiguration , len (listAnalyticsResponse .AnalyticsConfigurationList ))
336
- for i , analyticsConfiguration := range listAnalyticsResponse .AnalyticsConfigurationList {
337
- ko .Spec .Analytics [i ] = rm .setResourceAnalyticsConfiguration (r , analyticsConfiguration )
338
- }
339
- } else if (listAnalyticsResponse == nil || len (listAnalyticsResponse .AnalyticsConfigurationList ) == 0 ) && ko .Spec .Analytics != nil {
340
- ko .Spec .Analytics = []* svcapitypes.AnalyticsConfiguration {}
332
+ ko .Spec .Analytics = make ([]* svcapitypes.AnalyticsConfiguration , len (listAnalyticsResponse .AnalyticsConfigurationList ))
333
+ for i , analyticsConfiguration := range listAnalyticsResponse .AnalyticsConfigurationList {
334
+ ko .Spec .Analytics [i ] = rm .setResourceAnalyticsConfiguration (r , analyticsConfiguration )
341
335
}
342
336
343
337
getACLResponse , err := rm .sdkapi .GetBucketAclWithContext (ctx , rm .newGetBucketACLPayload (r ))
@@ -348,193 +342,160 @@ func (rm *resourceManager) addPutFieldsToSpec(
348
342
349
343
getCORSResponse , err := rm .sdkapi .GetBucketCorsWithContext (ctx , rm .newGetBucketCORSPayload (r ))
350
344
if err != nil {
351
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "NoSuchCORSConfiguration" {
345
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "NoSuchCORSConfiguration" {
346
+ getCORSResponse = & svcsdk.GetBucketCorsOutput {}
347
+ } else {
352
348
return err
353
349
}
354
350
}
355
- if getCORSResponse .CORSRules != nil {
356
- ko .Spec .CORS = rm .setResourceCORS (r , getCORSResponse )
357
- } else if getCORSResponse .CORSRules == nil && ko .Spec .CORS != nil {
358
- ko .Spec .CORS = & svcapitypes.CORSConfiguration {}
359
- }
351
+ ko .Spec .CORS = rm .setResourceCORS (r , getCORSResponse )
360
352
361
353
getEncryptionResponse , err := rm .sdkapi .GetBucketEncryptionWithContext (ctx , rm .newGetBucketEncryptionPayload (r ))
362
354
if err != nil {
363
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "ServerSideEncryptionConfigurationNotFoundError" {
355
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "ServerSideEncryptionConfigurationNotFoundError" {
356
+ getEncryptionResponse = & svcsdk.GetBucketEncryptionOutput {
357
+ ServerSideEncryptionConfiguration : & svcsdk.ServerSideEncryptionConfiguration {},
358
+ }
359
+ } else {
364
360
return err
365
361
}
366
- }
367
- if getEncryptionResponse .ServerSideEncryptionConfiguration .Rules != nil {
368
- ko .Spec .Encryption = rm .setResourceEncryption (r , getEncryptionResponse )
369
- } else if getEncryptionResponse .ServerSideEncryptionConfiguration .Rules == nil && ko .Spec .Encryption != nil {
370
- ko .Spec .Encryption = & svcapitypes.ServerSideEncryptionConfiguration {}
371
362
}
363
+ ko .Spec .Encryption = rm .setResourceEncryption (r , getEncryptionResponse )
372
364
373
365
listIntelligentTieringResponse , err := rm .sdkapi .ListBucketIntelligentTieringConfigurationsWithContext (ctx , rm .newListBucketIntelligentTieringPayload (r ))
374
366
if err != nil {
375
367
return err
376
- }
377
- if len (listIntelligentTieringResponse .IntelligentTieringConfigurationList ) > 0 {
378
- ko .Spec .IntelligentTiering = make ([]* svcapitypes.IntelligentTieringConfiguration , len (listIntelligentTieringResponse .IntelligentTieringConfigurationList ))
379
- for i , intelligentTieringConfiguration := range listIntelligentTieringResponse .IntelligentTieringConfigurationList {
380
- ko .Spec .IntelligentTiering [i ] = rm .setResourceIntelligentTieringConfiguration (r , intelligentTieringConfiguration )
381
- }
382
- } else if len (listIntelligentTieringResponse .IntelligentTieringConfigurationList ) == 0 && len (ko .Spec .IntelligentTiering ) > 0 {
383
- ko .Spec .IntelligentTiering = []* svcapitypes.IntelligentTieringConfiguration {}
368
+ }
369
+ ko .Spec .IntelligentTiering = make ([]* svcapitypes.IntelligentTieringConfiguration , len (listIntelligentTieringResponse .IntelligentTieringConfigurationList ))
370
+ for i , intelligentTieringConfiguration := range listIntelligentTieringResponse .IntelligentTieringConfigurationList {
371
+ ko .Spec .IntelligentTiering [i ] = rm .setResourceIntelligentTieringConfiguration (r , intelligentTieringConfiguration )
384
372
}
385
373
386
374
listInventoryResponse , err := rm .sdkapi .ListBucketInventoryConfigurationsWithContext (ctx , rm .newListBucketInventoryPayload (r ))
387
375
if err != nil {
388
376
return err
389
- } else {
390
- ko .Spec .Inventory = make ([]* svcapitypes.InventoryConfiguration , len (listInventoryResponse .InventoryConfigurationList ))
391
- for i , inventoryConfiguration := range listInventoryResponse .InventoryConfigurationList {
392
- ko .Spec .Inventory [i ] = rm .setResourceInventoryConfiguration (r , inventoryConfiguration )
393
- }
377
+ }
378
+ ko .Spec .Inventory = make ([]* svcapitypes.InventoryConfiguration , len (listInventoryResponse .InventoryConfigurationList ))
379
+ for i , inventoryConfiguration := range listInventoryResponse .InventoryConfigurationList {
380
+ ko .Spec .Inventory [i ] = rm .setResourceInventoryConfiguration (r , inventoryConfiguration )
394
381
}
395
382
396
383
getLifecycleResponse , err := rm .sdkapi .GetBucketLifecycleConfigurationWithContext (ctx , rm .newGetBucketLifecyclePayload (r ))
397
384
if err != nil {
398
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "NoSuchLifecycleConfiguration" {
385
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "NoSuchLifecycleConfiguration" {
386
+ getLifecycleResponse = & svcsdk.GetBucketLifecycleConfigurationOutput {}
387
+ } else {
399
388
return err
400
389
}
401
- }
402
- if getLifecycleResponse .Rules != nil {
403
- ko .Spec .Lifecycle = rm .setResourceLifecycle (r , getLifecycleResponse )
404
- } else if getLifecycleResponse .Rules == nil && ko .Spec .Lifecycle != nil {
405
- ko .Spec .Lifecycle = & svcapitypes.BucketLifecycleConfiguration {}
406
390
}
391
+ ko .Spec .Lifecycle = rm .setResourceLifecycle (r , getLifecycleResponse )
407
392
408
393
getLoggingResponse , err := rm .sdkapi .GetBucketLoggingWithContext (ctx , rm .newGetBucketLoggingPayload (r ))
409
394
if err != nil {
410
395
return err
411
396
}
412
- if getLoggingResponse .LoggingEnabled != nil {
413
- ko .Spec .Logging = rm .setResourceLogging (r , getLoggingResponse )
414
- } else if getLoggingResponse .LoggingEnabled == nil && ko .Spec .Logging != nil {
415
- ko .Spec .Logging = & svcapitypes.BucketLoggingStatus {}
416
- }
397
+ ko .Spec .Logging = rm .setResourceLogging (r , getLoggingResponse )
417
398
418
399
listMetricsResponse , err := rm .sdkapi .ListBucketMetricsConfigurationsWithContext (ctx , rm .newListBucketMetricsPayload (r ))
419
400
if err != nil {
420
401
return err
421
- }
422
- if len (listMetricsResponse .MetricsConfigurationList ) > 0 {
423
- ko .Spec .Metrics = make ([]* svcapitypes.MetricsConfiguration , len (listMetricsResponse .MetricsConfigurationList ))
424
- for i , metricsConfiguration := range listMetricsResponse .MetricsConfigurationList {
425
- ko .Spec .Metrics [i ] = rm .setResourceMetricsConfiguration (r , metricsConfiguration )
426
- }
427
- } else if len (listMetricsResponse .MetricsConfigurationList ) == 0 && len (ko .Spec .Metrics ) > 0 {
428
- ko .Spec .Metrics = []* svcapitypes.MetricsConfiguration {}
402
+ }
403
+ ko .Spec .Metrics = make ([]* svcapitypes.MetricsConfiguration , len (listMetricsResponse .MetricsConfigurationList ))
404
+ for i , metricsConfiguration := range listMetricsResponse .MetricsConfigurationList {
405
+ ko .Spec .Metrics [i ] = rm .setResourceMetricsConfiguration (r , metricsConfiguration )
429
406
}
430
407
431
408
getNotificationResponse , err := rm .sdkapi .GetBucketNotificationConfigurationWithContext (ctx , rm .newGetBucketNotificationPayload (r ))
432
409
if err != nil {
433
410
return err
434
411
}
435
- if getNotificationResponse .LambdaFunctionConfigurations != nil ||
436
- getNotificationResponse .QueueConfigurations != nil ||
437
- getNotificationResponse .TopicConfigurations != nil {
438
-
439
- ko .Spec .Notification = rm .setResourceNotification (r , getNotificationResponse )
440
- } else if (getNotificationResponse .LambdaFunctionConfigurations == nil ||
441
- getNotificationResponse .QueueConfigurations == nil ||
442
- getNotificationResponse .TopicConfigurations == nil ) && ko .Spec .Notification != nil {
443
- ko .Spec .Notification = & svcapitypes.NotificationConfiguration {}
444
- }
412
+ ko .Spec .Notification = rm .setResourceNotification (r , getNotificationResponse )
445
413
446
414
getOwnershipControlsResponse , err := rm .sdkapi .GetBucketOwnershipControlsWithContext (ctx , rm .newGetBucketOwnershipControlsPayload (r ))
447
415
if err != nil {
448
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "OwnershipControlsNotFoundError" {
416
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "OwnershipControlsNotFoundError" {
417
+ getOwnershipControlsResponse = & svcsdk.GetBucketOwnershipControlsOutput {
418
+ OwnershipControls : & svcsdk.OwnershipControls {},
419
+ }
420
+ } else {
449
421
return err
450
422
}
451
423
}
452
424
if getOwnershipControlsResponse .OwnershipControls != nil {
453
425
ko .Spec .OwnershipControls = rm .setResourceOwnershipControls (r , getOwnershipControlsResponse )
454
- } else if getOwnershipControlsResponse . OwnershipControls == nil && ko . Spec . OwnershipControls != nil {
455
- ko .Spec .OwnershipControls = & svcapitypes. OwnershipControls {}
426
+ } else {
427
+ ko .Spec .OwnershipControls = nil
456
428
}
457
429
458
430
getPolicyResponse , err := rm .sdkapi .GetBucketPolicyWithContext (ctx , rm .newGetBucketPolicyPayload (r ))
459
431
if err != nil {
460
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "NoSuchBucketPolicy" {
432
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "NoSuchBucketPolicy" {
433
+ getPolicyResponse = & svcsdk.GetBucketPolicyOutput {}
434
+ } else {
461
435
return err
462
436
}
463
437
}
464
- if getPolicyResponse .Policy != nil {
465
- ko .Spec .Policy = getPolicyResponse .Policy
466
- } else if getPolicyResponse .Policy == nil && ko .Spec .Policy != nil {
467
- ko .Spec .Policy = (& svcsdk.GetBucketPolicyOutput {}).Policy
468
- }
438
+ ko .Spec .Policy = getPolicyResponse .Policy
469
439
470
440
getPublicAccessBlockResponse , err := rm .sdkapi .GetPublicAccessBlockWithContext (ctx , rm .newGetPublicAccessBlockPayload (r ))
471
441
if err != nil {
472
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "NoSuchPublicAccessBlockConfiguration" {
442
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "NoSuchPublicAccessBlockConfiguration" {
443
+ getPublicAccessBlockResponse = & svcsdk.GetPublicAccessBlockOutput {}
444
+ } else {
473
445
return err
474
446
}
475
447
}
476
448
if getPublicAccessBlockResponse .PublicAccessBlockConfiguration != nil {
477
449
ko .Spec .PublicAccessBlock = rm .setResourcePublicAccessBlock (r , getPublicAccessBlockResponse )
478
- } else if getPublicAccessBlockResponse . PublicAccessBlockConfiguration == nil && ko . Spec . PublicAccessBlock != nil {
479
- ko .Spec .PublicAccessBlock = & svcapitypes. PublicAccessBlockConfiguration {}
450
+ } else {
451
+ ko .Spec .PublicAccessBlock = nil
480
452
}
481
453
482
454
getReplicationResponse , err := rm .sdkapi .GetBucketReplicationWithContext (ctx , rm .newGetBucketReplicationPayload (r ))
483
455
if err != nil {
484
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "ReplicationConfigurationNotFoundError" {
456
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "ReplicationConfigurationNotFoundError" {
457
+ getReplicationResponse = & svcsdk.GetBucketReplicationOutput {}
458
+ } else {
485
459
return err
486
460
}
487
461
}
488
462
if getReplicationResponse .ReplicationConfiguration != nil {
489
463
ko .Spec .Replication = rm .setResourceReplication (r , getReplicationResponse )
490
- } else if getReplicationResponse . ReplicationConfiguration == nil && ko . Spec . Replication != nil {
491
- ko .Spec .Replication = & svcapitypes. ReplicationConfiguration {}
464
+ } else {
465
+ ko .Spec .Replication = nil
492
466
}
493
467
494
468
getRequestPaymentResponse , err := rm .sdkapi .GetBucketRequestPaymentWithContext (ctx , rm .newGetBucketRequestPaymentPayload (r ))
495
469
if err != nil {
496
470
return nil
497
- }
498
- if getRequestPaymentResponse .Payer != nil {
499
- ko .Spec .RequestPayment = rm .setResourceRequestPayment (r , getRequestPaymentResponse )
500
- } else if getRequestPaymentResponse .Payer == nil && ko .Spec .RequestPayment != nil {
501
- ko .Spec .RequestPayment = & svcapitypes.RequestPaymentConfiguration {}
502
471
}
472
+ ko .Spec .RequestPayment = rm .setResourceRequestPayment (r , getRequestPaymentResponse )
503
473
504
474
getTaggingResponse , err := rm .sdkapi .GetBucketTaggingWithContext (ctx , rm .newGetBucketTaggingPayload (r ))
505
475
if err != nil {
506
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "NoSuchTagSet" {
476
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "NoSuchTagSet" {
477
+ getTaggingResponse = & svcsdk.GetBucketTaggingOutput {}
478
+ } else {
507
479
return err
508
480
}
509
- }
510
- if getTaggingResponse .TagSet != nil {
511
- ko .Spec .Tagging = rm .setResourceTagging (r , getTaggingResponse )
512
- } else if getTaggingResponse .TagSet == nil && ko .Spec .Tagging != nil {
513
- ko .Spec .Tagging = & svcapitypes.Tagging {}
514
481
}
482
+ ko .Spec .Tagging = rm .setResourceTagging (r , getTaggingResponse )
515
483
516
484
getVersioningResponse , err := rm .sdkapi .GetBucketVersioningWithContext (ctx , rm .newGetBucketVersioningPayload (r ))
517
485
if err != nil {
518
486
return err
519
- }
520
- if getVersioningResponse .Status != nil {
521
- ko .Spec .Versioning = rm .setResourceVersioning (r , getVersioningResponse )
522
- } else if getVersioningResponse .Status == nil && ko .Spec .Versioning != nil {
523
- ko .Spec .Versioning = & svcapitypes.VersioningConfiguration {}
524
487
}
488
+ ko .Spec .Versioning = rm .setResourceVersioning (r , getVersioningResponse )
525
489
526
490
getWebsiteResponse , err := rm .sdkapi .GetBucketWebsiteWithContext (ctx , rm .newGetBucketWebsitePayload (r ))
527
491
if err != nil {
528
- if awsErr , ok := ackerr .AWSError (err ); ! ok || awsErr .Code () != "NoSuchWebsiteConfiguration" {
492
+ if awsErr , ok := ackerr .AWSError (err ); ok && awsErr .Code () == "NoSuchWebsiteConfiguration" {
493
+ getWebsiteResponse = & svcsdk.GetBucketWebsiteOutput {}
494
+ } else {
529
495
return err
530
496
}
531
- }
532
- if getWebsiteResponse != nil {
533
- ko .Spec .Website = rm .setResourceWebsite (r , getWebsiteResponse )
534
- }else if getWebsiteResponse == nil && ko .Spec .Website != nil {
535
- ko .Spec .Website = & svcapitypes.WebsiteConfiguration {}
536
497
}
537
-
498
+ ko . Spec . Website = rm . setResourceWebsite ( r , getWebsiteResponse )
538
499
return nil
539
500
}
540
501
@@ -727,28 +688,16 @@ func (rm *resourceManager) setResourceACL(
727
688
resp * svcsdk.GetBucketAclOutput ,
728
689
) {
729
690
grants := GetHeadersFromGrants (resp )
730
- if grants .FullControl != "" {
731
- ko .Spec .GrantFullControl = & grants .FullControl
732
- }
733
- if grants .Read != "" {
734
- ko .Spec .GrantRead = & grants .Read
735
- }
736
- if grants .ReadACP != "" {
737
- ko .Spec .GrantReadACP = & grants .ReadACP
738
- }
739
- if grants .Write != "" {
740
- ko .Spec .GrantWrite = & grants .Write
741
- }
742
- if grants .WriteACP != "" {
743
- ko .Spec .GrantWriteACP = & grants .WriteACP
744
- }
691
+ ko .Spec .GrantFullControl = & grants .FullControl
692
+ ko .Spec .GrantRead = & grants .Read
693
+ ko .Spec .GrantReadACP = & grants .ReadACP
694
+ ko .Spec .GrantWrite = & grants .Write
695
+ ko .Spec .GrantWriteACP = & grants .WriteACP
745
696
746
697
// Join possible ACLs into a single string, delimited by bar
747
698
cannedACLs := GetPossibleCannedACLsFromGrants (resp )
748
699
joinedACLs := strings .Join (cannedACLs , CannedACLJoinDelimiter )
749
- if joinedACLs != "" {
750
- ko .Spec .ACL = & joinedACLs
751
- }
700
+ ko .Spec .ACL = & joinedACLs
752
701
}
753
702
754
703
func (rm * resourceManager ) newGetBucketACLPayload (
0 commit comments