Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add registerToken support #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions bin/cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var gcr = require('../lib/gcr')
, sslcert: path
, sslkey: path
, cacert: path
, registerToken: String
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spacing to align with the others

}
, shortHand = { verbose: ['--loglevel', 'verbose']
, h: ['--help']
Expand All @@ -38,6 +39,7 @@ var gcr = require('../lib/gcr')
, C: ['--sslcert']
, K: ['--sslkey']
, A: ['--cacert']
, r: ['--registerToken']
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix spacing to align with the others

}
, parsed = nopt(knownOpts, shortHand)

Expand Down Expand Up @@ -110,6 +112,31 @@ gcr.load(parsed, function(err) {

if (!gcr.config.get('token')) {
questions.push(tokenQuestion)
if (!gcr.config.get('registerToken')) {
questions.push(tokenQuestion)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If token is false and registerToken is true, this will push tokenQuestion twice.

} else {
var fp = gcr.config.get('keypath')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use 2 spaces instead of tabs to match up with the rest of the repository. I'll have to see about getting this added to the linting rules, but i don't know about lilint. @evanlucas?

fs.readFile(fp, 'utf8', function(err, content) {
if (err) {
log.error('[readFile]', 'error reading public key', err)
process.exit(1)
}
gcr.client.registerRunner(content
, gcr.config.get('registerToken')
, function(err, token) {
if (err) {
log.error('[register]', 'error registering', err)
process.exit(1)
} else {
gcr.config.set('token', token)
gcr.config.save(function(err) {
if (err) throw err
})
}
})
})
}
needsRegToken = true
}

if (questions.length) {
Expand Down
1 change: 1 addition & 0 deletions lib/config.default.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = function(parsed) {
const o = {}
if (parsed.url) o.url = parsed.url
if (parsed.token) o.token = parsed.token
if (parsed.registToken) o.registToken = parsed.registerToken
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

registToken, registerToken should become registrationToken in all cases

if (parsed.buildDir) o.buildDir = parsed.buildDir
if (parsed.npm) o.npm = parsed.npm
if (parsed.timeout) o.timeout = parsed.timeout
Expand Down
3 changes: 3 additions & 0 deletions lib/gcr.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ gcr.load = function(opts, cb) {
if (opts.token) {
nconf.set('token', opts.token)
}
if (opts.registerToken) {
nconf.set('registerToken', opts.registerToken)
}
if (opts.buildDir) {
nconf.set('buildDir', opts.buildDir)
}
Expand Down