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

Ability to disable ensure resources #73

Merged
merged 3 commits into from
Jul 3, 2019
Merged
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
1 change: 1 addition & 0 deletions extension/docs/DevelopmentAndDeploymentGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Environment variables to configure the notification module:
|`API_EXTENSION_BASE_URL` | URL of the Extension module server. In case of any payment changes, [CTP API extension](https://docs.commercetools.com/http-api-projects-api-extensions) will call this URL and pass the payment object in body. | YES | |
|`LOG_LEVEL` | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info`
|`PORT` | port on which the application will run | NO | 8080
|`ENSURE_RESOURCES` | Set to `false` to disable the creation of resources in commercetools (e.g. custom types) | NO | `true`


After setting all environmental variables, execute command `npm run extension` to run the module.
Expand Down
3 changes: 2 additions & 1 deletion extension/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ function getEnvConfig () {
logLevel: process.env.LOG_LEVEL,
apiExtensionBaseUrl: process.env.API_EXTENSION_BASE_URL,
keepAliveTimeout: !Number.isNaN(process.env.KEEP_ALIVE_TIMEOUT) ? parseFloat(process.env.KEEP_ALIVE_TIMEOUT, 10)
: undefined
: undefined,
ensureResources: process.env.ENSURE_RESOURCES !== 'false'
}
}

Expand Down
6 changes: 4 additions & 2 deletions extension/src/config/init/ensure-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const { ensurePaymentCustomType } = require('./ensure-payment-custom-type')
const { ensureInterfaceInteractionCustomType } = require('./ensure-interface-interaction-custom-type')
const { ensureApiExtensions } = require('./ensure-api-extensions')
const ctpClientBuilder = require('../../ctp/ctp-client')
const config = require('../../config/config')
const configLoader = require('../../config/config')

const ctpClient = ctpClientBuilder.get()

Expand All @@ -14,9 +14,11 @@ function ensureCustomTypes () {
}

function ensureResources () {
let config = configLoader.load()
if (!config.ensureResources) return Promise.resolve()
return Promise.all([
ensureCustomTypes(),
ensureApiExtensions(ctpClient, config.load().apiExtensionBaseUrl)
ensureApiExtensions(ctpClient, config.apiExtensionBaseUrl)
])
}

Expand Down
1 change: 1 addition & 0 deletions notification/docs/DevelopmentGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ CTP_CLIENT_SECRET | commercetools client secret (you can get in the [commercetoo
LOG_LEVEL | bunyan log level (`trace`, `debug`, `info`, `warn`, `error`, `fatal`)| NO | `info`
PORT | port on which the application will run | NO | 443
KEEP_ALIVE_TIMEOUT | milliseconds to keep a socket alive after the last response ([Node.js docs](https://nodejs.org/dist/latest-v8.x/docs/api/http.html#http_server_keepalivetimeout)) | NO | Node.js default
ENSURE_RESOURCES | Set to `false` to disable the creation of resources in commercetools (e.g. custom types) | NO | `true`

Don't forget to provide all required environment variables
After setting all variables, execute command `npm run start` to run the module.
Expand Down
3 changes: 2 additions & 1 deletion notification/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ function getEnvConfig () {
return {
logLevel: process.env.LOG_LEVEL,
keepAliveTimeout: !Number.isNaN(process.env.KEEP_ALIVE_TIMEOUT) ? parseFloat(process.env.KEEP_ALIVE_TIMEOUT, 10)
: undefined
: undefined,
ensureResources: process.env.ENSURE_RESOURCES !== 'false'
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
const logger = require('../../utils/logger').getLogger()

const interfaceInteractionType = require('../../../resources/payment-interface-interaction-type.json')
const config = require('../../config/config')()

async function ensureInterfaceInteractionCustomType (ctpClient) {
try {
if (!config.ensureResources) return
logger.debug('Ensuring interfaceInteraction')
const { body } = await ctpClient.fetch(ctpClient.builder.types.where(`key="${interfaceInteractionType.key}"`))
if (body.results.length === 0) {
Expand Down