Skip to content
This repository has been archived by the owner on Mar 10, 2021. It is now read-only.

Commit

Permalink
Allow to define all credentials in config files.
Browse files Browse the repository at this point in the history
  • Loading branch information
hajoeichler committed Mar 27, 2014
1 parent 65dbb86 commit c34a194
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ before_script:
script:
- npm test
- node lib/run --projectKey ${SPHERE_PROJECT_KEY} --clientId ${SPHERE_CLIENT_ID} --clientSecret ${SPHERE_CLIENT_SECRET}
- node lib/run --projectKey ${SPHERE_PROJECT_KEY}
env:
global:
- secure: hKwW5y/IJZp1WrgTlYtkmP7KZ8rYQGUFkvPw7j5fPDYALnrdDkkrEhX/mdjIXhnmR6Q9Ji+G9MKo9r8heNqTLMU68Fp1dBWqNbWCnRZlXHFy1qQaLzgGZiVM+gxbOhqrEMTgh5yjsC8gg0InbvfliCjdM1lD4Bt1oKuWU1MFU7c=
Expand Down
2 changes: 2 additions & 0 deletions create_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ exports.config = {
project_key: "${SPHERE_PROJECT_KEY}",
}
EOF

echo "${SPHERE_CLIENT_ID}:${SPHERE_CLIENT_SECRET}:${SPHERE_PROJECT_KEY}" > ".sphere-credentials"
2 changes: 1 addition & 1 deletion src/coffee/pricesync.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class PriceSync extends CommonUpdater
getPublishedVariantByMasterSku: (client, variant) ->
deferred = Q.defer()
variant.attributes or= []
attribute = _.find variant.attributes, (attribute) =>
attribute = _.find variant.attributes, (attribute) ->
attribute.name is 'mastersku'
unless attribute
deferred.reject new DataIssue("No mastersku attribute!")
Expand Down
49 changes: 28 additions & 21 deletions src/coffee/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package_json = require '../package.json'
Config = require '../config'
Logger = require './logger'
PriceSync = require '../lib/pricesync'
{ProjectCredentialsConfig} = require 'sphere-node-utils'

argv = require('optimist')
.usage('Usage: $0 --projectKey key --clientId id --clientSecret secret --logDir dir --logLevel level --timeout timeout')
Expand All @@ -15,7 +16,7 @@ argv = require('optimist')
.default('logLevel', 'info')
.default('logDir', '.')
.default('timeout', 60000)
.demand(['projectKey','clientId', 'clientSecret'])
.demand(['projectKey'])
.argv

logger = new Logger
Expand All @@ -27,26 +28,32 @@ logger = new Logger
process.on 'SIGUSR2', ->
logger.reopenFileStreams()

options =
baseConfig:
timeout: argv.timeout
user_agent: "#{package_json.name} - #{package_json.version}"
logConfig:
logger: logger
master: Config.config
retailer:
project_key: argv.projectKey
client_id: argv.clientId
client_secret: argv.clientSecret
credentialsConfig = ProjectCredentialsConfig.create()
.then (credentials) ->
options =
baseConfig:
timeout: argv.timeout
user_agent: "#{package_json.name} - #{package_json.version}"
logConfig:
logger: logger
master: credentials.enrichCredentials
project_key: Config.config.project_key
client_id: Config.config.client_id
client_secret: Config.config.client_secret
retailer: credentials.enrichCredentials
project_key: argv.projectKey
client_id: argv.clientId
client_secret: argv.clientSecret

options.baseConfig.host = argv.sphereHost if argv.sphereHost?
options.baseConfig.host = argv.sphereHost if argv.sphereHost?

updater = new PriceSync options
updater.run()
.then (msg) ->
logger.info info: msg, msg
process.exit 0
.fail (msg) ->
updater = new PriceSync options
updater.run()
.then (msg) ->
logger.info info: msg, msg
process.exit 0

.fail (err) ->
logger.error error: msg, msg
process.exit 1
.done()
process.exit 2
.done()
2 changes: 1 addition & 1 deletion src/spec/integration.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe '#run', ->
]
version: result.version
@client.products.byId(@masterProductId).save(data)
.then (result) =>
.then (result) ->
console.log 6
done()
.fail (error) ->
Expand Down

0 comments on commit c34a194

Please sign in to comment.