-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add more cache commands: get, list clear
also tests for same
- Loading branch information
1 parent
e63b160
commit cb8ca59
Showing
11 changed files
with
367 additions
and
183 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const util = require('util'), | ||
defaults = require('../defaults'), | ||
command_utils = require('./command-utils'); | ||
|
||
var descriptor = defaults.defaultDescriptor({ | ||
environment: { | ||
name: 'Environment', | ||
shortOption: 'e', | ||
required: true, | ||
prompt: true | ||
}, | ||
cache: { | ||
name: 'Cache Resource', | ||
shortOption: 'z', | ||
required: true | ||
} | ||
}); | ||
|
||
module.exports.descriptor = descriptor; | ||
|
||
module.exports.run = function(opts, cb) { | ||
if (opts.debug) { | ||
console.log('clearCache: %j', opts); | ||
} | ||
var uri = util.format('%s/v1/o/%s/e/%s/caches/%s/entries?action=clear', | ||
opts.baseuri, opts.organization, opts.environment, opts.cache); | ||
let requestOptions = { | ||
uri, | ||
method: 'POST', | ||
json: true, | ||
body: '', | ||
headers: { 'Content-Type': 'application/x-www-form-urlencoded', | ||
'Accept': 'application/json' } | ||
}; | ||
command_utils.run('clearCache', opts, requestOptions, cb); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
const util = require('util'), | ||
defaults = require('../defaults'), | ||
options = require('../options'); | ||
|
||
var descriptor = defaults.defaultDescriptor({ | ||
developerId: { | ||
name: 'Developer Id', | ||
required: true | ||
}, | ||
appName: { | ||
name: 'App Name', | ||
required: true | ||
}, | ||
key: { | ||
name: 'Client Key', | ||
required: true | ||
}, | ||
secret: { | ||
name: 'Client secret', | ||
required: true | ||
}, | ||
apiProducts : { | ||
name: 'API Products', | ||
required: true | ||
} | ||
|
||
}); | ||
|
||
module.exports.descriptor = descriptor; | ||
|
||
module.exports.run = function(opts, cb) { | ||
options.validateSync(opts, descriptor); | ||
if (opts.debug) { | ||
console.log('createAppKey: %j', opts); | ||
} | ||
var request = defaults.defaultRequest(opts); | ||
createAppKey(opts, request, function(err, results) { | ||
if (err) { | ||
cb(err); | ||
} | ||
else { | ||
if (opts.debug) { | ||
console.log('results: %j', results); | ||
} | ||
associateKeySecret(opts, request, function(err, results) { | ||
if (err) { | ||
cb(err); | ||
} else { | ||
if (opts.debug) { | ||
console.log('results: %j', results); | ||
} | ||
cb(undefined, results); | ||
} | ||
}); | ||
} | ||
}); | ||
}; | ||
|
||
function createAppKey(opts,request,done) { | ||
var payload = { | ||
consumerKey : opts.key, | ||
consumerSecret : opts.secret | ||
}; | ||
|
||
var uri = util.format('%s/v1/o/%s/developers/%s/apps/%s/keys/create', | ||
opts.baseuri, opts.organization, opts.developerId, opts.appName); | ||
request({ | ||
uri: uri, | ||
method:'POST', | ||
body: payload, | ||
json:true | ||
},function(err,res,body){ | ||
var jsonBody = body; | ||
if(err){ | ||
if (opts.debug) { | ||
console.log('Error occured %s', err); | ||
} | ||
done(err); | ||
}else if (res.statusCode === 201) { | ||
if (opts.verbose) { | ||
console.log('Create KeySecret successful'); | ||
} | ||
if (opts.debug) { | ||
console.log('%s', body); | ||
} | ||
done(undefined, jsonBody); | ||
}else { | ||
if (opts.verbose) { | ||
console.error('Create KeySecret result: %j', body); | ||
} | ||
var errMsg; | ||
if (jsonBody && (jsonBody.message)) { | ||
errMsg = jsonBody.message; | ||
} else { | ||
errMsg = util.format('Create KeySecret failed with status code %d', res.statusCode); | ||
} | ||
done(new Error(errMsg)); | ||
} | ||
}); | ||
} | ||
|
||
function associateKeySecret(opts,request,done) { | ||
var prods = opts.apiProducts; | ||
if (typeof prods === 'string') { | ||
prods = [prods]; | ||
} | ||
|
||
var payload = { | ||
apiProducts : prods | ||
}; | ||
|
||
var uri = util.format('%s/v1/o/%s/developers/%s/apps/%s/keys/%s', | ||
opts.baseuri, opts.organization, opts.developerId, opts.appName, opts.key); | ||
request({ | ||
uri: uri, | ||
method:'POST', | ||
body: payload, | ||
json:true | ||
},function(err,res,body){ | ||
var jsonBody = body; | ||
if(err){ | ||
if (opts.debug) { | ||
console.log('Error occured %s', err); | ||
} | ||
done(err); | ||
} | ||
else if (res.statusCode === 200) { | ||
if (opts.verbose) { | ||
console.log('Associate KeySecret successful'); | ||
} | ||
if (opts.debug) { | ||
console.log('%s', body); | ||
} | ||
done(undefined, jsonBody); | ||
}else { | ||
if (opts.verbose) { | ||
console.error('Associate KeySecret result: %j', body); | ||
} | ||
var errMsg; | ||
if (jsonBody && (jsonBody.message)) { | ||
errMsg = jsonBody.message; | ||
} else { | ||
errMsg = util.format('Associate KeySecret failed with status code %d', res.statusCode); | ||
} | ||
done(new Error(errMsg)); | ||
} | ||
}); | ||
} |
File renamed without changes.
Oops, something went wrong.