in plugins/internal/plugin/device_plugin.go [345:366]
func (p *DevicePlugin) GetDeviceForID(deviceID string) (*discovery.Device, error) {
// Strip the multitenancy suffix from the device ID
backslash := strings.LastIndex(deviceID, "\\")
if backslash == -1 {
return nil, fmt.Errorf("malformed device ID \"%s\"", deviceID)
}
stripped := deviceID[0:backslash]
// Lock the mutex for the device list
p.devicesMutex.Lock()
defer p.devicesMutex.Unlock()
// Search for a device with the specified ID
for _, device := range p.currentDevices {
if device.ID == stripped {
return device, nil
}
}
return nil, fmt.Errorf("could not find device with ID \"%s\"", stripped)
}