Skip to content

Instantly share code, notes, and snippets.

@masato
Last active December 27, 2015 18:17
Show Gist options
  • Save masato/a2ae35e3b6359f21a9a1 to your computer and use it in GitHub Desktop.
Save masato/a2ae35e3b6359f21a9a1 to your computer and use it in GitHub Desktop.
Webhook as a ServiceでIoTのserverlessなバックエンド考える - Part 3: Webtask.ioでIDCFクラウド APIのセキュアな情報を扱う ref: http://qiita.com/masato/items/7a9fc2c9408fbb3ca5c0
$ export PARAMETERIZED_TOKEN=$(curl -s https://webtask.it.auth0.com/api/tokens/issue -H "Authorization: Bearer eyJhbxxx" \
-H "Content-Type: application/json" \
--data-binary '{"url":"http://bit.ly/1wT1DOi","ectx":{"secret":"abc!123"}}')
$ wt create https://raw.githubusercontent.com/auth0/wt-cli/master/sample-webtasks/mongodb.js \
--name mongo \
--secret MONGO_URL=mongodb://webtask:supersecret@ds047592.mongolab.com:47592/webtask-examples
$ wt create startstop.js \
--name startstop \
--secret apikey=xxx \
--secret secretkey=xxx \
--secret endpoint=xxx
https://webtask.it.auth0.com/api/run/{コンテナ名}/startstop?webtask_no_cache=1
$ curl "https://webtask.it.auth0.com/api/run/{コンテナ名}/startstop?webtask_no_cache=1&key={デフォルトのkey}&command=stop&id={仮想マシンのID}"
{"stopvirtualmachineresponse":{"jobid":"ad52d24e-xxx"}}
$ curl "https://webtask.it.auth0.com/api/run/{コンテナ名}/startstop?webtask_no_cache=1&key={デフォルトのkey}&command=start&id={仮想マシンのID}"
module.exports = function(context, cb) {
var MONGO_URL = context.data.MONGO_URL;
module.exports = function(context, cb) {
var query = {
apiKey: context.data.apikey,
response: 'json',
command: context.data.command+'VirtualMachine',
id: context.data.id
}
query.signature = buildSignature(query, context.data.secretkey);
request.get({
url: context.data.endpoint,
qs: query,
json: true
}, function (error, response, body) {
cb(null, body);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment