mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-03-10 22:44:14 +00:00
Auto-merge for PR #923 via VersionBot
Update OS & config actions to the MC SDK, and add a --version option
This commit is contained in:
commit
79d9ebc805
@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file
|
||||
automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## v7.7.4 - 2018-07-17
|
||||
|
||||
* Update TypeScript to 2.8.1 #923 [Tim Perry]
|
||||
* Add --version options to os configure & config generate #923 [Tim Perry]
|
||||
* Update OS & config actions to the latest SDK #923 [Tim Perry]
|
||||
|
||||
## v7.7.3 - 2018-07-13
|
||||
|
||||
* Update the deploy key since npm invalidated the old one #927 [Tim Perry]
|
||||
|
@ -977,17 +977,20 @@ the path to the output JSON file
|
||||
Use this command to configure a previously downloaded operating system image for
|
||||
the specific device or for an application generally.
|
||||
|
||||
Calling this command without --version is not recommended, and may fail in
|
||||
future releases if the OS version cannot be inferred.
|
||||
|
||||
Note that device api keys are only supported on ResinOS 2.0.3+.
|
||||
|
||||
This comand still supports the *deprecated* format where the UUID and optionally device key
|
||||
This command still supports the *deprecated* format where the UUID and optionally device key
|
||||
are passed directly on the command line, but the recommended way is to pass either an --app or
|
||||
--device argument. The deprecated format will be remove in a future release.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>
|
||||
$ resin os configure ../path/rpi.img --app MyApp
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6 --version 2.12.7
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6 --version 2.12.7 --device-api-key <existingDeviceKey>
|
||||
$ resin os configure ../path/rpi.img --app MyApp --version 2.12.7
|
||||
|
||||
### Options
|
||||
|
||||
@ -1007,6 +1010,10 @@ device uuid
|
||||
|
||||
custom device key - note that this is only supported on ResinOS 2.0.3+
|
||||
|
||||
#### --version <version>
|
||||
|
||||
a resinOS version
|
||||
|
||||
#### --config <config>
|
||||
|
||||
path to the config JSON file, see `resin os build-config`
|
||||
@ -1125,22 +1132,29 @@ show advanced commands
|
||||
|
||||
Use this command to generate a config.json for a device or application.
|
||||
|
||||
Calling this command without --version is not recommended, and may fail in
|
||||
future releases if the OS version cannot be inferred.
|
||||
|
||||
This is interactive by default, but you can do this automatically without interactivity
|
||||
by specifying an option for each question on the command line, if you know the questions
|
||||
that will be asked for the relevant device type.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin config generate --device 7cf02a6
|
||||
$ resin config generate --device 7cf02a6 --generate-device-api-key
|
||||
$ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey>
|
||||
$ resin config generate --device 7cf02a6 --output config.json
|
||||
$ resin config generate --app MyApp
|
||||
$ resin config generate --app MyApp --output config.json
|
||||
$ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7 --generate-device-api-key
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7 --device-api-key <existingDeviceKey>
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7 --output config.json
|
||||
$ resin config generate --app MyApp --version 2.12.7
|
||||
$ resin config generate --app MyApp --version 2.12.7 --output config.json
|
||||
$ resin config generate --app MyApp --version 2.12.7 --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1
|
||||
|
||||
### Options
|
||||
|
||||
#### --version <version>
|
||||
|
||||
a resinOS version
|
||||
|
||||
#### --application, -a, --app <application>
|
||||
|
||||
application name
|
||||
|
@ -44,6 +44,11 @@ exports.optionalDeviceApiKey =
|
||||
parameter: 'device-api-key'
|
||||
alias: 'k'
|
||||
|
||||
exports.optionalOsVersion =
|
||||
signature: 'version'
|
||||
description: 'a resinOS version'
|
||||
parameter: 'version'
|
||||
|
||||
exports.booleanDevice =
|
||||
signature: 'device'
|
||||
description: 'device'
|
||||
|
@ -223,21 +223,26 @@ exports.generate =
|
||||
help: '''
|
||||
Use this command to generate a config.json for a device or application.
|
||||
|
||||
Calling this command without --version is not recommended, and may fail in
|
||||
future releases if the OS version cannot be inferred.
|
||||
|
||||
This is interactive by default, but you can do this automatically without interactivity
|
||||
by specifying an option for each question on the command line, if you know the questions
|
||||
that will be asked for the relevant device type.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin config generate --device 7cf02a6
|
||||
$ resin config generate --device 7cf02a6 --generate-device-api-key
|
||||
$ resin config generate --device 7cf02a6 --device-api-key <existingDeviceKey>
|
||||
$ resin config generate --device 7cf02a6 --output config.json
|
||||
$ resin config generate --app MyApp
|
||||
$ resin config generate --app MyApp --output config.json
|
||||
$ resin config generate --app MyApp --network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7 --generate-device-api-key
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7 --device-api-key <existingDeviceKey>
|
||||
$ resin config generate --device 7cf02a6 --version 2.12.7 --output config.json
|
||||
$ resin config generate --app MyApp --version 2.12.7
|
||||
$ resin config generate --app MyApp --version 2.12.7 --output config.json
|
||||
$ resin config generate --app MyApp --version 2.12.7 \
|
||||
--network wifi --wifiSsid mySsid --wifiKey abcdefgh --appUpdatePollInterval 1
|
||||
'''
|
||||
options: [
|
||||
commandOptions.optionalOsVersion
|
||||
commandOptions.optionalApplication
|
||||
commandOptions.optionalDevice
|
||||
commandOptions.optionalDeviceApiKey
|
||||
@ -279,7 +284,7 @@ exports.generate =
|
||||
normalizeUuidProp(options, 'device')
|
||||
Promise = require('bluebird')
|
||||
writeFileAsync = Promise.promisify(require('fs').writeFile)
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
resin = require('resin-sdk').fromSharedOptions()
|
||||
form = require('resin-cli-form')
|
||||
deviceConfig = require('resin-device-config')
|
||||
prettyjson = require('prettyjson')
|
||||
@ -308,6 +313,8 @@ exports.generate =
|
||||
# required option, that value is used (and the corresponding question is not asked)
|
||||
form.run(formOptions, override: options)
|
||||
.then (answers) ->
|
||||
answers.version = options.version
|
||||
|
||||
if resource.uuid?
|
||||
generateDeviceConfig(resource, options.deviceApiKey || options['generate-device-api-key'], answers)
|
||||
else
|
||||
|
@ -31,7 +31,7 @@ resolveVersion = (deviceType, version) ->
|
||||
return Promise.resolve(version)
|
||||
|
||||
form = require('resin-cli-form')
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
resin = require('resin-sdk').fromSharedOptions()
|
||||
|
||||
resin.models.os.getSupportedVersions(deviceType)
|
||||
.then ({ versions, recommended }) ->
|
||||
@ -57,7 +57,7 @@ exports.versions =
|
||||
$ resin os versions raspberrypi3
|
||||
'''
|
||||
action: (params, options, done) ->
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
resin = require('resin-sdk').fromSharedOptions()
|
||||
|
||||
resin.models.os.getSupportedVersions(params.type)
|
||||
.then ({ versions, recommended }) ->
|
||||
@ -203,17 +203,20 @@ exports.configure =
|
||||
Use this command to configure a previously downloaded operating system image for
|
||||
the specific device or for an application generally.
|
||||
|
||||
Calling this command without --version is not recommended, and may fail in
|
||||
future releases if the OS version cannot be inferred.
|
||||
|
||||
Note that device api keys are only supported on ResinOS 2.0.3+.
|
||||
|
||||
This comand still supports the *deprecated* format where the UUID and optionally device key
|
||||
This command still supports the *deprecated* format where the UUID and optionally device key
|
||||
are passed directly on the command line, but the recommended way is to pass either an --app or
|
||||
--device argument. The deprecated format will be remove in a future release.
|
||||
|
||||
Examples:
|
||||
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6 --deviceApiKey <existingDeviceKey>
|
||||
$ resin os configure ../path/rpi.img --app MyApp
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6 --version 2.12.7
|
||||
$ resin os configure ../path/rpi.img --device 7cf02a6 --version 2.12.7 --device-api-key <existingDeviceKey>
|
||||
$ resin os configure ../path/rpi.img --app MyApp --version 2.12.7
|
||||
'''
|
||||
permission: 'user'
|
||||
options: [
|
||||
@ -221,6 +224,7 @@ exports.configure =
|
||||
commandOptions.optionalApplication
|
||||
commandOptions.optionalDevice
|
||||
commandOptions.optionalDeviceApiKey
|
||||
commandOptions.optionalOsVersion
|
||||
{
|
||||
signature: 'config'
|
||||
description: 'path to the config JSON file, see `resin os build-config`'
|
||||
@ -233,7 +237,7 @@ exports.configure =
|
||||
fs = require('fs')
|
||||
Promise = require('bluebird')
|
||||
readFileAsync = Promise.promisify(fs.readFile)
|
||||
resin = require('resin-sdk-preconfigured')
|
||||
resin = require('resin-sdk').fromSharedOptions()
|
||||
init = require('resin-device-init')
|
||||
helpers = require('../utils/helpers')
|
||||
patterns = require('../utils/patterns')
|
||||
@ -279,6 +283,8 @@ exports.configure =
|
||||
.then(JSON.parse)
|
||||
return buildConfig(params.image, appOrDevice.device_type, options.advanced)
|
||||
.then (answers) ->
|
||||
answers.version = options.version
|
||||
|
||||
(if configurationResourceType == 'device'
|
||||
generateDeviceConfig(appOrDevice, deviceApiKey, answers)
|
||||
else
|
||||
|
@ -15,22 +15,21 @@ limitations under the License.
|
||||
*/
|
||||
import Promise = require('bluebird');
|
||||
import ResinSdk = require('resin-sdk');
|
||||
import _ = require('lodash');
|
||||
import deviceConfig = require('resin-device-config');
|
||||
import * as semver from 'resin-semver';
|
||||
|
||||
const resin = ResinSdk.fromSharedOptions();
|
||||
|
||||
export function generateBaseConfig(
|
||||
application: ResinSdk.Application,
|
||||
options: { appUpdatePollInterval?: number },
|
||||
options: { version?: string; appUpdatePollInterval?: number },
|
||||
) {
|
||||
options = _.mapValues(options, function(value, key) {
|
||||
if (key === 'appUpdatePollInterval') {
|
||||
return value! * 60 * 1000;
|
||||
} else {
|
||||
return value;
|
||||
}
|
||||
});
|
||||
if (options.appUpdatePollInterval) {
|
||||
options = {
|
||||
...options,
|
||||
appUpdatePollInterval: options.appUpdatePollInterval * 60 * 1000,
|
||||
};
|
||||
}
|
||||
|
||||
return Promise.props({
|
||||
userId: resin.auth.getUserId(),
|
||||
@ -66,27 +65,30 @@ export function generateBaseConfig(
|
||||
|
||||
export function generateApplicationConfig(
|
||||
application: ResinSdk.Application,
|
||||
options: {},
|
||||
options: { version?: string },
|
||||
) {
|
||||
return generateBaseConfig(application, options).tap(config =>
|
||||
addApplicationKey(config, application.id),
|
||||
);
|
||||
return generateBaseConfig(application, options).tap(config => {
|
||||
if (semver.satisfies(options.version, '>=2.7.8')) {
|
||||
return addProvisioningKey(config, application.id);
|
||||
} else {
|
||||
return addApplicationKey(config, application.id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function generateDeviceConfig(
|
||||
device: ResinSdk.Device & { application_name: string },
|
||||
device: ResinSdk.Device & { belongs_to__application: ResinSdk.PineDeferred },
|
||||
deviceApiKey: string | true | null,
|
||||
options: {},
|
||||
options: { version?: string },
|
||||
) {
|
||||
return resin.models.application
|
||||
.get(device.application_name)
|
||||
.get(device.belongs_to__application.__id)
|
||||
.then(application => {
|
||||
return generateBaseConfig(application, options).tap(config => {
|
||||
// Device API keys are only safe for ResinOS 2.0.3+. We could somehow obtain
|
||||
// the expected version for this config and generate one when we know it's safe,
|
||||
// but instead for now we fall back to app keys unless the user has explicitly opted in.
|
||||
if (deviceApiKey) {
|
||||
return addDeviceKey(config, device.uuid, deviceApiKey);
|
||||
} else if (semver.satisfies(options.version, '>=2.0.3')) {
|
||||
return addDeviceKey(config, device.uuid, true);
|
||||
} else {
|
||||
return addApplicationKey(config, application.id);
|
||||
}
|
||||
@ -111,6 +113,14 @@ function addApplicationKey(config: any, applicationNameOrId: string | number) {
|
||||
});
|
||||
}
|
||||
|
||||
function addProvisioningKey(config: any, applicationNameOrId: string | number) {
|
||||
return resin.models.application
|
||||
.generateProvisioningKey(applicationNameOrId)
|
||||
.tap(apiKey => {
|
||||
config.apiKey = apiKey;
|
||||
});
|
||||
}
|
||||
|
||||
function addDeviceKey(
|
||||
config: any,
|
||||
uuid: string,
|
||||
|
27
package.json
27
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "resin-cli",
|
||||
"version": "7.7.3",
|
||||
"version": "7.7.4",
|
||||
"description": "The official resin.io CLI tool",
|
||||
"main": "./build/actions/index.js",
|
||||
"homepage": "https://github.com/resin-io/resin-cli",
|
||||
@ -57,17 +57,17 @@
|
||||
"node": ">=6.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/archiver": "^2.0.1",
|
||||
"@types/bluebird": "^3.5.19",
|
||||
"@types/common-tags": "^1.4.0",
|
||||
"@types/archiver": "2.1.2",
|
||||
"@types/bluebird": "3.5.19",
|
||||
"@types/common-tags": "1.4.0",
|
||||
"@types/es6-promise": "0.0.32",
|
||||
"@types/fs-extra": "^5.0.0",
|
||||
"@types/is-root": "^1.0.0",
|
||||
"@types/lodash": "^4.14.103",
|
||||
"@types/mkdirp": "^0.5.2",
|
||||
"@types/node": "^9.0.0",
|
||||
"@types/fs-extra": "5.0.4",
|
||||
"@types/is-root": "1.0.0",
|
||||
"@types/lodash": "4.14.103",
|
||||
"@types/mkdirp": "0.5.2",
|
||||
"@types/node": "10.5.2",
|
||||
"@types/prettyjson": "0.0.28",
|
||||
"@types/raven": "^2.1.2",
|
||||
"@types/raven": "2.5.1",
|
||||
"catch-uncommitted": "^1.0.0",
|
||||
"ent": "^2.2.0",
|
||||
"filehound": "^1.16.2",
|
||||
@ -85,11 +85,12 @@
|
||||
"resin-lint": "^1.5.0",
|
||||
"rewire": "^3.0.2",
|
||||
"ts-node": "^4.0.1",
|
||||
"typescript": "2.4.0"
|
||||
"typescript": "2.8.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@resin.io/valid-email": "^0.1.0",
|
||||
"@types/stream-to-promise": "^2.2.0",
|
||||
"@types/stream-to-promise": "2.2.0",
|
||||
"JSONStream": "^1.0.3",
|
||||
"ansi-escapes": "^2.0.0",
|
||||
"any-promise": "^1.3.0",
|
||||
"archiver": "^2.1.0",
|
||||
@ -119,7 +120,6 @@
|
||||
"inquirer": "^3.1.1",
|
||||
"is-root": "^1.0.0",
|
||||
"js-yaml": "^3.10.0",
|
||||
"JSONStream": "^1.0.3",
|
||||
"klaw": "^1.3.1",
|
||||
"lodash": "^4.17.4",
|
||||
"mixpanel": "^0.4.0",
|
||||
@ -151,6 +151,7 @@
|
||||
"resin-release": "^1.2.0",
|
||||
"resin-sdk": "10.0.0-beta1",
|
||||
"resin-sdk-preconfigured": "^6.9.0",
|
||||
"resin-semver": "^1.2.2",
|
||||
"resin-settings-client": "^3.6.1",
|
||||
"resin-stream-logger": "^0.1.0",
|
||||
"resin-sync": "^9.3.3",
|
||||
|
@ -4,6 +4,7 @@
|
||||
"target": "es5",
|
||||
"outDir": "build",
|
||||
"strict": true,
|
||||
"strictPropertyInitialization": false,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"preserveConstEnums": true,
|
||||
|
Loading…
x
Reference in New Issue
Block a user