Skip to content

Commit

Permalink
Close #2
Browse files Browse the repository at this point in the history
Along with support from the keybase maintstream
  • Loading branch information
maxtaco committed Jan 16, 2014
1 parent 9c115cc commit d81de6f
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/command/version.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/constants.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/err.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion lib/package.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 28 additions & 11 deletions lib/req.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion src/command/version.iced
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ exports.Command = class Command extends Base
lines = [
(pjs.bin() + " (keybase.io CLI) v" + pjs.version())
("- node.js " + process.version)
].concat("- #{l}" for l in gpg_v)
].concat("- #{l}" for l in gpg_v).concat [
("Identifies as: '" + pjs.identify_as() + "'")
]
console.log lines.join("\n")

cb err
Expand Down
1 change: 1 addition & 0 deletions src/constants.iced
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ exports.constants = constants =
version : 1
api_version : "1.0"
canonical_host : "keybase.io"
client_name : "keybase.io node.js client"
server :
host : "api.keybase.io"
port : 443
Expand Down
1 change: 1 addition & 0 deletions src/err.iced
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ exports.E = E = ie.make_errors
UNKNOWN_SERVICE : "unknown service"
PROOF_NOT_AVAILABLE : "proof isn't available"
WRONG_SIGNER : "Expected a signature, but by someone else"
REQUIRED_UPGRADE : "Software upgrade required"

#================================================

Expand Down
6 changes: 6 additions & 0 deletions src/package.iced
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ path = require 'path'
fs = require 'fs'
log = require './log'
package_json = require '../package.json'
{constants} = require './constants'

##=======================================================================

Expand All @@ -20,5 +21,10 @@ exports.PackageJson = class PackageJson
for k,v of @json.bin
return k

#------------

identify_as : () ->
"#{constants.client_name} v#{@version()}"

##=======================================================================

13 changes: 11 additions & 2 deletions src/req.iced
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ urlmod = require 'url'
{E} = require './err'
log = require './log'
{certs} = require './ca'
{PackageJson} = require './package'

#=================================================

Expand Down Expand Up @@ -61,7 +62,8 @@ exports.Client = class Client
req : ({method, endpoint, args, http_status, kb_status}, cb) ->
method or= 'GET'
opts = { method, json : true, jar : true }
opts.headers = @headers if @headers?
opts.headers = @headers or {}
opts.headers["X-Keybase-Client"] = (new PackageJson).identify_as()

kb_status or= [ "OK" ]
http_status or= [ 200 ]
Expand All @@ -86,13 +88,20 @@ exports.Client = class Client
await request opts, defer err, res, body
if err? then #noop
else if not (res.statusCode in http_status)
err = new E.HttpError "Got reply #{res.statusCode}"
if res.statusCode is 400 and res.headers?["x-keybase-client-unsupported"]
v = res.headers["x-keybase-client-upgrade-to"]
err = new E.RequiredUpgradeError "Upgrade is required! Run `keybase-install` to upgrade to v#{v}"
err.upgrade_to = v
else
err = new E.HttpError "Got reply #{res.statusCode}"
else if not (body?.status?.name in kb_status)
err = new E.KeybaseError "#{body.status.desc} (error ##{body.status.code})"
err.fields = body.status?.fields or {}
log.debug "Full request: #{JSON.stringify opts}"
log.debug "Full reply: #{JSON.stringify body}"
else
if (v = res.headers["x-keybase-client-upgrade-to"])?
log.warn "Upgrade suggested! Run `keybase-install` to upgrade to v#{v}"
@_find_cookies res

# Note the swap --- we care more about the body in most cases.
Expand Down

0 comments on commit d81de6f

Please sign in to comment.