Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid creating a provisioning api key when registering a device #1424

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 21 additions & 23 deletions src/models/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1382,29 +1382,25 @@ const getDeviceModel = function (
$expand: { is_for__device_type: deviceTypeOptions },
} as const;

const [{ id: userId }, apiKey, application, deviceType] =
await Promise.all([
sdkInstance.auth.getUserInfo(),
sdkInstance.models.application.generateProvisioningKey(
applicationSlugOrUuidOrId,
),
sdkInstance.models.application.get(
applicationSlugOrUuidOrId,
applicationOptions,
) as Promise<PineTypedResult<Application, typeof applicationOptions>>,
typeof deviceTypeSlug === 'string'
? (sdkInstance.models.deviceType.get(deviceTypeSlug, {
$select: 'slug',
$expand: {
is_of__cpu_architecture: {
$select: 'slug',
},
const [{ id: userId }, application, deviceType] = await Promise.all([
sdkInstance.auth.getUserInfo(),
sdkInstance.models.application.get(
applicationSlugOrUuidOrId,
applicationOptions,
) as Promise<PineTypedResult<Application, typeof applicationOptions>>,
typeof deviceTypeSlug === 'string'
? (sdkInstance.models.deviceType.get(deviceTypeSlug, {
$select: 'slug',
$expand: {
is_of__cpu_architecture: {
$select: 'slug',
},
}) as Promise<
PineTypedResult<DeviceType, typeof deviceTypeOptions>
>)
: null,
]);
},
}) as Promise<
PineTypedResult<DeviceType, typeof deviceTypeOptions>
>)
: null,
]);
if (deviceType != null) {
const isCompatibleParameter =
sdkInstance.models.os.isArchitectureCompatibleWith(
Expand All @@ -1423,7 +1419,9 @@ const getDeviceModel = function (
applicationId: application.id,
uuid,
deviceType: (deviceType ?? application.is_for__device_type[0]).slug,
provisioningApiKey: apiKey,
// This just needs to be auth that can create the device, so using user auth is just fine and avoids
// creating an api key unnecessarily
provisioningApiKey: await sdkInstance.auth.getToken(),
apiEndpoint: apiUrl,
});
},
Expand Down
Loading