Skip to content

Commit c65243c

Browse files
committed
Set auto provision bucket as true by default and fixed project assignment
1 parent 494bf3b commit c65243c

File tree

6 files changed

+23
-6
lines changed

6 files changed

+23
-6
lines changed

http-device/CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## [1.1.1] - 2024-03-22
4+
5+
### Fixed
6+
7+
- Auto provision bucket is set true as default
8+
- Assign project to provisioned failing device provisioning
9+
310
## [1.1.0] - 2024-02-15
411

512
### Added
@@ -26,6 +33,7 @@
2633

2734
- Make sure Thinger server is running before starting service
2835

36+
[1.1.1]: https://github.com/thinger-io/plugins/compare/http-device/v1.1.0...http-device/v1.1.1
2937
[1.1.0]: https://github.com/thinger-io/plugins/compare/http-device/v1.0.2...http-device/v1.1.0
3038
[1.0.2]: https://github.com/thinger-io/plugins/tree/http-device/v1.0.2
3139

http-device/plugin.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name" : "http-device",
3-
"version" : "1.1.0",
3+
"version" : "1.1.1",
44
"description" : "Plugin for handling generic HTTP devices.",
55
"author" : "Alvaro Luis Bustamante",
66
"license" : "MIT",

http-device/task/api/api.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ module.exports.createHTTPDevice = async function(deviceId, deviceName, deviceDes
2121
};
2222
if(settings.assign_asset_type) data.asset_type = settings.assign_asset_type;
2323
if(settings.assign_asset_group) data.asset_group = settings.assign_asset_group;
24-
if(settings.assign_project) data.project = settings.assign_project;
2524
if(settings.assign_product) data.product = settings.assign_product;
2625
console.log(`creating device: ${JSON.stringify(data)}`);
2726
return axios({
@@ -106,3 +105,12 @@ module.exports.getDeviceProperty = async function(deviceId, propertyId){
106105
url: `/v3/users/${USER}/devices/${deviceId}/properties/${propertyId}`,
107106
});
108107
};
108+
109+
module.exports.setDeviceProject = async function(deviceID, project) {
110+
console.log(`setting project ${project} for ${device}`);
111+
return axios({
112+
method: 'put',
113+
url: `/v1/users/${USER}/devices/${deviceID}/projects`,
114+
data: JSON.stringify([ project ])
115+
});
116+
}

http-device/task/app.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ async function handleDeviceRequest(req) {
196196
if (payload!==undefined && (error.response && error.response.status===404)) {
197197

198198
// no auto provision
199-
if (!settings.auto_provision_resources && !settings.auto_provision_bucket) return reject(error);
199+
if (!settings.auto_provision_resources) return reject(error);
200200

201201
let realBucketId = getBucketId(deviceId, settings);
202202

@@ -213,6 +213,7 @@ async function handleDeviceRequest(req) {
213213
if ( typeof realBucketId !== 'undefined' ) actions["write_bucket"] = realBucketId;
214214
thinger.setDeviceCallback(realDeviceId, actions, {timeout: getDeviceTimeout(settings)})
215215
})
216+
.then(() => settings.assign_project ? thinger.setDeviceProject(realDeviceId, settings.assign_project) : Promise.resolve())
216217
.then(() => thinger.callDeviceCallback(realDeviceId, processedPayload, sourceIP, timestamp))
217218
.then((response) => {
218219
response.data = runCallback(response.data, 'response', deviceType, response.headers);

http-device/task/package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

http-device/task/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-device",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Plugin for handling generic HTTP devices.",
55
"author": "Alvaro Luis Bustamante",
66
"license": "MIT",

0 commit comments

Comments
 (0)