@@ -317,27 +317,21 @@ func (rm *resourceManager) addPutFieldsToSpec(
317317 // This method is not supported in every region, ignore any errors if
318318 // we attempt to describe this property in a region in which it's not
319319 // 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 {
321323 return err
322324 }
323325 }
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 )
329327
330328 listAnalyticsResponse , err := rm .sdkapi .ListBucketAnalyticsConfigurationsWithContext (ctx , rm .newListBucketAnalyticsPayload (r ))
331329 if err != nil {
332330 return err
333331 }
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 )
341335 }
342336
343337 getACLResponse , err := rm .sdkapi .GetBucketAclWithContext (ctx , rm .newGetBucketACLPayload (r ))
@@ -348,193 +342,160 @@ func (rm *resourceManager) addPutFieldsToSpec(
348342
349343 getCORSResponse , err := rm .sdkapi .GetBucketCorsWithContext (ctx , rm .newGetBucketCORSPayload (r ))
350344 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 {
352348 return err
353349 }
354350 }
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 )
360352
361353 getEncryptionResponse , err := rm .sdkapi .GetBucketEncryptionWithContext (ctx , rm .newGetBucketEncryptionPayload (r ))
362354 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 {
364360 return err
365361 }
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 {}
371362 }
363+ ko .Spec .Encryption = rm .setResourceEncryption (r , getEncryptionResponse )
372364
373365 listIntelligentTieringResponse , err := rm .sdkapi .ListBucketIntelligentTieringConfigurationsWithContext (ctx , rm .newListBucketIntelligentTieringPayload (r ))
374366 if err != nil {
375367 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 )
384372 }
385373
386374 listInventoryResponse , err := rm .sdkapi .ListBucketInventoryConfigurationsWithContext (ctx , rm .newListBucketInventoryPayload (r ))
387375 if err != nil {
388376 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 )
394381 }
395382
396383 getLifecycleResponse , err := rm .sdkapi .GetBucketLifecycleConfigurationWithContext (ctx , rm .newGetBucketLifecyclePayload (r ))
397384 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 {
399388 return err
400389 }
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 {}
406390 }
391+ ko .Spec .Lifecycle = rm .setResourceLifecycle (r , getLifecycleResponse )
407392
408393 getLoggingResponse , err := rm .sdkapi .GetBucketLoggingWithContext (ctx , rm .newGetBucketLoggingPayload (r ))
409394 if err != nil {
410395 return err
411396 }
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 )
417398
418399 listMetricsResponse , err := rm .sdkapi .ListBucketMetricsConfigurationsWithContext (ctx , rm .newListBucketMetricsPayload (r ))
419400 if err != nil {
420401 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 )
429406 }
430407
431408 getNotificationResponse , err := rm .sdkapi .GetBucketNotificationConfigurationWithContext (ctx , rm .newGetBucketNotificationPayload (r ))
432409 if err != nil {
433410 return err
434411 }
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 )
445413
446414 getOwnershipControlsResponse , err := rm .sdkapi .GetBucketOwnershipControlsWithContext (ctx , rm .newGetBucketOwnershipControlsPayload (r ))
447415 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 {
449421 return err
450422 }
451423 }
452424 if getOwnershipControlsResponse .OwnershipControls != nil {
453425 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
456428 }
457429
458430 getPolicyResponse , err := rm .sdkapi .GetBucketPolicyWithContext (ctx , rm .newGetBucketPolicyPayload (r ))
459431 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 {
461435 return err
462436 }
463437 }
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
469439
470440 getPublicAccessBlockResponse , err := rm .sdkapi .GetPublicAccessBlockWithContext (ctx , rm .newGetPublicAccessBlockPayload (r ))
471441 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 {
473445 return err
474446 }
475447 }
476448 if getPublicAccessBlockResponse .PublicAccessBlockConfiguration != nil {
477449 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
480452 }
481453
482454 getReplicationResponse , err := rm .sdkapi .GetBucketReplicationWithContext (ctx , rm .newGetBucketReplicationPayload (r ))
483455 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 {
485459 return err
486460 }
487461 }
488462 if getReplicationResponse .ReplicationConfiguration != nil {
489463 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
492466 }
493467
494468 getRequestPaymentResponse , err := rm .sdkapi .GetBucketRequestPaymentWithContext (ctx , rm .newGetBucketRequestPaymentPayload (r ))
495469 if err != nil {
496470 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 {}
502471 }
472+ ko .Spec .RequestPayment = rm .setResourceRequestPayment (r , getRequestPaymentResponse )
503473
504474 getTaggingResponse , err := rm .sdkapi .GetBucketTaggingWithContext (ctx , rm .newGetBucketTaggingPayload (r ))
505475 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 {
507479 return err
508480 }
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 {}
514481 }
482+ ko .Spec .Tagging = rm .setResourceTagging (r , getTaggingResponse )
515483
516484 getVersioningResponse , err := rm .sdkapi .GetBucketVersioningWithContext (ctx , rm .newGetBucketVersioningPayload (r ))
517485 if err != nil {
518486 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 {}
524487 }
488+ ko .Spec .Versioning = rm .setResourceVersioning (r , getVersioningResponse )
525489
526490 getWebsiteResponse , err := rm .sdkapi .GetBucketWebsiteWithContext (ctx , rm .newGetBucketWebsitePayload (r ))
527491 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 {
529495 return err
530496 }
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 {}
536497 }
537-
498+ ko . Spec . Website = rm . setResourceWebsite ( r , getWebsiteResponse )
538499 return nil
539500}
540501
@@ -727,28 +688,16 @@ func (rm *resourceManager) setResourceACL(
727688 resp * svcsdk.GetBucketAclOutput ,
728689) {
729690 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
745696
746697 // Join possible ACLs into a single string, delimited by bar
747698 cannedACLs := GetPossibleCannedACLsFromGrants (resp )
748699 joinedACLs := strings .Join (cannedACLs , CannedACLJoinDelimiter )
749- if joinedACLs != "" {
750- ko .Spec .ACL = & joinedACLs
751- }
700+ ko .Spec .ACL = & joinedACLs
752701}
753702
754703func (rm * resourceManager ) newGetBucketACLPayload (
0 commit comments