Skip to content

Commit 0dfb827

Browse files
authored
Merge pull request #390 from vmware/rnarenpujari/dp-auth
Refresh auth context while polling for data protection resources
2 parents 3681696 + db5c3cd commit 0dfb827

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

internal/resources/backupschedule/resource_backup_schedule.go

+5
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ func readResourceWait(ctx context.Context, config *authctx.TanzuContext, resourc
463463
resp, err = config.TMCConnection.BackupScheduleService.BackupScheduleResourceServiceGet(resourceFullName)
464464

465465
if err != nil || resp == nil || resp.Schedule == nil {
466+
if clienterrors.IsUnauthorizedError(err) {
467+
authctx.RefreshUserAuthContext(config, clienterrors.IsUnauthorizedError, err)
468+
continue
469+
}
470+
466471
return nil, err
467472
}
468473

internal/resources/dataprotection/resource_enable_data_protection.go

+22-16
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,23 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource
6666
config := m.(authctx.TanzuContext)
6767

6868
err := populateDataFromServer(ctx, config, scopedFullnameData, data)
69+
if err != nil {
70+
if clienterrors.IsNotFoundError(err) {
71+
if !helper.IsContextCallerSet(ctx) {
72+
*data = schema.ResourceData{}
73+
74+
return diags
75+
} else if helper.IsDeleteState(ctx) {
76+
// d.SetId("") is automatically called assuming delete returns no errors, but
77+
// it is added here for explicitness.
78+
_ = schema.RemoveFromState(data, m)
79+
80+
return diags
81+
}
82+
}
83+
84+
return diag.FromErr(err)
85+
}
6986

7087
// remove the existing cluster level resource from state if it is now
7188
// managed at the cluster group level.
@@ -83,22 +100,6 @@ func resourceEnableDataProtectionRead(ctx context.Context, data *schema.Resource
83100
}
84101
}
85102

86-
if err != nil {
87-
if clienterrors.IsNotFoundError(err) {
88-
if !helper.IsContextCallerSet(ctx) {
89-
*data = schema.ResourceData{}
90-
91-
return diags
92-
} else if helper.IsDeleteState(ctx) {
93-
// d.SetId("") is automatically called assuming delete returns no errors, but
94-
// it is added here for explicitness.
95-
_ = schema.RemoveFromState(data, m)
96-
97-
return diags
98-
}
99-
}
100-
}
101-
102103
return diags
103104
}
104105

@@ -228,6 +229,11 @@ func populateDataFromServer(ctx context.Context, config authctx.TanzuContext, sc
228229

229230
resp, err := config.TMCConnection.DataProtectionService.DataProtectionResourceServiceList(scopedFullnameData.FullnameCluster)
230231
if err != nil || resp == nil {
232+
if clienterrors.IsUnauthorizedError(err) {
233+
authctx.RefreshUserAuthContext(&config, clienterrors.IsUnauthorizedError, err)
234+
continue
235+
}
236+
231237
return errors.Wrap(err, "list data protections")
232238
}
233239

internal/resources/targetlocation/resource_target_location.go

+5
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ func readResourceWait(ctx context.Context, config *authctx.TanzuContext, resourc
266266
resp, err = config.TMCConnection.TargetLocationService.TargetLocationResourceServiceGet(resourceFullName)
267267

268268
if err != nil || resp == nil || resp.BackupLocation == nil {
269+
if clienterrors.IsUnauthorizedError(err) {
270+
authctx.RefreshUserAuthContext(config, clienterrors.IsUnauthorizedError, err)
271+
continue
272+
}
273+
269274
return nil, err
270275
}
271276

0 commit comments

Comments
 (0)