-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
162 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ pipeline { | |
MPKIT_EMAIL = "[email protected]" | ||
MPKIT_URL = "https://qa-17263.staging.oregon.platform-os.com" | ||
POS_PORTAL_PASSWORD = credentials('POS_PORTAL_PASSWORD') | ||
CI = 'true' | ||
} | ||
|
||
stages { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,83 +1,31 @@ | ||
#!/usr/bin/env node | ||
|
||
const { program } = require('commander'); | ||
const ServerError = require('../lib//ServerError'); | ||
const logger = require('../lib/logger'); | ||
const validate = require('../lib/validators'); | ||
const Portal = require('../lib/portal'); | ||
const waitForStatus = require('../lib/data/waitForStatus'); | ||
const { readPassword } = require('../lib/utils/password'); | ||
const { storeEnvironment, deviceAuthorizationFlow } = require('../lib/environments'); | ||
const ServerError = require('../lib/ServerError'); | ||
|
||
const saveToken = (settings, token) => { | ||
storeEnvironment(Object.assign(settings, { token: token })); | ||
logger.Success(`Environment ${settings.url} as ${settings.environment} has been added successfuly.`); | ||
}; | ||
|
||
const help = () => { | ||
program.outputHelp(); | ||
process.exit(1); | ||
} | ||
|
||
const checkParams = params => { | ||
// validate.existence({ argumentValue: params.email, argumentName: 'email', fail: help }); | ||
if (params.email) validate.email(params.email); | ||
|
||
validate.existence({ argumentValue: program.args[0], argumentName: 'environment', fail: help }); | ||
|
||
validate.existence({ argumentValue: params.url, argumentName: 'URL', fail: help }); | ||
if (params.url.slice(-1) != '/') { | ||
params.url = params.url + '/'; | ||
} | ||
validate.url(params.url); | ||
}; | ||
|
||
|
||
const login = async (email, password, url) => { | ||
return Portal.login(email, password, url) | ||
.then(response => { | ||
if (response) return Promise.resolve(response[0].token); | ||
}) | ||
} | ||
const addEnv = require('../lib/env-add/main') | ||
|
||
program.showHelpAfterError(); | ||
program | ||
.name('pos-cli env add') | ||
.arguments('[environment]', 'name of environment. Example: staging') | ||
.arguments('<environment>', 'name of environment. Example: staging') | ||
.option('--email <email>', 'Partner Portal account email. Example: [email protected]') | ||
.option('--url <url>', 'marketplace url. Example: https://example.com') | ||
.requiredOption('--url <url>', 'marketplace url. Example: https://example.com') | ||
.option('--partner-portal-url <partnerPortalUrl>', 'Partner Partner URL', 'https://partners.platformos.com') | ||
.option( | ||
'--token <token>', | ||
'if you have a token you can add it directly to pos-cli configuration without connecting to portal' | ||
) | ||
.action(async (environment, params) => { | ||
try { | ||
checkParams(params); | ||
const settings = { url: params.url, environment: environment, email: params.email }; | ||
|
||
if (params.token) { | ||
token = params.token; | ||
} else if (!params.email){ | ||
token = await deviceAuthorizationFlow(params.url); | ||
} else { | ||
logger.Info( | ||
`Please make sure that you have a permission to deploy. \n You can verify it here: ${Portal.HOST}/me/permissions`, | ||
{ hideTimestamp: true } | ||
); | ||
|
||
const password = await readPassword(); | ||
logger.Info(`Asking ${Portal.HOST} for access token...`); | ||
|
||
token = await login(params.email, password, params.url); | ||
} | ||
|
||
if (token) saveToken(settings, token); | ||
await addEnv(environment, params); | ||
} catch (e) { | ||
if (ServerError.isNetworkError(e)) | ||
ServerError.handler(e) | ||
else | ||
logger.Error('Error'); | ||
process.exit(1); | ||
logger.Error(e); | ||
} | ||
process.exit(1); | ||
}); | ||
|
||
program.parse(process.argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const Portal = require('../portal'); | ||
const logger = require('../logger'); | ||
const validate = require('../validators'); | ||
const { storeEnvironment, deviceAuthorizationFlow } = require('../environments'); | ||
const waitForStatus = require('../data/waitForStatus'); | ||
const { readPassword } = require('../utils/password'); | ||
|
||
const checkParams = (env, params) => { | ||
if (params.email) validate.email(params.email); | ||
|
||
if (params.url.slice(-1) != '/') { | ||
params.url = params.url + '/'; | ||
} | ||
validate.url(params.url); | ||
}; | ||
|
||
const saveToken = (settings, token) => { | ||
storeEnvironment(Object.assign(settings, { token: token })); | ||
logger.Success(`Environment ${settings.url} as ${settings.environment} has been added successfuly.`); | ||
}; | ||
|
||
const login = async (email, password, url) => { | ||
return Portal.login(email, password, url) | ||
.then(response => { | ||
if (response) return Promise.resolve(response[0].token); | ||
}) | ||
} | ||
|
||
const addEnv = async (environment, params) => { | ||
checkParams(environment, params); | ||
if (params.partnerPortalUrl) { | ||
process.env['PARTNER_PORTAL_HOST'] ||= params.partnerPortalUrl | ||
} | ||
|
||
const settings = { | ||
url: params.url, | ||
environment: environment, | ||
email: params.email, | ||
partner_portal_url: process.env['PARTNER_PORTAL_HOST'] | ||
}; | ||
|
||
if (params.token) { | ||
token = params.token; | ||
} else if (!params.email){ | ||
token = await deviceAuthorizationFlow(params.url); | ||
} else { | ||
logger.Info( | ||
`Please make sure that you have a permission to deploy. \n You can verify it here: ${Portal.url()}/me/permissions`, | ||
{ hideTimestamp: true } | ||
); | ||
|
||
const password = await readPassword(); | ||
logger.Info(`Asking ${Portal.url()} for access token...`); | ||
|
||
token = await login(params.email, password, params.url); | ||
} | ||
|
||
if (token) saveToken(settings, token); | ||
} | ||
|
||
module.exports = addEnv; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,78 @@ | ||
const { apiRequest } = require('./apiRequest'); | ||
const logger = require('./logger'); | ||
|
||
const HOST = process.env.PARTNER_PORTAL_HOST || 'https://partners.platformos.com'; | ||
|
||
const Portal = { | ||
url: () => { return process.env.PARTNER_PORTAL_HOST || 'https://partners.platformos.com' }, | ||
|
||
login: (email, password, url) => { | ||
logger.Debug('Portal.login ' + email + ' to ' + HOST); | ||
logger.Debug('Portal.login ' + email + ' to ' + Portal.url()); | ||
|
||
return apiRequest({ | ||
uri: `${HOST}/api/user_tokens`, | ||
uri: `${Portal.url()}/api/user_tokens`, | ||
headers: { UserAuthorization: `${email}:${password}`, InstanceDomain: url }, | ||
}); | ||
}, | ||
jwtToken: (email, password) => { | ||
return apiRequest({ | ||
method: 'POST', | ||
uri: `${HOST}/api/authenticate`, | ||
uri: `${Portal.url()}/api/authenticate`, | ||
formData: { email: email, password: password }, | ||
}); | ||
}, | ||
findModules: (token, name) => { | ||
return apiRequest({ | ||
method: 'GET', | ||
uri: `${HOST}/api/pos_modules/?modules=${name}`, | ||
uri: `${Portal.url()}/api/pos_modules/?modules=${name}`, | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}); | ||
}, | ||
moduleVersions(modules) { | ||
return apiRequest({ | ||
uri: `${HOST}/api/pos_modules?modules=${modules.join(',')}`, | ||
uri: `${Portal.url()}/api/pos_modules?modules=${modules.join(',')}`, | ||
}); | ||
}, | ||
createVersion: (token, url, name, posModuleId) => { | ||
return apiRequest({ | ||
method: 'POST', | ||
uri: `${HOST}/api/pos_modules/${posModuleId}/pos_module_versions`, | ||
uri: `${Portal.url()}/api/pos_modules/${posModuleId}/pos_module_versions`, | ||
body: { pos_module_version: { archive: url, name: name } }, | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}); | ||
}, | ||
moduleVersionStatus: (token, posModuleId, moduleVersionId) => { | ||
return apiRequest({ | ||
method: 'GET', | ||
uri: `${HOST}/api/pos_modules/${posModuleId}/pos_module_versions/${moduleVersionId}`, | ||
uri: `${Portal.url()}/api/pos_modules/${posModuleId}/pos_module_versions/${moduleVersionId}`, | ||
headers: { Authorization: `Bearer ${token}` }, | ||
}); | ||
}, | ||
moduleVersionsSearch: (moduleVersionName) => { | ||
return apiRequest({ | ||
method: 'GET', | ||
uri: `${HOST}/api/pos_module_version?name=${moduleVersionName}` | ||
uri: `${Portal.url()}/api/pos_module_version?name=${moduleVersionName}` | ||
}); | ||
}, | ||
requestDeviceAuthorization: (instanceDomain) => { | ||
return apiRequest({ | ||
method: 'POST', | ||
uri: `${HOST}/oauth/authorize_device`, | ||
uri: `${Portal.url()}/oauth/authorize_device`, | ||
formData: { | ||
domain: instanceDomain | ||
}, | ||
json: false | ||
json: true | ||
}); | ||
}, | ||
fetchDeviceAccessToken: (deviceCode) => { | ||
return apiRequest({ | ||
method: 'POST', | ||
uri: `${HOST}/oauth/device_token`, | ||
uri: `${Portal.url()}/oauth/device_token`, | ||
formData: { | ||
grant_type: 'urn:ietf:params:oauth:grant-type:device_code', | ||
device_code: deviceCode | ||
}, | ||
json: true | ||
}); | ||
}, | ||
|
||
HOST: HOST | ||
} | ||
}; | ||
|
||
module.exports = Portal; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.