Skip to content

Commit

Permalink
adds support for 'app' and 'credentials' in Appbase parameters
Browse files Browse the repository at this point in the history
* credentials can be used in lieu of username, password parameters
* app can be used as a shorthand for appname

This change is backwards compatible.
  • Loading branch information
siddharthlatest committed Mar 5, 2017
1 parent 7cac816 commit e22c4ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
20 changes: 13 additions & 7 deletions src/appbase.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ var appbaseClient = function appbaseClient(args) {
return new appbaseClient(args)
}

if (typeof args.appname !== 'string' || args.appname === '') {
throw new Error('Appname not present in options.')
}

if (typeof args.url !== 'string' || args.url === '') {
throw new Error('URL not present in options.')
}
Expand All @@ -34,18 +30,28 @@ var appbaseClient = function appbaseClient(args) {
this.url = parsedUrl.host
this.protocol = parsedUrl.protocol
this.credentials = parsedUrl.auth
this.appname = args.appname
this.appname = args.appname || args.app

if (typeof this.appname !== 'string' || this.appname === '') {
throw new Error('App name is not present in options.')
}

if (typeof this.protocol !== 'string' || this.protocol === '') {
throw new Error('Protocol not present in url. URL should be of the form https://scalr.api.appbase.io')
throw new Error('Protocol is not present in url. URL should be of the form https://scalr.api.appbase.io')
}

if (typeof args.username === 'string' && args.username !== '' && typeof args.password === 'string' && args.password !== '') {
this.credentials = args.username + ':' + args.password
}

// credentials can be provided as a part of the URL, as username, password args or
// as a credentials argument directly
if (typeof args.credentials === 'string' && args.credentials !== '') {
this.credentials = args.credentials
}

if (typeof this.credentials !== 'string' || this.credentials === '') {
throw new Error('Authentication information not present.')
throw new Error('Authentication information is not present. Did you add credentials?')
}

if (parsedUrl.protocol === 'https:') {
Expand Down
7 changes: 4 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ describe('Appbase', function() {

before(function() {
streamingClient = new appbase({
url: 'http://QEVrcElba:[email protected]',
appname: 'es2test1'
url: 'https://scalr.api.appbase.io',
app: 'es2test1',
credentials: 'QEVrcElba:5c13d943-a5d1-4b05-92f3-42707d49fcbb'
})
})

Expand Down Expand Up @@ -99,4 +100,4 @@ describe('Appbase', function() {
}
})
})
})
})

0 comments on commit e22c4ce

Please sign in to comment.