UNPKG

@artilleryio/platform-fargate

Version:
17 lines (15 loc) 3.41 kB
const A=require("async"),util=require("../util"),debug=require("debug")("commands:subscription"),moment=require("moment"),chalk=require("chalk"),AWS=require("aws-sdk"),ora=require("ora"),cloud=require("../artillery-cloud")(),getAccountId=require("../util")["getAccountId"],promisify=require("util")["promisify"],setDefaultAWSCredentials=require("../utils/aws-set-default-credentials"),getBackendId=require("../utils/get-backend-id"),getSubscription=require("../data-api").subscriptions["getSubscription"];async function status(options){if(options.email)await requestEmail(options);else{debug("credentials provided: ",null!==(new AWS.Config).credentials);var spinner=ora({spinner:"simpleDotsScrolling"});options.json||(console.log("========== Subscription status =========="),spinner.start());try{var result=await getSubscription();options.json?console.log(JSON.stringify(result,null,4)):(spinner.stop(),result.isTrial?(console.log("Artillery Pro trial license for "+result.licenseEmail),console.log(`Expiry date: ${moment(result.expiresOn).format("MMM D YYYY")} `),console.log("AWS account: "+result.awsAccountId),console.log("Backend region: "+result.backendRegion),console.log(`Limits: Parallel test runs: ${result.maxParallelTestRuns||1} Workers per test run: `+(result.maxWorkers||10)),console.log("\nA license can be purchased on https://www.artillery.io/pro"),console.log("\nQuestions? Please get in touch via sales@artillery.io")):(console.log("AWS account: "+result.awsAccountId),console.log("Subscription plan: "+result.planName),console.log(`Limits: Parallel test runs: ${result.maxParallelTestRuns||1} Workers per test run: `+(result.maxWorkers||10)),console.log(` Backend region: `+result.backendRegion),console.log("Backend version: "+result.backendVersion),"object"==typeof result.secondaryBackends&&(console.log("\nSecondary backend:"),console.log(" Region: "+result.secondaryBackends[0].backendRegion),console.log(` Version: ${result.secondaryBackends[0].version} `)),console.log("License email: "+result.licenseEmail),console.log(` Manage your subscription via: https://artillery.chargebeeportal.com`),console.log("\nQuestions? Please get in touch via support@artillery.io"),debug(result)))}catch(getErr){console.log(chalk.red("Subscription status could not be determined\n")),"CredentialsError"===getErr.code?(console.log("Error: AWS SDK could not load credentials\n"),console.log("Please make sure you are running Artillery with the appropriate AWS credentials configured"),console.log("See https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html for more information")):console.log(getErr),process.exit(1)}}}async function requestEmail(options){try{await cloud.requestLicenseKey({email:options.email})?console.log(chalk.green(`A license key is on its way to ${options.email} and should be with you shortly.`)):console.log(chalk.red(` We could not find an active subscription for ${options.email}. When requesting a license key, the email address that was used to subscribe must be used. Please see https://artillery.io/pro for subscription options for your team. Drop us a line on team@artillery.io if you have any questions.`))}catch(err){console.log(chalk.red("There was a problem requesting a license key for "+options.email)),debug(err),console.log(chalk.green("Please try again or drop us a line on team@artillery.io"))}}module.exports={status:status};