Skip to content

Commit

Permalink
Merge pull request #803 from Juniper/bug/282-GetDeviceKey-404
Browse files Browse the repository at this point in the history
Handle 404 in GetDeviceKey
  • Loading branch information
chrismarget-j authored Aug 22, 2024
2 parents b77ab3c + 7123371 commit 82401fd
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apstra/system_agents/managed_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,13 @@ func (o *ManagedDevice) Acknowledge(ctx context.Context, si *apstra.ManagedSyste
}

func (o *ManagedDevice) GetDeviceKey(ctx context.Context, client *apstra.Client, diags *diag.Diagnostics) {
o.DeviceKey = types.StringNull()

// Get SystemInfo from API
systemInfo, err := client.GetSystemInfo(ctx, apstra.SystemId(o.SystemId.ValueString()))
if err != nil {
if utils.IsApstra404(err) {
return // o.DeviceKey has been set to null -- better ideas?
} else {
diags.AddError(
"error reading managed device system info",
Expand All @@ -223,9 +226,7 @@ func (o *ManagedDevice) GetDeviceKey(ctx context.Context, client *apstra.Client,
}

// record device key and location if possible
if systemInfo == nil {
o.DeviceKey = types.StringNull()
} else {
if systemInfo != nil {
o.DeviceKey = types.StringValue(systemInfo.DeviceKey)
}
}
Expand Down

0 comments on commit 82401fd

Please sign in to comment.