diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.bind_device_to_gateway.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.bind_device_to_gateway.js new file mode 100644 index 00000000000..ef68a2f2a43 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.bind_device_to_gateway.js @@ -0,0 +1,66 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, gatewayId, deviceId) { + // [START cloudiot_v1_generated_DeviceManager_BindDeviceToGateway_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the registry. For example, + * `projects/example-project/locations/us-central1/registries/my-registry`. + */ + // const parent = 'abc123' + /** + * Required. The value of `gateway_id` can be either the device numeric ID or the + * user-defined device identifier. + */ + // const gatewayId = 'abc123' + /** + * Required. The device to associate with the specified gateway. The value of + * `device_id` can be either the device numeric ID or the user-defined device + * identifier. + */ + // const deviceId = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function bindDeviceToGateway() { + // Construct request + const request = { + parent, + gatewayId, + deviceId, + }; + + // Run request + const response = await iotClient.bindDeviceToGateway(request); + console.log(response); + } + + bindDeviceToGateway(); + // [END cloudiot_v1_generated_DeviceManager_BindDeviceToGateway_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.create_device.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.create_device.js new file mode 100644 index 00000000000..a0cff18f921 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.create_device.js @@ -0,0 +1,61 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, device) { + // [START cloudiot_v1_generated_DeviceManager_CreateDevice_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device registry where this device should be created. + * For example, + * `projects/example-project/locations/us-central1/registries/my-registry`. + */ + // const parent = 'abc123' + /** + * Required. The device registration details. The field `name` must be empty. The server + * generates `name` from the device registry `id` and the + * `parent` field. + */ + // const device = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function createDevice() { + // Construct request + const request = { + parent, + device, + }; + + // Run request + const response = await iotClient.createDevice(request); + console.log(response); + } + + createDevice(); + // [END cloudiot_v1_generated_DeviceManager_CreateDevice_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.create_device_registry.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.create_device_registry.js new file mode 100644 index 00000000000..dc549ab5b02 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.create_device_registry.js @@ -0,0 +1,60 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, deviceRegistry) { + // [START cloudiot_v1_generated_DeviceManager_CreateDeviceRegistry_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The project and cloud region where this device registry must be created. + * For example, `projects/example-project/locations/us-central1`. + */ + // const parent = 'abc123' + /** + * Required. The device registry. The field `name` must be empty. The server will + * generate that field from the device registry `id` provided and the + * `parent` field. + */ + // const deviceRegistry = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function createDeviceRegistry() { + // Construct request + const request = { + parent, + deviceRegistry, + }; + + // Run request + const response = await iotClient.createDeviceRegistry(request); + console.log(response); + } + + createDeviceRegistry(); + // [END cloudiot_v1_generated_DeviceManager_CreateDeviceRegistry_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.delete_device.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.delete_device.js new file mode 100644 index 00000000000..d3c2658cfc9 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.delete_device.js @@ -0,0 +1,54 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START cloudiot_v1_generated_DeviceManager_DeleteDevice_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0` or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const name = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function deleteDevice() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await iotClient.deleteDevice(request); + console.log(response); + } + + deleteDevice(); + // [END cloudiot_v1_generated_DeviceManager_DeleteDevice_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.delete_device_registry.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.delete_device_registry.js new file mode 100644 index 00000000000..fc3fe930c37 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.delete_device_registry.js @@ -0,0 +1,53 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START cloudiot_v1_generated_DeviceManager_DeleteDeviceRegistry_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device registry. For example, + * `projects/example-project/locations/us-central1/registries/my-registry`. + */ + // const name = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function deleteDeviceRegistry() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await iotClient.deleteDeviceRegistry(request); + console.log(response); + } + + deleteDeviceRegistry(); + // [END cloudiot_v1_generated_DeviceManager_DeleteDeviceRegistry_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.get_device.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.get_device.js new file mode 100644 index 00000000000..515f87814eb --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.get_device.js @@ -0,0 +1,60 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START cloudiot_v1_generated_DeviceManager_GetDevice_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0` or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const name = 'abc123' + /** + * The fields of the `Device` resource to be returned in the response. If the + * field mask is unset or empty, all fields are returned. Fields have to be + * provided in snake_case format, for example: `last_heartbeat_time`. + */ + // const fieldMask = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function getDevice() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await iotClient.getDevice(request); + console.log(response); + } + + getDevice(); + // [END cloudiot_v1_generated_DeviceManager_GetDevice_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.get_device_registry.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.get_device_registry.js new file mode 100644 index 00000000000..46bdf72d8dc --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.get_device_registry.js @@ -0,0 +1,53 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START cloudiot_v1_generated_DeviceManager_GetDeviceRegistry_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device registry. For example, + * `projects/example-project/locations/us-central1/registries/my-registry`. + */ + // const name = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function getDeviceRegistry() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await iotClient.getDeviceRegistry(request); + console.log(response); + } + + getDeviceRegistry(); + // [END cloudiot_v1_generated_DeviceManager_GetDeviceRegistry_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.get_iam_policy.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.get_iam_policy.js new file mode 100644 index 00000000000..7d6db9ed210 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.get_iam_policy.js @@ -0,0 +1,58 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(resource) { + // [START cloudiot_v1_generated_DeviceManager_GetIamPolicy_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * REQUIRED: The resource for which the policy is being requested. + * See the operation documentation for the appropriate value for this field. + */ + // const resource = 'abc123' + /** + * OPTIONAL: A `GetPolicyOptions` object for specifying options to + * `GetIamPolicy`. This field is only used by Cloud IAM. + */ + // const options = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function getIamPolicy() { + // Construct request + const request = { + resource, + }; + + // Run request + const response = await iotClient.getIamPolicy(request); + console.log(response); + } + + getIamPolicy(); + // [END cloudiot_v1_generated_DeviceManager_GetIamPolicy_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_config_versions.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_config_versions.js new file mode 100644 index 00000000000..672446ef1e2 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_config_versions.js @@ -0,0 +1,60 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START cloudiot_v1_generated_DeviceManager_ListDeviceConfigVersions_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0` or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const name = 'abc123' + /** + * The number of versions to list. Versions are listed in decreasing order of + * the version number. The maximum number of versions retained is 10. If this + * value is zero, it will return all the versions available. + */ + // const numVersions = 1234 + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function listDeviceConfigVersions() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await iotClient.listDeviceConfigVersions(request); + console.log(response); + } + + listDeviceConfigVersions(); + // [END cloudiot_v1_generated_DeviceManager_ListDeviceConfigVersions_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_registries.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_registries.js new file mode 100644 index 00000000000..6a04762fe55 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_registries.js @@ -0,0 +1,68 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent) { + // [START cloudiot_v1_generated_DeviceManager_ListDeviceRegistries_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The project and cloud region path. For example, + * `projects/example-project/locations/us-central1`. + */ + // const parent = 'abc123' + /** + * The maximum number of registries to return in the response. If this value + * is zero, the service will select a default size. A call may return fewer + * objects than requested. A non-empty `next_page_token` in the response + * indicates that more data is available. + */ + // const pageSize = 1234 + /** + * The value returned by the last `ListDeviceRegistriesResponse`; indicates + * that this is a continuation of a prior `ListDeviceRegistries` call and + * the system should return the next page of data. + */ + // const pageToken = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function listDeviceRegistries() { + // Construct request + const request = { + parent, + }; + + // Run request + const iterable = await iotClient.listDeviceRegistriesAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + listDeviceRegistries(); + // [END cloudiot_v1_generated_DeviceManager_ListDeviceRegistries_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_states.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_states.js new file mode 100644 index 00000000000..20c05621ea4 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_device_states.js @@ -0,0 +1,60 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name) { + // [START cloudiot_v1_generated_DeviceManager_ListDeviceStates_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0` or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const name = 'abc123' + /** + * The number of states to list. States are listed in descending order of + * update time. The maximum number of states retained is 10. If this + * value is zero, it will return all the states available. + */ + // const numStates = 1234 + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function listDeviceStates() { + // Construct request + const request = { + name, + }; + + // Run request + const response = await iotClient.listDeviceStates(request); + console.log(response); + } + + listDeviceStates(); + // [END cloudiot_v1_generated_DeviceManager_ListDeviceStates_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.list_devices.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_devices.js new file mode 100644 index 00000000000..f0ee8de5550 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.list_devices.js @@ -0,0 +1,89 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent) { + // [START cloudiot_v1_generated_DeviceManager_ListDevices_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The device registry path. Required. For example, + * `projects/my-project/locations/us-central1/registries/my-registry`. + */ + // const parent = 'abc123' + /** + * A list of device numeric IDs. If empty, this field is ignored. Maximum + * IDs: 10,000. + */ + // const deviceNumIds = 1234 + /** + * A list of device string IDs. For example, `['device0', 'device12']`. + * If empty, this field is ignored. Maximum IDs: 10,000 + */ + // const deviceIds = 'abc123' + /** + * The fields of the `Device` resource to be returned in the response. The + * fields `id` and `num_id` are always returned, along with any + * other fields specified in snake_case format, for example: + * `last_heartbeat_time`. + */ + // const fieldMask = '' + /** + * Options related to gateways. + */ + // const gatewayListOptions = '' + /** + * The maximum number of devices to return in the response. If this value + * is zero, the service will select a default size. A call may return fewer + * objects than requested. A non-empty `next_page_token` in the response + * indicates that more data is available. + */ + // const pageSize = 1234 + /** + * The value returned by the last `ListDevicesResponse`; indicates + * that this is a continuation of a prior `ListDevices` call and + * the system should return the next page of data. + */ + // const pageToken = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function listDevices() { + // Construct request + const request = { + parent, + }; + + // Run request + const iterable = await iotClient.listDevicesAsync(request); + for await (const response of iterable) { + console.log(response); + } + } + + listDevices(); + // [END cloudiot_v1_generated_DeviceManager_ListDevices_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.modify_cloud_to_device_config.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.modify_cloud_to_device_config.js new file mode 100644 index 00000000000..5c94c3f6701 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.modify_cloud_to_device_config.js @@ -0,0 +1,67 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name, binaryData) { + // [START cloudiot_v1_generated_DeviceManager_ModifyCloudToDeviceConfig_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0` or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const name = 'abc123' + /** + * The version number to update. If this value is zero, it will not check the + * version number of the server and will always update the current version; + * otherwise, this update will fail if the version number found on the server + * does not match this version number. This is used to support multiple + * simultaneous updates without losing data. + */ + // const versionToUpdate = 1234 + /** + * Required. The configuration data for the device. + */ + // const binaryData = 'Buffer.from('string')' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function modifyCloudToDeviceConfig() { + // Construct request + const request = { + name, + binaryData, + }; + + // Run request + const response = await iotClient.modifyCloudToDeviceConfig(request); + console.log(response); + } + + modifyCloudToDeviceConfig(); + // [END cloudiot_v1_generated_DeviceManager_ModifyCloudToDeviceConfig_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.send_command_to_device.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.send_command_to_device.js new file mode 100644 index 00000000000..be1e94bdedc --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.send_command_to_device.js @@ -0,0 +1,67 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(name, binaryData) { + // [START cloudiot_v1_generated_DeviceManager_SendCommandToDevice_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the device. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0` or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const name = 'abc123' + /** + * Required. The command data to send to the device. + */ + // const binaryData = 'Buffer.from('string')' + /** + * Optional subfolder for the command. If empty, the command will be delivered + * to the /devices/{device-id}/commands topic, otherwise it will be delivered + * to the /devices/{device-id}/commands/{subfolder} topic. Multi-level + * subfolders are allowed. This field must not have more than 256 characters, + * and must not contain any MQTT wildcards ("+" or "#") or null characters. + */ + // const subfolder = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function sendCommandToDevice() { + // Construct request + const request = { + name, + binaryData, + }; + + // Run request + const response = await iotClient.sendCommandToDevice(request); + console.log(response); + } + + sendCommandToDevice(); + // [END cloudiot_v1_generated_DeviceManager_SendCommandToDevice_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.set_iam_policy.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.set_iam_policy.js new file mode 100644 index 00000000000..e6a075ba82a --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.set_iam_policy.js @@ -0,0 +1,61 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(resource, policy) { + // [START cloudiot_v1_generated_DeviceManager_SetIamPolicy_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * REQUIRED: The resource for which the policy is being specified. + * See the operation documentation for the appropriate value for this field. + */ + // const resource = 'abc123' + /** + * REQUIRED: The complete policy to be applied to the `resource`. The size of + * the policy is limited to a few 10s of KB. An empty policy is a + * valid policy but certain Cloud Platform services (such as Projects) + * might reject them. + */ + // const policy = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function setIamPolicy() { + // Construct request + const request = { + resource, + policy, + }; + + // Run request + const response = await iotClient.setIamPolicy(request); + console.log(response); + } + + setIamPolicy(); + // [END cloudiot_v1_generated_DeviceManager_SetIamPolicy_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.test_iam_permissions.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.test_iam_permissions.js new file mode 100644 index 00000000000..5f5eb59cdf8 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.test_iam_permissions.js @@ -0,0 +1,61 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(resource, permissions) { + // [START cloudiot_v1_generated_DeviceManager_TestIamPermissions_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * REQUIRED: The resource for which the policy detail is being requested. + * See the operation documentation for the appropriate value for this field. + */ + // const resource = 'abc123' + /** + * The set of permissions to check for the `resource`. Permissions with + * wildcards (such as '*' or 'storage.*') are not allowed. For more + * information see + * [IAM Overview](https://cloud.google.com/iam/docs/overview#permissions). + */ + // const permissions = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function testIamPermissions() { + // Construct request + const request = { + resource, + permissions, + }; + + // Run request + const response = await iotClient.testIamPermissions(request); + console.log(response); + } + + testIamPermissions(); + // [END cloudiot_v1_generated_DeviceManager_TestIamPermissions_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.unbind_device_from_gateway.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.unbind_device_from_gateway.js new file mode 100644 index 00000000000..960f873c473 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.unbind_device_from_gateway.js @@ -0,0 +1,66 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(parent, gatewayId, deviceId) { + // [START cloudiot_v1_generated_DeviceManager_UnbindDeviceFromGateway_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The name of the registry. For example, + * `projects/example-project/locations/us-central1/registries/my-registry`. + */ + // const parent = 'abc123' + /** + * Required. The value of `gateway_id` can be either the device numeric ID or the + * user-defined device identifier. + */ + // const gatewayId = 'abc123' + /** + * Required. The device to disassociate from the specified gateway. The value of + * `device_id` can be either the device numeric ID or the user-defined device + * identifier. + */ + // const deviceId = 'abc123' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function unbindDeviceFromGateway() { + // Construct request + const request = { + parent, + gatewayId, + deviceId, + }; + + // Run request + const response = await iotClient.unbindDeviceFromGateway(request); + console.log(response); + } + + unbindDeviceFromGateway(); + // [END cloudiot_v1_generated_DeviceManager_UnbindDeviceFromGateway_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.update_device.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.update_device.js new file mode 100644 index 00000000000..a9910d37a4d --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.update_device.js @@ -0,0 +1,63 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(device, updateMask) { + // [START cloudiot_v1_generated_DeviceManager_UpdateDevice_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The new values for the device. The `id` and `num_id` fields must + * be empty, and the field `name` must specify the name path. For example, + * `projects/p0/locations/us-central1/registries/registry0/devices/device0`or + * `projects/p0/locations/us-central1/registries/registry0/devices/{num_id}`. + */ + // const device = '' + /** + * Required. Only updates the `device` fields indicated by this mask. + * The field mask must not be empty, and it must not contain fields that + * are immutable or only set by the server. + * Mutable top-level fields: `credentials`, `blocked`, and `metadata` + */ + // const updateMask = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function updateDevice() { + // Construct request + const request = { + device, + updateMask, + }; + + // Run request + const response = await iotClient.updateDevice(request); + console.log(response); + } + + updateDevice(); + // [END cloudiot_v1_generated_DeviceManager_UpdateDevice_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/samples/generated/v1/device_manager.update_device_registry.js b/packages/google-cloud-iot/samples/generated/v1/device_manager.update_device_registry.js new file mode 100644 index 00000000000..c521bf69340 --- /dev/null +++ b/packages/google-cloud-iot/samples/generated/v1/device_manager.update_device_registry.js @@ -0,0 +1,63 @@ +// Copyright 2021 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +'use strict'; + +function main(deviceRegistry, updateMask) { + // [START cloudiot_v1_generated_DeviceManager_UpdateDeviceRegistry_async] + /** + * TODO(developer): Uncomment these variables before running the sample. + */ + /** + * Required. The new values for the device registry. The `id` field must be empty, and + * the `name` field must indicate the path of the resource. For example, + * `projects/example-project/locations/us-central1/registries/my-registry`. + */ + // const deviceRegistry = '' + /** + * Required. Only updates the `device_registry` fields indicated by this mask. + * The field mask must not be empty, and it must not contain fields that + * are immutable or only set by the server. + * Mutable top-level fields: `event_notification_config`, `http_config`, + * `mqtt_config`, and `state_notification_config`. + */ + // const updateMask = '' + + // Imports the Iot library + const {DeviceManagerClient} = require('@google-cloud/iot').v1; + + // Instantiates a client + const iotClient = new DeviceManagerClient(); + + async function updateDeviceRegistry() { + // Construct request + const request = { + deviceRegistry, + updateMask, + }; + + // Run request + const response = await iotClient.updateDeviceRegistry(request); + console.log(response); + } + + updateDeviceRegistry(); + // [END cloudiot_v1_generated_DeviceManager_UpdateDeviceRegistry_async] +} + +process.on('unhandledRejection', err => { + console.error(err.message); + process.exitCode = 1; +}); +main(...process.argv.slice(2)); diff --git a/packages/google-cloud-iot/src/v1/device_manager_client.ts b/packages/google-cloud-iot/src/v1/device_manager_client.ts index e370cde11ce..2c0723f8007 100644 --- a/packages/google-cloud-iot/src/v1/device_manager_client.ts +++ b/packages/google-cloud-iot/src/v1/device_manager_client.ts @@ -2092,7 +2092,8 @@ export class DeviceManagerClient { gax.routingHeader.fromParams({ parent: request.parent || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listDeviceRegistries']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDeviceRegistries.createStream( this.innerApiCalls.listDeviceRegistries as gax.GaxCall, @@ -2148,7 +2149,8 @@ export class DeviceManagerClient { parent: request.parent || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listDeviceRegistries']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDeviceRegistries.asyncIterate( this.innerApiCalls['listDeviceRegistries'] as GaxCall, @@ -2319,7 +2321,8 @@ export class DeviceManagerClient { gax.routingHeader.fromParams({ parent: request.parent || '', }); - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listDevices']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDevices.createStream( this.innerApiCalls.listDevices as gax.GaxCall, @@ -2388,7 +2391,8 @@ export class DeviceManagerClient { parent: request.parent || '', }); options = options || {}; - const callSettings = new gax.CallSettings(options); + const defaultCallSettings = this._defaults['listDevices']; + const callSettings = defaultCallSettings.merge(options); this.initialize(); return this.descriptors.page.listDevices.asyncIterate( this.innerApiCalls['listDevices'] as GaxCall,